SRL Archive - Reflection Development

FindNPCEx


turbobk

2008-09-04 20:49:05

Hey Guys,

This will find any NPC, with the name 'TheName' and save its location into x, y.
This was just a little something a made for my script that I'm working on, but it is very usefull so I decided to release it for everyone to use.

Function FindNPCEx(Var x, y: Integer; TheName: String): Boolean;
Var
Name: Array Of TNPC;
i: Integer;
Begin
If Not LoggedIn Then Exit;
Name := SortNPCs(GetNPCsByName(TheName));
For i := 0 To High(Name) Do
If Name[i].MS.X <> 0 Then
Begin
x := Name[i].MS.X;
y := Name[i].MS.Y;
Result := True;
Exit;
End;
End;


Example:
Procedure KillDaCowz;
Var
x, y: Integer;
Begin
If FindNPCEx(x, y, 'Cow') Then
Begin
Mouse(x, y, 4, 4, True);
Blah blah blah
End;
End;


That is all,
Thanks,
TurboBk. :)

noidea

2008-09-04 20:53:34

WOW! Thats so awsome. Its way better than having to find the ID and all of that. GOOD JOB. REP 4 u

Timer

2008-09-04 21:05:23

Before you post things for reflection, check depreciated.scar… ;)

turbobk

2008-09-04 23:12:30

From: noidea
WOW! Thats so awsome. Its way better than having to find the ID and all of that. GOOD JOB. REP 4 u


Haha thanks man. ;)



From: Timer
Before you post things for reflection, check depreciated.scar… ;)


Nice "Attack NPC" functions Timer :p
But as you can see, my code is alot more efficient, I know yours walks to the Tile and Flag's but yours is only for Attacking NPC's, mine can find and talk to shop owners, or any NPC for that matter. :)

This is just a quick example I wrote up, It should work but didn't test it.

Function OpenTheBank: Boolean;
Label
Start;
Var
x, y, c, d: Integer;
Begin
Start:
If Not LoggedIn Then Exit;
If FindNPCEx(x, y, 'Banker') Then
Begin
Mouse(x, y, 5, 5, False);
Wait(200 + Random(300));
If ChooseOption('ank') Then
Begin
Repeat
If Not LoggedIn Then Break;
Result := (BankScreen Or (PinScreen));
Wait(500 + Random(500));
c := c + 1;
Until(Result Or (c > 6));
If Result Then
Begin
If PinScreen Then
Begin
Wait(300 + Random(300));
InPin(Players[CurrentPlayer].Pin);
Wait(500 + Random(1000));
End;
If BankScreen Then
Begin
Result := True;
Exit;
End Else
Begin
CloseBank;
Goto Start;
End;
End Else
Begin
CloseBank;
WriteLn('Error Opening the Bank.');
SafeLogout;
NextPlayer(False);
Exit;
End;
End Else Goto Start;
End Else
Begin
If (d > 3) Then
Begin
WriteLn('Error Finding the Banker.');
SafeLogout;
NextPlayer(False);
Exit;
End;
d := d + 1;
Goto Start;
End;
End;

Thanks,
TurboBk. :)

Xtensity

2008-09-05 13:05:58

Thanks, this makes my script a little less cluttered.

3Garrett3

2008-09-05 15:08:01

Turbo. First off.. Good snippet and such. But you have a flaw in your test ;)

If ChooseOption('ank') Then

Since it is clicking the Banker, it will choose the first option with Banker in it : Talk. I believe that is how it works, no?

turbobk

2008-09-05 21:49:09

From: 3Garrett3
Turbo. First off.. Good snippet and such. But you have a flaw in your test ;)

If ChooseOption('ank') Then

Since it is clicking the Banker, it will choose the first option with Banker in it : Talk. I believe that is how it works, no?


Hey 3Garrett3,
Thanks for the reply ;)

You are semi right..
In my script, the Banker's UpText is "Talk-to Banker".

I use
If ChooseOption('Bank') Then

The Options in the list are,
  • Talk-to Banker
  • Bank Banker
  • Examine Banker

Indeed sometimes (1 out of 5) it will click on "Talk-to Banker".
Thats why I use this code in my script.


Begin
FFlag(0);
Wait(500 + Random(500));
If ClickToContinue Then
Begin
ClickContinue(True, True);
Repeat
Wait(300 + Random(300));
Until FindColorTolerance(x, y, 128, 202, 364, 243, 377, 3);
MouseBox(108, 384, 416, 395, 1);
End;
Repeat
If Not LoggedIn Then Break;
Wait(500 + Random(500));
Result := (BankScreen Or (PinScreen));
c := c + 1;
Until(Result Or (c > 6));

3Garrett3

2008-09-05 21:54:18

Could you not just say

ChooseOption('ank B');

?? Seems like it should work, no? Maybe not. I only know it worked that way in RSbot, I have not had this sort of test in SCAR though.

turbobk

2008-09-05 21:56:22

From: 3Garrett3
Could you not just say

ChooseOption('ank B');

?? Seems like it should work, no? Maybe not. I only know it worked that way in RSbot, I have not had this sort of test in SCAR though.


I have tryed that, and it does nothing, I don't think you can use spaces?
It just moves the Mouse away from the ChooseOption list.

3Garrett3

2008-09-05 22:03:01

Hmm. Must be the weird color changes from the option to the name. Just keep doing what you have. The check for when it does choose talk to seems to be the only thing. Of course you would only need the search for a banker would be in the GE, right?

But of course for fighters and stuff it would be a sexy add-on.

turbobk

2008-09-05 22:09:36

From: 3Garrett3
Hmm. Must be the weird color changes from the option to the name. Just keep doing what you have. The check for when it does choose talk to seems to be the only thing. Of course you would only need the search for a banker would be in the GE, right?

But of course for fighters and stuff it would be a sexy add-on.


Nope not in the GE..
Have a look in the General News Section, thread name is: SRL Members,
or something similar.

And thanks, I'm glad you like it :)

Tniffoc

2008-09-06 16:50:38

About that ChooseOption problem,

In my script, I use a bitmap of the white word bank and click on it. Would this be acceptable here?

If you want the BMP, here it is,


BitmapFromString(35, 17, 'beNoLcY8NGUUUof+ogEJzC' +
'CpgAANK7IKbQ4wCgoqHkEVwAAlDTCmCcQrXjiv8ccURfnFMM3G5lp' +
'igw/QsVgcgi+OyBY9F+A3ExcaTbok3hEg2/jgimBjIsBTTLgZUQFC' +
'KVPYoIhMBAKDWABQ=');