SRL Archive - Reflection Tutorials

[Intermedian][Tut]Finding many NPCs


Naike

2008-09-23 16:33:58

This tutorial will teach you how to find and sort NPCs.

If you don't know how to find a Npc please read this.

To find diffrent Npcs start by doing this

program TUT;
{.Include SRL\SRL\Misc\Smart.Scar}
{.Include SRL\SRL.Scar}
{.Include SRL\SRL\Reflection\Reflection.Scar}

var
NPCs : array of TNPC; // Very importent that you declare it as Array of.

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

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

An array is basicly many of one thing in one Var.

Now if we look at the functions we can use to find our Npcs,


function GetNPCs:array of TNPC;
function GetNPCsByName(name:string): array of TNPC;
function GetNPCsByID(TheType:integer): array of TNPC;

Those function is the main 3 functions you can use, Let me explain them.

GetNPCs gets every single loaded NPC, From a level 3 warrior to level 702 Jad and stores them into a array of TNPC, The one you just declared :).

GetNPCsByName gets all NPCs with that name! ( Note: The name have to be exact.) and as above this also stores it into a Array of TNPC.

GetNPCsByID gets all NPCs with that id, every NPC got its own number(Id) not sorted by name or anything like that, If you got 2 monsters with the diffrent level they will have diffrent id's.

Now think of one above matching you needs.

Done?, Then lets carry on.

I choose to use GetNPCs in this tutorial.


program TUT;
{.Include SRL\SRL\Misc\Smart.Scar}
{.Include SRL\SRL.Scar}
{.Include SRL\SRL\Reflection\Reflection.Scar}

var
NPCs : array of TNPC; // Very importent that you declare it as Array of.

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

Function TUTFindNpc: Boolean;
var i, x, y : integer;
begin
NPCs := SortNPCs(GetNPCs); // Stores all the Npcs in your Array
// making number 0 in your array the closest npc from your location.
If GetArrayLength(NPcs) = 0 then Exit; // If you didnt find any npcs
// then the array will be 0, if so it will Exit;
For i:= 0 to High(NPCs) do // If you don't know what this do then
// read more about Statements.
Begin
// In this area you can look for the Npcs you like
// look for a name or see if its InFight etc.. Let me explain.
If NPCs[i].Name = 'Hill giant' Then // Checks if the name is Hill Giant
If Not NPCs[i].InFight Then Continue; // Checks if the Npcs is in fight
MMouse(NPCs[i].MS.X, NPCs[i].MS.Y, 4, 4); // Hovers the mouse to the monster
If IsUpText('Hill giant')then // Checks the uptext
begin
GetMousePos(x, y);
Mouse(x, y, 0, 0, True);
Result := True;
Exit;
end;
end;
end;

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

Thats what i did. Experiment alot and you will master it in notime!

If you got any problems feel free to add my Msn [email]N_1_c_e@hotmail.com[/email]

Another thing i made,

program TUT;
{.Include SRL\SRL\Misc\Smart.Scar}
{.Include SRL\SRL.Scar}
{.Include SRL\SRL\Reflection\Reflection.Scar}

var
NPCs : array of TNPC; // Very importent that you declare it as Array of.

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

Function FindNPCsByNames(Names: TStringArray): TNPC;
var i, ii : integer;
begin
NPCs := SortNPCs(GetNPCs);
If GetArrayLength(NPCs) = 0 then Exit;
For i:=0 to High(NPCs) do
begin
For ii:= 0 to High(Names)do
If NPCs[i].Name = Names[ii] then
begin
Result := NPCs[i];
Writeln('Found : ' + Names[ii]);
end;
end;
end;

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

As you see, the creativity is endless!

shotty87

2008-09-23 16:59:37

ty

Naike

2008-09-23 17:37:27

If i didnt know better i would say that was spam?

I be making a Tut each week ;)

NiCbaZ

2008-09-23 23:20:04

Great Tut Good job.

Baked0420

2008-09-27 08:21:07

nice tut, this is the first one I read on reflection so I kinda get it now but I'm going to read a lot more on reflection till I can do it without references, but thanks for this tut, it helped a lot

BazzBarrett

2008-09-27 16:43:35

TY SO MUCH just wat i was lloking for i <3 reflection already started making scripts in it =)

rawsilk

2008-12-01 04:04:20

I'm making an autofighter and several antirandoms and this helps greatly.