SRL Archive - Reflection Tutorials

[Tutorial] NPC's!


Drakan

2008-09-12 23:38:23

Hey, welcome to my second tutorial on NPC Finding and Clicking. In this tutorial I will cover pretty much anything you need to know about fighting, talking, and interacting with NPC's.

With Smart's reflection, we can see different actions of NPC's and other players. We can find their animations, levels, if they're under attack, and more. In case you didn't know what animation is, here is my way of explaining it: Every action you do (mining, fishing, dancing, etc.) has its own ID we call Animation. Each animation is unique. Lets say you are mining with a rune pick and your animation is 645 (made up number). If you switch to a different pick the number will also change.

So, how do you find NPC's and Players on the screen? Simple. Lets start with my basic template I use for reflection scripts:
program NPCsAndPlayers;
{.Include SRL\SRL\Misc\Smart.Scar}
{.Include SRL\SRL.Scar}
{.Include SRL\SRL\Reflection\Reflection.Scar}

procedure SetupSmart;
begin
SmartSetup('world51', True, True, false);
Wait(1000);
SetTargetDC(SmartGetDC);
end;

begin
SetupSRL;
SetupSmart;
wait(2000);
end;

Now, we are going to go with the scenario that you want to find and talk to an NPC. Let's create a function called TalkToNPC(Name: String);
function TalkToNPC(Name: String);
begin
end;
Now you need to declare a variable to store the NPC's info in. We will call this var TheNPC: TNPC; Lets also add in a variable called P: TPoint; We will store the mainscreen location of the NPC into this.
function TalkToNPC(Name: String);
var
TheNPC: TNPC;
P: TPoint;
begin
end;
Now that we have that declared, lets use the FindNPC function in the Characters.scar inside of the reflection folder.
function TalkToNPC(Name: String);
var
TheNPC: TNPC;
P: TPoint;
begin
if not FindNPC(Name, TheNPC) then Exit;
end;
Now we want to set our variable P to the mainscreen coords. To do this, add the following line to our function:
  P := TheNPC.MS;
This will store the point inside of P. Now we can use Mouse to click that NPC!
function TalkToNPC(Name: String);
var
TheNPC: TNPC;
begin
if not FindNPC(Name, TheNPC) then Exit;
P := TheNPC.MS;
Mouse(P.x, P.y, 5, 5, false);
wait(100+Random(200));
Result := ChooseOption('Talk-to');
end;
I went ahead and added a wait and ChooseOption. Now you have a simple, NPC talker to-er. To use it all you would have to do is:
  TalkToNPC('Bob');
Tada!
There's lots of info you can get from the npc. Here is a list!
TNPC = record
Tile, MS, MM: TPoint;
NPCType, height, animation, HPRatio: integer;
Name : string;
InFight, IsMoving: boolean;
end;
I find InFight to be one of the most helpful when making a Fighting script. It returns true or false depending on if the current npc is under attack. This makes sure that you don't click someone else's monster and look botty :).

Well thats all for this tutorial! Good luck, and post if you have questions/comments!

stunts7058

2008-09-13 03:04:55

awesome Right when i needed this it werent here yesterday i went to make a new script today and tada THANK YOU


Edit: WOO HOO FIRST POST

Quickmarch

2008-09-13 03:22:13

yay second post and is there an object finding tut with reflection? cool tut BTW:)

NiCbaZ

2008-09-13 04:00:32

and is there an object finding tut with reflection? Just made one, nice tut cheese.

Drakan

2008-09-13 08:25:39

Thanks NiCbaZ :) Glad you guys like the tut!

cause

2008-09-22 17:33:25

Man, I haven't been around in awhile, a lot of new stuff is coming out. This reflection stuff is un-freakin' stoppable. We can make tut runners, questers, unstoppable fighters, etc…! It seems there is some hesitation to accept this by the community, am I picking up the right vibe?
Btw, rockin' tut, love it, I might try and make a tut runner from this. (even though you already have)

Drakan

2008-09-22 18:45:12

No problem :)

quipeace

2008-10-11 06:42:51

hmm, I've been away for quite some time but this reflection seems very nice! Just have one problem with your script…

colon (':') expected in script

function TalkToNPC(Name: String);

thats the line, its missing a colon somewhere apparently, but I can't figure out where…

Its a great tut btw :)

Heysus

2008-10-11 07:16:08

It should be like this I think.

function TalkToNPC(Name: String): Boolean;

Thats what worked for me anway. The last end should have a period after it too.

BazzBarrett

2008-10-11 07:20:20

yer i was about to point that out:
function TalkToNPC(Name: String):Boolean;
var
TheNPC: TNPC;
begin
if not FindNPC(Name, TheNPC) then Exit;
P := TheNPC.MS;
Mouse(P.x, P.y, 5, 5, false);
wait(100+Random(200));
Result := ChooseOption('Talk-to');
end;

that sould work perfect ;) can some1 change it on the first post?

Perfect_Coder

2009-08-11 10:55:59

Thank you for insight on interacting with NPC's.
Is there a reason why you use whole option on Result := ChooseOption('Talk-to');?
I haven't been around here for long, but most other tutorials omit capital letter from start.