SRL Archive - OSR Help

Tracking a NPC in Reflection


Bobzilla69

2011-02-18 15:26:19

Hi,

i am trying to work on a way to track a specific NPC until its dead for my Ratinator script.

I have made some progress but i need help to polish this off a bit.

the way i am doing it, or shall we say trying to do it is using the Index of the NPC to track it.

for most part is works fine but occasionally it will kill the rat but keep thinking its alive, i am not sure why, its possible at that point a new rat has spawned with the same Index but i would love some help with this.

This is my check to see if the rat index is found against the current rats on screen.

Function FastFighting:Boolean; //using this now to check that we are attacking rat, no false positives (hopefully)
var
i:integer;
Char : TNPCArray;
mx, my, Colour, Shadow:integer;
ratBMP, TotalBMP:TMufasaBitmap;
Canvas: TCanvas;
ratBox:TBox;
ratpoint:TPoint;
Foundit:Boolean;
begin
Write('Checking for Fight');
ratBox.X1 := 0;
ratBox.Y1 := 0;
ratBox.X2 := 8;
ratBox.Y2 := 8;

Foundit:= false;

if Players[CurrentPlayer].Booleans[0] then
begin
repeat
Char := (SortNPCS(GetNPCS('Giant rat'))); //gets all rats
if(Length(Char) = 0)then
Exit;



{if TileOnMS(rattile, 0) then //used to draw on smart.
begin

SmartSetDebug(True);
GetClientDimensions(mx,my);

Colour := 225; //change color of text
Shadow := 65536;
ratBMP := TMufasaBitmap.create;
ratBMP.SetSize(mx,my);
ratBMP.FastDrawClear(clBlack);

ratBMP.Rectangle( ratBox, Colour);

Canvas := TCANVAS.Create;
Canvas.Handle := SmartGetDebugDC;
TotalBMP := TMufasaBitmap.create;
TotalBMP.SetSize(mx,my);


ratpoint:= tiletoms(rattile, 0);


//writeln('rat location is x: '+inttostr(ratpoint.x)+ ' y :'+inttostr(ratpoint.y));

ratBMP.FastDrawTransparent( ratpoint.x ,ratpoint.y , TotalBMP);

ratBMP.SetTransparentColor(clBlack);
TotalBMP.DrawToCanvas(0 ,0, Canvas);

ratBMP.Free;
TotalBMP.Free;

end; }



//Writeln('looking for '+inttostr(Rat)+' in array');

for i := 0 to High(Char) do //loops through all rats found
begin

//writeln('currently in array is ' +inttostr(char[i].Index));
if (Rat = Char[i].Index) then //checks rat index from attack function to ones in current array
begin
Writeln('Rat Index found rat coould still be alive');
Result:= True;
Break;
end;

if (I = High(Char)) then
begin
Write('looped through all rats, exiting');
Result:= False
Wait(800+Random(1000));
end;
end;
//writeln('');

Wait(500+Random(500));
until( not Result)
end;
end;

I get my initial Rat Index from my attack function when i click it.

what do you think? am i being stupid and this would not work?

Train

2011-02-18 15:32:10

Just check if you're interacting with the rat. Interaction stops on death.

mormonman

2011-02-18 15:33:55

Won't work. Better idea: AreWeInteracting(var NPC: TNPC): Boolean; I created it specifically for this purpose. It gets the npc that is interacting with you.

Bobzilla69

2011-02-18 15:35:55

ok, brilliant will use that.

can anyone shed some more light on why my way wont work, it just means i will understand it all better :)

Train

2011-02-18 15:38:36

I wouldn't know if yours works or not… but wont the index just be replaced after the rat dies?

mormonman

2011-02-18 15:40:14

From: Train
I wouldn't know if yours works or not… but wont the index just be replaced after the rat dies?


As soon as a new npc is spawned. NPCs are stored by a node just like everything else pretty much.

Bobzilla69

2011-02-18 15:43:28

ok i see.

thanks for the explanation :)

Train

2011-02-18 16:43:09

From: mormonman
As soon as a new npc is spawned. NPCs are stored by a node just like everything else pretty much.


That's what I meant. So if in a chance one spawned as soon as yours died, it would return that it's still fighting. :o

Boreas

2011-02-18 17:51:36

Can you get health of the rat you are tracking?

Train

2011-02-18 18:41:41

From: Boreas
Can you get health of the rat you are tracking?


yes

Capricorn

2011-02-18 18:53:52

The Index randomly changes every 8-20~ seconds or so.

kitchenrange

2011-02-19 03:13:35

