PDA

View Full Version : How do I find a NPC?



klit rs
02-01-2011, 06:34 AM
So I am currently working on a script, as u can tell my me having a quesion about scripting lol.... But anyways, in this script I need to find the NPC so I can Right Click him, etc... I know about the right clicking part and all, but Im not really quite sure how to find the NPC... Should I use a DTM, I dont think so since he moves... Plus there are other NPC's around him that look exactly like him, but have a different name... Please someone help me! It will be greatly appreciated!

P.S. I have seen the FindNPC and GetNPC functions from the Reflection files, but I have no earthly idea of what they do, so if those are the best way to do this then just teach me what those do and how to use them if possible =) thank you!!!!!

P.S.S. Im fairly new to scripting... I would say I am an Intermediate scripter.... Freshman in College, working towards a Computer Science Major...

Well thanks to everyone that reads this and many more thanks to anyone who can help me =) Thanks alot!

KingKong
02-01-2011, 06:45 AM
This gives you the name and id of all currently loaded npcs:

procedure SearchNPCs;
var
a: Integer;
NPCs: TNPCArray;
begin
NPCs := GetNPCs(False);
for a := 0 to high(NPCs) do
begin
writeln(NPCs[a].Name + ToStr(NPCs[a].ID);
end;
end;


After you run this, record the Id of the npc you want, then run this:

function InteractNPC(Name: string): Boolean;
var
ID, height, a: Integer;
NPC: TNPC;
NPC_Tile: TPoint;
begin
ID := 0; //<---------replace 0 with id of npc
Result := False;
NPC := GetNPCMulti([ID]);
NPC_Tile := TileToMS(NPC.Tile, NPC.height);
Mouse(NPC_Tile.x, NPC_Tile.y, 0, 0, False);
WaitOptionMultiEx(['alk-'], 'action', ClickLeft, 1000);
while (a < 5) and (IsMoving) do
begin
wait(700 + randomrange(-50, 200));
R_FindRandoms;
Inc(a);
end;
wait(1218 + random(100));
if InteractingWithMe(NPC) then
Result := True;
end;

TomTuff
02-01-2011, 06:45 AM
Well, it really depends if you want to use reflection or color. Color is more complex, but in the long run will create a more stable function. Reflection is easy to code, but liable to break.

If you want to do this in color, then try looking at some of the tutorials about TPointArrays (Commonly abbreviated as "TPA"). A TPointArray is exactly what the name implies; an array of points on the screen. The points are gathered by various methods, the most common being functions in Simba like "FindColorsTolerance." These functions look for colors on the screen, and store the points where the colors are found in the TPA. The TPA is then split into an "Array of TPointArray", (abbreviated ATPA commonly) by using one of the functions in the wizzyplugin, like TPAtoATPA or SplitTPA; a list of the functions in the wizzyplugin and what they do can be found in SRL\SRL\Misc\wizzyplugin.scar.

Reflection uses java hooking methods to read the client. You could supply an NPC's name or ID and use the functions in the Reflection include to find all the NPCs that match the criteria. You can then sort through this "TNPCArray" to find an NPC that matches all of the things you need (e.g. an NPC whose name is "Guard", is not in a fight, and is nearer to you than any other NPCs like this). Once you've done that, you can use either "TileToMS" or "TileToMSEx" to generate a TPoint that will click the tile the NPC you've found is on.

That's a quick rundown of the 2 methods you could use to find an NPC in Simba. Post back with questions or for clarification.

Frement
02-01-2011, 06:45 AM
Do a TPA search with all of his colors (with tolerances), then combine the arrays and do ATPA conversion with the NPC size, then sort from MS center and loop through all found from nearest and when found the right uptext, right click it.