Results 1 to 18 of 18

Thread: Returning values at Real-Time

  1. #1
    Join Date
    Feb 2012
    Posts
    168
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Returning values at Real-Time

    So currently I have a function which "tracks" an NPC. At this point, all it does is output the NPC's center coordinates (will make a TBox in the near future) to the debug box. How can I make it return them as the function runs so I can have a FindColorsSpiralTolerance avoid the specific area where the NPC is?

    I can upload what I have of the function so far if anybody would like it.

    Seeing as there are no replies yet, I'll upload what I have so far:

    Simba Code:
    function TrackNPC(hue, saturation: extended; Color, Tol : Integer; Uptext : TStringArray; XBounds, YBounds, Tries : Integer): Boolean;
    var
      I, N, x, y, t: Integer;
      TPA: TPointArray;
      ATPA: Array of TPointArray;
      FoundIt: Boolean;
    begin
      ColorToleranceSpeed(2);
      SetColorSpeed2Modifiers(h, s);
      FindColorsSpiralTolerance(MSCX, MSCY, TPA, Color, MSX1, MSY1, MSX2, MSY2, Tol);
      ATPA := TPAToATPAEx(TPA, 15, 15);
      N := High(ATPA);
      for I := 0 to N do
      begin
        MiddleTPAEx(ATPA[i], x, y);
        MMouse(x, y, 2, 2);
        if(IsUpTextMultiCustom([Uptext])) then
        begin
          FoundIt := True;
          GetMousePosition(x, y);
        end;
      end;
      while(FoundIt = true) do
        for t := 0 to Tries do
          if FindColorsSpiralTolerance(x, y, TPA, Color, (x - (XBounds/2)) , (y - (YBounds/2)), (x + (XBounds/2)), (y + (XBounds/2)), Tol) then
          begin
            ATPA := TPAToATPAEx(TPA, 15, 15);
            MiddleTPAEx(ATPA[i], x, y);
            writeln('Object is currently at ' + IntToStr(x)+ ',' + IntToStr(y));
            break; // Found object
            FoundIt := true;
          end
          else begin
            writeln('Failed to find object - Trying again');
            Inc(t);
            FoundIt := False;
          end;
          wait(100 + Random(100));
    end;

    Making a TBox around the object is on the to-do list. But I need to figure out a way I can get the results of this function to a mainloop so I can run the regular script and not find whatever it found with this over and over again - if that makes sense.
    Last edited by Imagine; 04-01-2012 at 06:38 PM.

  2. #2
    Join Date
    Feb 2012
    Posts
    168
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Uploaded the function.

  3. #3
    Join Date
    Feb 2012
    Posts
    168
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Anyone? :S

  4. #4
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Your function currently returns a boolean..

    make it return a TPointArray..
    Then do something like:

    Simba Code:
    function TrackNPC(hue, saturation: double; Color, Tol : Integer; Uptext : TStringArray; XBounds, YBounds, Tries : Integer): TPointArray;
    var
      I, N, x, y, t: Integer;
      TPA: TPointArray;
      ATPA: Array of TPointArray;
      FoundIt: Boolean;
    begin
      ColorToleranceSpeed(2);
      SetColorSpeed2Modifiers(h, s);
      FindColorsSpiralTolerance(MSCX, MSCY, TPA, Color, MSX1, MSY1, MSX2, MSY2, Tol);
      ATPA := TPAToATPAEx(TPA, 15, 15);
      N := High(ATPA);
      for I := 0 to N do
      begin
        MiddleTPAEx(ATPA[i], x, y);
        MMouse(x, y, 2, 2);
        if(IsUpTextMultiCustom([Uptext])) then
        begin
          FoundIt := True;
          GetMousePosition(x, y);
        end;
      end;
      while(FoundIt = true) do
        for t := 0 to Tries do
          if FindColorsSpiralTolerance(x, y, TPA, Color, (x - (XBounds/2)) , (y - (YBounds/2)), (x + (XBounds/2)), (y + (XBounds/2)), Tol) then
          begin
            ATPA := TPAToATPAEx(TPA, 15, 15);
            MiddleTPAEx(ATPA[i], x, y);
            writeln('Object is currently at ' + IntToStr(x)+ ',' + IntToStr(y));
            SetLength(Result, Length(Result) + 1);
            Result[I]:= Point(X, Y);
            break; // Found object
            FoundIt := true;
          end
          else begin
            writeln('Failed to find object - Trying again');
            Inc(t);
            FoundIt := False;
          end;
          wait(100 + Random(100));
    end;
    I am Ggzz..
    Hackintosher

  5. #5
    Join Date
    Feb 2012
    Posts
    168
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    ^ Wouldn't that make the TPA only accessible after the function ends though?

  6. #6
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    Yes, but since you only have one thread, that doesn't matter.
    Working on: Tithe Farmer

  7. #7
    Join Date
    Feb 2012
    Posts
    168
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by masterBB View Post
    Yes, but since you only have one thread, that doesn't matter.
    Part of the question is also how to include another thread.

    Simba Code:
    while(FoundIt = true) do
    This will cause the function to go on forever while it seems the specified object/NPC on the screen, so running it if you can't multi-thread it is sorta pointless.

  8. #8
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    What? No where in the OP does it say anything about threading..
    It returns them as the function runs just like you asked.. You run the function, you get your values returned. There is no reason that you'd need threading to track the npc and do other stuff at the same time.. You track your NPC & when it gets to wherever, you do whatever.. Else just call the function multiple times..

    It shouldn't go on forever anyway.. if you have a function with an infinite loop, that's just bad coding. How would you destroy your thread and how would your thread receive messages?
    I am Ggzz..
    Hackintosher

  9. #9
    Join Date
    Feb 2012
    Posts
    168
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I assumed that it would be threading because of the real-time.
    And the problem with having my values returned and having to call it every time is that I can't keep track of the NPC. (It has to mouse over the NPC to check the Uptext every time).

    And it wouldn't go on forever, it would just go on until it could no longer see what it was tracking.

    Essentially what I'm trying to have here is a function which will identify something, confirm it with uptext, and then just keep track of it so it no longer needs to check it's uptext, and so I can search other parts of the Screen and not the region the object is in. This would be for objects with similar colors to what I was looking for, etc.

  10. #10
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    What ur asking for colour is nearly impossible anyway.. To track an NPC with the same colours as other NPC's around.. Not going to happen.. The moment another NPC of the same type/colour comes around the current, ur mouse will automatically go to the closest one or the one with the most colours found..
    I am Ggzz..
    Hackintosher

  11. #11
    Join Date
    Feb 2012
    Posts
    168
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Well that's the thing... the function at the moment identifies what you're tracking (With uptext), then just identifies it by movement on the screen and re-searches color. It doesn't constantly check the uptext, and it doesn't matter if another of the same NPC moves into another area of the screen.

  12. #12
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    There's different ways to do what your doing.. I'm pretty sure that function unnecessary.. You can check the NPC's Area then blacklist it and ever so often check the area and make sure your mouse isn't near it.. It's the same thing I do for waterfiends because there is no way for me to track greendragons.. Same for Sorceress Garden.. Used SPS to track the NPC's Movements, when I thought it was necessary to run, I had the character run.

    Like I said though if you did have multi-threading, you'd have problems even then.. Your question would turn into "How To track a single NPC".. There's no way to track a single NPC constantly unless it's unique in that area.. You can of course try what I suggested or track it by Minimap dots, etc..

    Just Curious.. Why are you trying to track it? Would help if we all knew..
    I am Ggzz..
    Hackintosher

  13. #13
    Join Date
    Feb 2012
    Posts
    168
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Well I wasn't really writing this function specifically for one of my scripts, I just thought it would be useful to have. Also, how could I blacklist an area that moves?

    However, I would probably end up using it in scripts such as an ogre ranger, because my mouse keeps hovering over the Competition Judges' arms.

  14. #14
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    U can blacklist an area that moves by constantly checking, adding to a TPA and clearing From a TPA..

    If Colours Found in whatever area, TPAFromBox and remove the ClearTPAFromTPA of your finder function.. Then when you check again, Clear Your blacklist and do the same thing again.

    Basically In your finder function, you can check to see if a certain colours exist.. If they do, Make a TPA from them and remove it from your TPA that holds the screen data.. Then you can move your mouse to all the points that aren't in that contained TPA.. Get it?

    Even better is what I call SPS TPA's.. Basically Get SPS Points of an area.. convert it to minimap points then to Mainscreen Points.. If an object is in the SPS Mainscreen Box that you just made.. then TPA from that box and remove it from your finder.
    I am Ggzz..
    Hackintosher

  15. #15
    Join Date
    Feb 2012
    Posts
    168
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Hmm that's interesting, I'll have to look into the MMtoMS things

  16. #16
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by ggzz View Post
    What ur asking for colour is nearly impossible anyway.. To track an NPC with the same colours as other NPC's around.. Not going to happen.. The moment another NPC of the same type/colour comes around the current, ur mouse will automatically go to the closest one or the one with the most colours found..
    Come on bra, you could possibly sort points by mouse position and you keep having the mouse move along the NPC?
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  17. #17
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by Sex View Post
    Come on bra, you could possibly sort points by mouse position and you keep having the mouse move along the NPC?
    To move the mouse along the npc u'd constantly do FindColorsSpiralTolerance.. Another NPC with the same colours comes around, really close to ur other one maybe even overlap.. ur mouse will track the other one..
    I am Ggzz..
    Hackintosher

  18. #18
    Join Date
    Feb 2012
    Posts
    168
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I wanted to free the mouse to do other things though ._., but the blacklist sounds pretty nice to be honest.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •