SRL Archive - Reflection Discussion

GetNPCAt?


3Garrett3

2010-06-13 13:59:51

Could someone make this function?

I know that there is a GetObjectAt function, to get an object's tile, but there is none for the NPC.

NPCs usually aren't static, but fishing spots are quite static, which is what I would like to use it for. And I have no idea how to turn


function GetObjectAt(T: TTile; objType: Integer): TRSObject;
var
objFuncts: array [0..3] of function(T: TTile):TRSObject;
begin
Result := NULL_RSOBJECT;

objFuncts[0] := @GetInteractableAt; objFuncts[1] := @GetWallObjectAt;
objFuncts[2] := @GetWallDecorAt; objFuncts[3] := @GetFloorDecorAt;

Result := objFuncts[objType](T);
end;

into an NPC function.

Nava2

2010-06-13 14:14:28

You can't really..

What you *could* do is write a function to get all of the NPCs and then sort through and find the ones that are on that Tile.

Be forewarned, it won't work the same way.

I can write this up if you'd like, let me know.

Method

2010-06-13 14:14:33

You would need to loop through the npcs in the local list while checking their locations until you found one that was on the tile you wanted.

3Garrett3

2010-06-13 14:21:43

From: Nava2
You can't really..

What you *could* do is write a function to get all of the NPCs and then sort through and find the ones that are on that Tile.

Be forewarned, it won't work the same way.

I can write this up if you'd like, let me know.


I've got a version that Timer wrote up for me, but I am curious about how you would go about it. I asked you on msn and you signed out :(

TRiLeZ

2010-06-13 17:01:42


{*******************************************************************************
function GetNPCAt(T: TTile): array of TNPC;
By: TRiLeZ
Description: Returns all of the NPCs on a certain TTile.
*******************************************************************************}
function GetNPCAt(T: TTile): array of TNPC;
var
Plane, Ground, Node, NPC, ID, LX, LY, NPCDef, NameBytes, I: integer;
begin
Result := NULL_NPC;
I := 0;
try
LX := T.X - SmartGetFieldInt(0, hook_static_BaseX);
LY := T.Y - SmartGetFieldInt(0, hook_static_BaseY);
Plane := SmartGetFieldInt(0, hook_static_LoadedPlane);
Ground := SmartGetFieldArray3DObject(0, hook_static_GroundTiles, Plane, LX, LY);
Node := SmartGetFieldObject(Ground, hook_ground_AnimableList);

while(Node <> 0)do
begin
NPC := SmartGetFieldObject(Node, hook_AnimableNode_GetAnimable);
if(NPC <> 0)then
begin
NPCDef := SmartGetFieldObject(NPC, hook_npc_NPCDef);
if (NPCDef <> 0) then
begin
NameBytes := SmartGetFieldObject(NPCDef, hook_npcdef_GetName);
if(lowercase(trim(GetJavaString(NameBytes, 255))) <> 'null')then
begin
SetArrayLength(Result, i + 1);
Result[i].ID := SmartGetFieldInt(NPCDef, hook_npcdef_GetID);
Result[i].Name := GetJavaString(NameBytes, 255);
Result[i].Actions := GetNPCActionArray(NPCDef);
Result[i].Tile.X := (SmartGetFieldInt(0, hook_static_BaseX) +
(SmartGetFieldInt(NPC, hook_animable_PixelX) / 512));
Result[i].Tile.Y := (SmartGetFieldInt(0, hook_static_BaseY) +
(SmartGetFieldInt(NPC, hook_animable_PixelY) / 512));
Result[i].Moving := (SmartGetFieldInt(NPC, hook_character_Motion)>0);
Result[i].Animation := SmartGetFieldInt(NPC, hook_character_Animation);
Result[i].Height := iabs(SmartGetFieldInt(NPC, hook_character_GetHeight));
Result[i].HPRatio := SmartGetFieldInt(NPC, hook_character_HPRatio) * 100 / $FF;
Result[i].Fighting := (SmartGetFieldInt(NPC, hook_character_LoopCycleStatus) >
SmartGetFieldInt(0, hook_static_LoopCycle));
Result[i].Orientation := (SmartGetFieldInt(NPC, hook_character_Orientation)* 45) / 2048;
Result[i].Level := SmartGetFieldInt(NPCDef, hook_npcdef_GetLevel);
Result[i].Interacting := SmartGetFieldInt(NPC, hook_character_GetInteracting);
Inc(i);
end;
end;
end;
SmartFreeObject(NameBytes);
SmartFreeObject(NPCDef);
SmartFreeObject(NPC);
SmartFreeObject(Node);
Node := SmartGetFieldObject(Node, hook_AnimableNode_GetNext);
end;