From: Train
yes


Have you used this personally? It keeps returning 0 for me.

Narcle

2011-02-19 03:22:39

From: kitchenrange
Have you used this personally? It keeps returning 0 for me.


Iirc it actually returns the % its at, also it won't show unless the npcs hp bar is up. Unless there has been a recent hook added to know the current hp.

kitchenrange

2011-02-19 05:45:03

I'm talking about the percentage. NPC.HPRatio.

But, I've set up a script just to debug the HPRatio of the NPC interacting with me and after manually attacking the NPC's, nothing was debugged besides a a value of 0.

Capricorn

2011-02-19 16:11:16

From: kitchenrange
I'm talking about the percentage. NPC.HPRatio.

But, I've set up a script just to debug the HPRatio of the NPC interacting with me and after manually attacking the NPC's, nothing was debugged besides a a value of 0.


You have to "update" the variables.

It's kinda like when they move. If you have an array of 10 NPCs and one moves, your mouse will move to the tile were they where when you grabbed them all.

There really isn't any reason to care about any of that nonsense when AreWeInteracting is perfect for any sort of combat purposes.

AreWeInteracting(NPC)
Writeln(NPC.HPRatio)

Loop that and you will see that it works.

mormonman

2011-02-19 22:54:22

function m_InFight: boolean;
var
NPC: TNPC;
begin
Result := False;
if AreWeInteracting(NPC) then
Result := NPC.Fighting and (NPC.HPRatio > 0);
end;

Capricorn

2011-02-19 23:48:10

From: mormonman
function m_InFight: boolean;
var
NPC: TNPC;
begin
Result := False;
if AreWeInteracting(NPC) then
Result := NPC.Fighting and (NPC.HPRatio > 0);
end;


See now this is a waste, because if the NPC is dead you're not interacting.

Gu3st...

2011-02-20 04:35:14

From: Capricorn
See now this is a waste, because if the NPC is dead you're not interacting.
And if the NPS is dead, you're not fighting it either

mormonman

2011-02-20 06:25:05

From: Capricorn
See now this is a waste, because if the NPC is dead you're not interacting.


No because while the NPC is dying it still exists, so you check for the hp bar(NPC.Fighting) and then check its percentage.

kitchenrange

2011-02-20 12:09:41

procedure WaitForFight;
var
Me : TMe;
i : integer;
begin
Flag;
Wait(RandomRange(200,300));
for i := 0 to 10 do
begin
WriteLN('waiting');
if loggedin = false then LoginPlayer;
ClickContinue(True, False);
Wait(5);
Me := GetMe;
inc(i);
if Me.Interacting > 0 then i := 0;
end;
end;



This is the shit.

mormonman

2011-02-20 13:28:29

From: kitchenrange
procedure WaitForFight;
var
Me : TMe;
i : integer;
begin
Flag;
Wait(RandomRange(200,300));
for i := 0 to 10 do
begin
WriteLN('waiting');
if loggedin = false then LoginPlayer;
ClickContinue(True, False);
Wait(5);
Me := GetMe;
inc(i);
if Me.Interacting > 0 then i := 0;
end;
end;



This is the shit.


You will still be "Interacting" when the NPC is doing the dying animation. Thus making yours slower.

Floor66

2011-02-20 13:37:36

I had this:

//These were -global- vars:
//_NPCWeAreFighting, NPCWeWereFighting : TNPC;
//used like:
//AreWeInteracting(_NPCWeAreFighting);
//when a rock crab attacked

Function NPCWeAreFighting: Boolean;
Begin
If Not LoggedIn Then
Exit;
_Status('NPCWeAreFighting');
AreWeInteracting(NPCWeWereFighting);
Result := (_NPCWeAreFighting.Index <> NPCWeWereFighting.Index);
End;

It might not work at all because Rock Crabs are agressive or this is simply wrong code :p

mormonman

2011-02-20 13:57:01

From: Floor66
I had this:

//These were -global- vars:
//_NPCWeAreFighting, NPCWeWereFighting : TNPC;
//used like:
//AreWeInteracting(_NPCWeAreFighting);
//when a rock crab attacked

Function NPCWeAreFighting: Boolean;
Begin
If Not LoggedIn Then
Exit;
_Status('NPCWeAreFighting');
AreWeInteracting(NPCWeWereFighting);
Result := (_NPCWeAreFighting.Index <> NPCWeWereFighting.Index);
End;

It might not work at all because Rock Crabs are agressive or this is simply wrong code :p


NPC indices are not handled like they were when you made this.

Floor66

