Log in

View Full Version : Returning values at Real-Time



Imagine
03-31-2012, 06:12 PM
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:

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.

Imagine
03-31-2012, 08:57 PM
Uploaded the function.

Imagine
04-01-2012, 12:45 PM
Anyone? :S

Brandon
04-01-2012, 12:53 PM
Your function currently returns a boolean..

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


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;

Imagine
04-01-2012, 03:32 PM
^ Wouldn't that make the TPA only accessible after the function ends though?

masterBB
04-01-2012, 03:53 PM
Yes, but since you only have one thread, that doesn't matter.

Imagine
04-01-2012, 04:02 PM
Yes, but since you only have one thread, that doesn't matter.

Part of the question is also how to include another thread.

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.

Brandon
04-01-2012, 05:02 PM
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?

Imagine
04-01-2012, 06:34 PM
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.

Brandon
04-01-2012, 06:49 PM
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..

Imagine
04-02-2012, 01:19 AM
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.

Brandon
04-02-2012, 02:08 AM
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..

Imagine
04-02-2012, 03:11 AM
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.

Brandon
04-02-2012, 03:20 AM
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.

Imagine
04-02-2012, 10:30 PM
Hmm that's interesting, I'll have to look into the MMtoMS things :)

Sex
04-02-2012, 10:52 PM
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?

Brandon
04-02-2012, 11:08 PM
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..

Imagine
04-03-2012, 12:44 AM
I wanted to free the mouse to do other things though ._., but the blacklist sounds pretty nice to be honest.