finally
SmartFreeObject(Ground);
SmartFreeObject(NPC);
SmartFreeObject(Node);
SmartFreeObject(NameBytes);
SmartFreeObject(NPCDef);
end;
end;

I haven't tested this, but it should work because npcs are on the animable node.

Capricorn

2010-06-13 17:44:25

Not even fishing spots are static, the only NPC's that don't move are like bankers. And for that you could just use tiletoms…

Whats the point of this exactly? :S

3Garrett3

2010-06-13 17:59:16

From: Capricorn
Not even fishing spots are static, the only NPC's that don't move are like bankers. And for that you could just use tiletoms…

Whats the point of this exactly? :S


Reflection has a handy dandy feature that is called "FORGET EVERYTHING" I believe.

If the script is standing on the dock, and I call "GetNPC(FishSpot)" where the fishspot is a variable which stands for a fishing spot. (There are different ID's for Bait/Net and Cage/Harpoon spots). Usually this will work, but there is a small chance that the script says "Fishing Failed" and "No Fishing spot found" indicating that the spot wasn't found. Then when I check the player, they are sitting on the dock. Which means that reflection just didn't find the spot. I have 3 failsafes already for it, and they all like to fail. So I just wanted to have an array of tiles around the dock, and make it search all around it for a fishing spot, and hope for the best. I've implemented one of the versions Nava sent me, and it hasn't failed yet.

Capricorn

2010-06-13 18:34:25

I have not had that problem so, alright. Fair enough. Lol I don't know what else to say

3Garrett3

2010-06-13 18:35:42

Yeah, everyone who was testing my script has mentioned it. And I cant figure out how to fix it, so I just add tons of fail safes :P

Capricorn

2010-06-13 18:47:15

The only thing I can think about is, when the fishing spots change location and you are unlucky enough to search for one while it hasn't respawned yet. That or there is a problem with reflection, but I am to lazy to test that.

Drakan

2010-06-13 19:31:08

I doubt it's reflection. Like, HIGHLY doubt.

3Garrett3

2010-06-13 19:33:15

We'll discuss on msn ;)

Nava2

2010-06-13 21:11:11

Uhm, did my version not work?

3Garrett3

2010-06-13 21:12:22

From: Nava2
Uhm, did my version not work?


It works. Except the script still failed in finding the fishing spot when it was standing on the dock once.

I never said yours failed though. It increased the time the script ran without messing up on finding the fishing spot by 3 hours.

Narcle

2010-06-13 21:55:42

Why don't you make a tile array and GetAllNPCs then loop through the npcs to see if they are in the tile array of fishing spawn points? And check with the ID(s)/name(s)?

Having a Tile array really is an extreme, but you might want to check to see if Jagex is making ghost fishing spots, just like they make null npc's in certain areas.

Drakan

2010-06-14 07:12:11

Narcle, the include automatically fishes out ghost npcs. ;)

Naike

2010-06-14 08:08:38

From: drags111
Narcle, the include automatically fishes out ghost npcs. ;)


My new pc'er seems to think there's ghost NPC's as well..