2011-02-20 14:17:39

Aww damnit, well sorry then :0

Capricorn

2011-02-20 14:38:31

From: mormonman
You will still be "Interacting" when the NPC is doing the dying animation. Thus making yours slower.


That's not how it works for me.

Train

2011-02-20 14:57:18

From: mormonman
You will still be "Interacting" when the NPC is doing the dying animation. Thus making yours slower.


Incorrect. The interaction is broken instantly on death.

Capricorn

2011-02-20 15:08:08

The only problem though is sometimes AreWeInteracting returns false even though it should be true. Happens rarely though.

Another thing you have to look out for is with magic. Casting spells seems to take to long, and in between spells there will be like a half second period where you won't be interacting.

Train

2011-02-20 15:09:20

From: Capricorn
The only problem though is sometimes AreWeInteracting returns false even though it should be true. Happens rarely though.

Another thing you have to look out for is with magic. Casting spells seems to take to long, and in between spells there will be like a half second period where you won't be interacting.


The NPC should never stop interacting with you. That doesn't make any sense. But one of you should always be interacting… so check interaction between NPC -> Player and Player -> NPC.

Capricorn

2011-02-20 15:25:23

From: Train
The NPC should never stop interacting with you. That doesn't make any sense. But one of you should always be interacting… so check interaction between NPC -> Player and Player -> NPC.


Ahhh that is clever. I'll add that in my autofighter :)

Edit: to clarify I think it's a bug, because most of the time it works perfectly. A bug with reflection or SMART, not really sure. All I know is it happens very infrequently but it does happen.

Ogre

2011-02-20 15:31:24

"check interaction between NPC -> Player and Player -> NPC."

I could be wrong, but I don't think this should be necessary. I have a script where I simply click the NPC then wait while its Interacting is > 0, and that's always worked.

Train

2011-02-20 16:30:13

From: Capricorn
The only problem though is sometimes AreWeInteracting returns false even though it should be true. Happens rarely though.

Another thing you have to look out for is with magic. Casting spells seems to take to long, and in between spells there will be like a half second period where you won't be interacting.


…

mormonman

2011-02-20 16:53:47

From: Train
Incorrect. The interaction is broken instantly on death.


You should probably test something before you say that. Me.Interacting will return > 0 right after you click the npc, before you are even in a fight with it, and will stay > 0 until it is gone.

I have personally tested this so next time you should.

Gu3st...

2011-02-20 17:00:17

From: mormonman
You should probably test something before you say that. Me.Interacting will return > 0 right after you click the npc, before you are even in a fight with it, and will stay > 0 until it is gone.

I have personally tested this so next time you should.
I tested it just now, and GetMe.Interacting turned into -1 when the target was dieing (still visible). So Train is right

{$DEFINE SMART}
{$i SRL/SRL.scar}
{$i Reflection/Reflection.simba}
begin
Smart_Server := 1;
Smart_Signed := True;
SetupSRL;
SetupReflection;
while True do
begin
ClearDebug;
WriteLn(GetMe.Interacting);
Wait(50);
end;
end.

mormonman

2011-02-20 17:02:39

From: Zyt3x
I tested it just now, and GetMe.Interacting turned into -1 when the target was dieing (still visible). So Train is right

{$DEFINE SMART}
{$i SRL/SRL.scar}
{$i Reflection/Reflection.simba}
begin
Smart_Server := 1;
Smart_Signed := True;
SetupSRL;
SetupReflection;
while True do
begin
ClearDebug;
WriteLn(GetMe.Interacting);
Wait(50);
end;
end.


It lasts a good 500ms after it has 0 HPRatio.

Train

2011-02-20 17:13:12

From: mormonman
It lasts a good 500ms after it has 0 HPRatio.


The interaction is broke almost instantly depending on your ping from my tests ~a month ago.

Capricorn

2011-02-20 18:16:46

From: mormonman
You should probably test something before you say that. Me.Interacting will return > 0 right after you click the npc, before you are even in a fight with it, and will stay > 0 until it is gone.

I have personally tested this so next time you should.


Well I have just tested both, and they both operate differently.

If you are interacting with something, your me.interacting will always be higher than 0 and yes it does not go back to -1 until the death animation is done. AreWeInteracting however returns false as soon as the HP hits 0. I could theorize why this is but it doesn't matter at the end of the day, what matters is that it does.

Why is there a difference? How should I know. Why do you seem to be getting frustrated over this? No need to say stuff with spite.

kitchenrange

2011-02-21 01:33:25

My function definitely exits on death. Not sure why it would have different results for others.