SRL Archive - Reflection Tutorials

Finding NPCs!


Smarter Child

2009-08-28 01:09:38

NPCs!

Today i am going to be writing a tutorial on using NPCs in functions etc..

So lets get started:

- What is an NPC?

An NPC is a non player character in runescape. NPCs are like shopkeepers/fishing spots/Bankers.
( + Fishing Spots are weird they're like the only "non - living" npcs in runescape. + )
- What is not an NPC?

Rocks/Trees etc. These things are objects, which won't be discussed in the tutorial today :p.

—-

First lets make a basic reflection script template:
program New;
{.Include SRL\SRL\Misc\Smart.Scar}
{.Include SRL\SRL.Scar}
{.Include SRL\SRL\Reflection\Reflection.Scar}

Const
World = 72;
Members = false;
Signed = true;

procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;

Players[0].Name :='';
Players[0].Pass :='';
Players[0].Nick :='';
Players[0].Active := True;
end;

begin
Smart_Members := Members;
Smart_Signed := Signed;
Smart_Server := World;
Smart_SuperDetail := false;
SetupSRL;
SetupReflection;
DeclarePlayers;
LoginPlayer;
{Next functions}
end.

I use this to test any of my functions that i create with reflection.

So just make a function named: FindTheNPC or something, then we have to declare a var.

var npc: TNPC;

This variable stores TNPC in the npc variable.

Now type: FindNPC(
You'll get these parameters:

FindNPC(TheVar: Variant;var NPC: TNPC): boolean;

So lets start with TheVar:

For this parameter you can have either the npc id or the npc name[doesn't have to be whole thing].

For example:

Function FindFishingSpot: boolean;
var
NPC: TNPC:
begin
FindNPC('ishing Spot',

end;

Or:


Function FindFishingSpot: boolean;
var
NPC: TNPC:
begin
FindNPC(434
//not real fishing spot id, but is an example
end;

Understand?

The next variable is NPC: TNPC; which you guys should have covered by now :p
So this is what i have currently:
Function FindFishingSpot: boolean;
var
NPC: TNPC:
begin
if FindNPC('ishing Spot', NPC)then
end;

Now we have to use NPC variable to find the tile of npc so we can click it!

So do this:

Function FindFishingSpot: boolean;
var
NPC: TNPC:
TP: TPoint;
begin
if FindNPC('ishing Spot', NPC)then
TP := TileToMs(NPC.Tile, 0);
end;
Don't get :confused: just yet, its very simple.
The NPC variable store the Tile of the npc so therefore u can do NPC.Tile.
Height is the distance in pixels above the ground, but we obviously know fishing spots are on the floor.(well not irl :p).
Now we have the mainscreen locations stored to TP, so all we have to do now is:
Function FindFishingSpot: boolean;
var
NPC: TNPC:
TP: TPoint;
begin
if FindNPC('ishing Spot', NPC)then
TP := TileToMs(NPC.Tile, 0);
MMouse(TP.x, TP.y, 2, 2);
end;
Try that out yourself, on some other NPC, and it will move the mouse to it. But we won't a little more failsafes don't we?

Function FindFishingSpot: boolean;
var
NPC: TNPC:
TP: TPoint;
begin
if FindNPC('ishing Spot', NPC)then //if it finds the npc it does..
TP := TileToMs(NPC.Tile, 0); //TP stores the mainscreen location of the npc
MMouse(TP.x, TP.y, 2, 2); //moves mouse to mainscreen location
if R_IsUpText('ishing')then ///checks the uptext using reflection
begin
Wait(500 + Random(500)): //small wait
Mouse(TP.x, TP.y, 3, 3, true);//left clicks the npc
Result := //function results true;
end;
if(not(FindNPC('ishing Spot', NPC)))then
begin
Result := false; //function results false
Exit; //exits function if it couldn't find the spot
end;
end;

And thats your basic npc finding in reflection, good luck making your own functions.

:).

~~ END ~~

mormonman

2009-08-28 02:59:15

Add NPCEx, as it is more powerful… and you should know that 'ishing Spot' isn't any(noticeable) faster than "Fishing Spot".

rogeruk

2009-08-28 03:35:31

Problem i found with FindNPC with fishing spots is that it will find it OFF mainscreen which will cause a script to fail.

Simply add a distance check such as..

If (DistanceFrom(Fish.Tile) > 5) Then

This way you can easily move from spot to spot fast and efficent.

mormonman

2009-08-28 03:37:52

Isn't that kind of obvious rogeruk… it finds everything within the 104x104 tile square that the RS Client loads.

rogeruk

2009-08-28 03:57:12

Yea and why hasnt a simple check been implemented?

What good is finding an NPC 15 tiles away when you cant even see the NPC?. WalkToTile should have been implemented into the function standard.

mormonman

2009-08-28 04:00:05

From: rogeruk
Yea and why hasnt a simple check been implemented?

What good is finding an NPC 15 tiles away when you cant even see the NPC?. WalkToTile should have been implemented into the function standard.


I don't think it should.

Infantry001

2009-08-28 04:19:55

From: rogeruk
Yea and why hasnt a simple check been implemented?

What good is finding an NPC 15 tiles away when you cant even see the NPC?. WalkToTile should have been implemented into the function standard.

I feel the scripter could add that in themselves. Besides, it would be easier to use FindNPCEx so you can control the area you are looking in.

rogeruk

2009-08-28 04:24:33

Function FindFishingSpot: boolean;
var
NPC: TNPC:
TP: TPoint;
begin
if FindNPC('ishing Spot', NPC) then //if it finds the npc it does..
TP := TileToMs(NPC.Tile, 0); //TP stores the mainscreen location of the npc
MMouse(TP.x, TP.y, 2, 2); //moves mouse to mainscreen location
if R_IsUpText('ishing') then ///checks the uptext using reflection
begin
Wait(500 + Random(500)): //small wait
Mouse(TP.x, TP.y, 3, 3, true);//left clicks the npc
Result := //function results true; << No True here...
end;
if(not(FindNPC('ishing Spot', NPC)))then
begin
Result := false; //function results false
Exit; //exits function if it couldn't find the spot
end;
end;

NPC: TNPC:


Fixed..
Function FindFishingSpot: Boolean;
Var
NPC: TNPC;
TP: TPoint;
Begin
If (FindNPC('ishing Spot', NPC)) Then
Begin
TP := TileToMs(NPC.Tile, 0);
MMouse(TP.x, TP.y, 2, 2);
If (R_IsUpText('ishing'))Then
Begin
Wait(500 + Random(500));
Mouse(TP.x, TP.y, 3, 3, True);
Result := True
End Else Result := False;
End Else Result := False;
End;

Tutorial needs work. Dont really want to be using : when you should be using ;

Smarter Child

2009-08-29 03:39:05

Alright, thanks everyone. Yes i am very new to reflection myself, so. Until i become better at reflection. I won't be writing any more reflection tutorials :

ZaSz

2009-08-29 04:26:46

From: Smarter Child
Alright, thanks everyone. Yes i am very new to reflection myself, so. Until i become better at reflection. I won't be writing any more reflection tutorials :


You know the saying, those that cant do teach. :p

Also, maybe go over what all goes into a TNPC also, and possibly more options like if its in a fight or animating. Like in my reflection tut here

Nice try at a tutorial though.

Smarter Child

2009-08-29 04:47:31

From: ZaSz
You know the saying, those that cant do teach. :p

Also, maybe go over what all goes into a TNPC also, and possibly more options like if its in a fight or animating. Like in my reflection tut here

Nice try at a tutorial though.


Thanks, i think i will stick to color tuts for now :p.