SRL Archive - SRL Snippets

FindNearestNPC(x,y:Integer;Click:Boolean);


Sin

2012-03-07 17:18:51

function FindNearestNPC(var x,y:Integer;Click,Wait:Boolean):Boolean;
var
NPC:TPoint;
begin
if FindColorSpiralTolerance(NPC.x,NPC.y,65536,558,6,690,153,4) then
begin
Result := True;
if (Click = True) and (Result = True) then
Mouse(NPC.x,NPC.y,1,1,True);
if Wait = True then
begin
FFlag(1);
Wait(750 + random(250));
end;
end;
end;

x,y = Stores info of NPC locations.
Click = Whether to click or not.
Wait = Whether to wait until not moving or not.

It's been really useful for me in fighting scripts and even my ZMI :)

Sin

2012-03-07 17:38:43

Added an FFlag boolean :p

shstiger2009

2012-03-07 17:44:32

Right when I read the thread title I thought woah, this is for fighting for sure! Looks pretty good, I'd bet it speeds up some fighting scripts a ton.

Sin

2012-03-07 17:45:47

From: shstiger2009
Right when I read the thread title I thought woah, this is for fighting for sure! Looks pretty good, I'd bet it speeds up some fighting scripts a ton.


Hehe, it will work for anything actually :P
For example, thieving, cooking scripts, etc :p

Flight

2012-03-07 21:28:09

Actually, your X and Y variables are never stored, therefore when calling this function they'll always return '0'… Also, by default, this function should return false, not true. Also, 'Wait' as one of your parameters is already a valid procedure in Simba thus you cannot use that same name. Here's your function fixed up:

function FindNearestNPC(var x,y: Integer; Click,DoWait: Boolean):Boolean;
var
NPC:TPoint;
begin
Result := False; //This should always be false by default
if FindColorSpiralTolerance(NPC.x,NPC.y,65536,558,6,690,153,4) then
begin
Result := True;
X := NPC.x; //Now, X & Y actually return something...
Y := NPC.y;
if (Click and Result) then //No need for (Boolean = True)
begin
Mouse(NPC.x,NPC.y,1,1,True);
if DoWait then
begin
FFlag(1);
Wait(750+random(250));
end;
end;
end;
end;

Jokester

2012-03-07 21:33:14

From: Flight
Actually, your X and Y variables are never stored, therefore when calling this function they'll always return '0'… Also, by default, this function should return false, not true. Also, 'Wait' as one of your parameters is already a valid procedure in Simba thus you cannot use that same name. Here's your function fixed up:

function FindNearestNPC(var x,y: Integer; Click,DoWait: Boolean):Boolean;
var
NPC:TPoint;
begin
Result := False; //This should always be false by default
if FindColorSpiralTolerance(NPC.x,NPC.y,65536,558,6,690,153,4) then
begin
Result := True;
X := NPC.x; //Now, X & Y actually return something...
Y := NPC.y;
if (Click and Result) then //No need for (Boolean = True)
begin
Mouse(NPC.x,NPC.y,1,1,True);
if DoWait then
begin
FFlag(1);
Wait(750+random(250));
end;
end;
end;
end;


Looks good! I've got the perfect script for this!:stirthepot:

Sin

2012-03-07 21:34:23

It was working for me Flight :$

Flight

2012-03-07 21:56:25

From: Sin
It was working for me Flight :$


If you were to debug your function's return values for X & Y you'd always have 0. You understand that an integer was never assigned to either of them within your function. Try this and you'll see:

Procedure Test;
Var
X,Y: Integer;
begin
if FindNearestNPC(X, Y, True, True) then
Writeln('NPC dot found at Point('+InttoStr(X)+', '+InttoStr(Y)+')');
end;

Ashaman88

2012-03-07 22:01:06

This could be pretty handy!