SRL Archive - OSR Help

Kill Detection Help?


Ian

2012-11-08 15:01:12

I'm working on a rat killer that someone requested, but the problem that I'm running into is that I need a way to accurately determine how many rats have been killed. I suspect that what I'm using now artificially inflates the nubmer of rats it killed. Here's the function I'm using now:
Procedure KillRats;
Var
x, y: Integer;
begin
if not LoggedIn then LoginPlayer;
FindNormalRandoms;
If (not InFight) Then
begin
If FindObjCustom(x, y, ['Rat', 'at'], [4605769, 3882302], 5) Then
begin
WriteLn('Fighting Rat')
GetMousePos(x, y);
Mouse(x, y, 1, 1, false);
WaitOption('nt', 2000);
Kills := Kills + 1
Antiban;
Wait(randomrange(3000,4000));
Flag;
end;
end;
end;

The problem is when it attacks a rat that is in combat with the lumbridge guard (a bot-like npc that randomly wanders around killing rats), It registers the kill. Unfortunately, there is no message saying "somebody else is fighting that" (I was going to check the chatbox for that message then -1 the killcount.)

Any help would be appreciated, thanks!

Olly

2012-11-08 15:15:28

Look for the empty (red) hp bar around your char

Rezozo

2012-11-08 15:18:10

Hmm, I can't think of a solution to this…I know there are ways to detect if a rat is killed, but not if you killed it 'together or not'…

Are you able to attack a rat that is also in combat with the guard?

Ian

2012-11-08 15:25:30

From: Rezozo
Hmm, I can't think of a solution to this…I know there are ways to detect if a rat is killed, but not if you killed it 'together or not'…

Are you able to attack a rat that is also in combat with the guard?


No, it's single-way combat. Also is it just me or did they remove the "someone else is fighting that" message from the chatbox?

Rezozo

2012-11-08 15:36:36

IDK, I think that was only for players. Hmm, Ill try to think of something.
Is there any difference in the way the rat dies from him and you? Lol anything at all? (frustrating!)

Ian

2012-11-08 15:42:01

From: Rezozo
IDK, I think that was only for players. Hmm, Ill try to think of something.
Is there any difference in the way the rat dies from him and you? Lol anything at all? (frustrating!)


Nope, he kills just like humans do. Time to start learning TPAs I guess….. :(

Rezozo

2012-11-08 15:47:29

^^^Suggest Footy.

and yea, I don't know for this :p Maybe what Olly said before, check for the red HP bar if its away from you, that would at least make the script 'slightly' more accurate, but I guess not fully :)

Footy

2012-11-08 15:52:48

Why not use srl_infight? Like this


Findobj...
If SRL_infight then
(Register kill, wait for rat to die) else
(find another rat)

You will need some failsafes, but that should work…

Rezozo

2012-11-08 15:58:49

Im just wondering, again, wont that detect any kill around you? What if the guy kills one right next to you… Otherwise the HP Bar one works as well :)

Welcome Rezozo…To the 100% activity club!!!!!!!!!!!

Footy

2012-11-08 16:03:19

I believe srl_infight uses pixelshift aswell as hp bar… I'm not sure, you can check on SIMBA though.

Rezozo

2012-11-08 16:15:58

Will do. Also, Just got like 4 rep from my post above^^^ lol

Ian

2012-11-08 18:05:40

From: Footy
I believe srl_infight uses pixelshift aswell as hp bar… I'm not sure, you can check on SIMBA though.


From: Simba Globals


(*
srl_InFight
~~~~~~~~~~~

.. code-block:: pascal

function srl_InFight: Boolean;

Checks whether player currently is in a fight, using mainscreen
HP bar presence detection. Returns True if Player's HP bar is detected.
Idea for improvement: Also check using PixelShift(); to see whether Player
is performing fighting animations to further improve the certainty of results.

.. note::

by Narcle

Example:

.. code-block:: pascal

while srl_InFight do
begin
CheckHP;
EatFood;
end;

*)
Function srl_InFight: Boolean;
begin
Result := InRange(Length(GetFightBarTPA(MFBox)), 30, 240);
end;
.


Pixelshift is suggested but not implemented.

Also I found earlier that infight takes a few seconds to detect it's in a fight so I added
Wait(randomrange(3000,4000));
to force a wait until the next check

Rezozo

2012-11-08 18:43:45

So how about using pixelshift and this function together, to make it a 100% accurate that if one is killed, right after you stop moving (within 500ms) then it counts as one of your kills?
Maybe someone should implement this…

Ian

2012-11-08 18:48:50

Whoohooo!
Tracking xp rates now, but it seems that I finally have a working method! Using what footy suggested, but might use pixelshift as well once I learn it :D.
for those curious, here's the new procedure :
rocedure KillRats;
Var
x, y: Integer;
begin
if not LoggedIn then LoginPlayer;
FindNormalRandoms;
If (not InFight) Then
begin
If FindObjCustom(x, y, ['Rat', 'at'], [4605769, 3882302], 5) Then
begin
WriteLn('Fighting Rat')
GetMousePos(x, y);
Mouse(x, y, 1, 1, false);
WaitOption('nt', 2000);
If SRL_infight then
begin
Kills := Kills + 1
Repeat
Antiban;
Wait(randomrange(100,200));
Until(not SRL_infight)
end;
Flag;
end;
end;
end;

E: After some testing, I found the above procedure underreports kills, any ideas?

Rezozo

2012-11-08 19:50:32

Um…Well…First thats a procedure, not a function :)
Second, you forgot the 'p' in procedure :p

Do tell, does it work nicely?

Ian

2012-11-08 20:34:11

From: Rezozo
Um…Well…First thats a procedure, not a function :)
Second, you forgot the 'p' in procedure :p

Do tell, does it work nicely?


Whoops, I tend to say them interchangeably :redface:.
And the missing P was a copy and paste error, the one in the script is fine :)
unfortunately, as I said above, it now underreports kills, to the extent that runescape said I got 1k xp and the proggy said I got 600 xp. :( Any idea what could be going wrong?

___

2012-11-08 21:33:17

I`ve always used timeout + pixelshift failsafes… I find that a proggy for something like fighting isn`t exactly useful. Not only is it hard, but it`s usually wrong or bugs out. Other skills like mining and woodcutting (love wc) are easy to proggy-ize.

Footy

2012-11-08 21:37:38

You could go hardcore and:

1) Create an ATPA of all Yellow dots on minimap
2) When in a fight, figure out which yellow dot you are fighting via MMToMS functions
3) Wait for the yellow dot to dissapear then add your experience

Or, you could go softcore and do this

1) Take note of how much xp you get per kill
2) Keep xp counter open
3) Assign a variable to the total xp on the xp counter at the beginning of script
4) Every proggy, compare new total xp with old one
5) To get total kills, divide xp by how much xp you get per kill, then round it to a whole number.

Edit: Reading over my Hardcore method, it seems like a heck of a lot of work for something that might not work. Stick with my second method. :p

Ian

2012-11-08 22:00:09

From: ___
I`ve always used timeout + pixelshift failsafes… I find that a proggy for something like fighting isn`t exactly useful. Not only is it hard, but it`s usually wrong or bugs out. Other skills like mining and woodcutting (love wc) are easy to proggy-ize.


But a proggy for fighting is useful when it is accurate. A mining proggy is easy, yes, but difficult <> less useful.


From: Footy
You could go hardcore and:

1) Create an ATPA of all Yellow dots on minimap
2) When in a fight, figure out which yellow dot you are fighting via MMToMS functions
3) Wait for the yellow dot to dissapear then add your experience

Or, you could go softcore and do this

1) Take note of how much xp you get per kill
2) Keep xp counter open
3) Assign a variable to the total xp on the xp counter at the beginning of script
4) Every proggy, compare new total xp with old one
5) To get total kills, divide xp by how much xp you get per kill, then round it to a whole number.

Edit: Reading over my Hardcore method, it seems like a heck of a lot of work for something that might not work. Stick with my second method. :p


20 xp per kill (27 counting constitution but who counts that, it levels when it levels :p)

How can I get it to read the xp counter?

Also I found the problem with my procedure: When I kill the rat in 1 or 2 hits then it does not register as being in a fight, so no kill is added.

Lalaji

2012-11-09 21:24:35

Hey, I was reading through your code and just saw this:
Completely Off Topic -
Procedure KillRats;
Var
x, y: Integer;
begin
if not LoggedIn then LoginPlayer;
FindNormalRandoms;
If (not InFight) Then
begin
If FindObjCustom(x, y, ['Rat', 'at'], [4605769, 3882302], 5) Then // X and y Stored.
begin
WriteLn('Fighting Rat')
GetMousePos(x, y); //X and Y overwritten here.
Mouse(x, y, 1, 1, false); //will move to the same place (x, y) where the mouse already is.
WaitOption('nt', 2000);
Kills := Kills + 1
Antiban;
Wait(randomrange(3000,4000));
Flag;
end;
end;
end;

I think you are using the find function, it is storing the result in the coordinates (x, y). Then you are calling the GetMousePos function and it is storing that result again in the variables x and y (thus overwriting the value from your custom find function). So when you call the Mouse function, it will only move and click the mouse in that same location (ignoring the rx and ry) where the mouse already is.

Have you tested the code? is that not what is happening?

riwu

2012-11-09 21:31:58

From: Lalaji
Hey, I was reading through your code and just saw this:
Completely Off Topic -
Procedure KillRats;
Var
x, y: Integer;
begin
if not LoggedIn then LoginPlayer;
FindNormalRandoms;
If (not InFight) Then
begin
If FindObjCustom(x, y, ['Rat', 'at'], [4605769, 3882302], 5) Then // X and y Stored.
begin
WriteLn('Fighting Rat')
GetMousePos(x, y); //X and Y overwritten here.
Mouse(x, y, 1, 1, false); //will move to the same place (x, y) where the mouse already is.
WaitOption('nt', 2000);
Kills := Kills + 1
Antiban;
Wait(randomrange(3000,4000));
Flag;
end;
end;
end;

I think you are using the find function, it is storing the result in the coordinates (x, y). Then you are calling the GetMousePos function and it is storing that result again in the variables x and y (thus overwriting the value from your custom find function). So when you call the Mouse function, it will only move and click the mouse in that same location (ignoring the rx and ry) where the mouse already is.

Have you tested the code? is that not what is happening?

FindObjCustom would already be hovering over the item as it needs to check the uptext, so GetMousePos(x, y) would be redundant as it should be the exact same coordinate as the x,y output.

Ian

2012-11-09 21:51:08

Haha yeah I guess that was a bit redundant, thanks.
New procedure(still inaccurate kill detection, but less jumpy mouse movement):
Procedure KillRats;
Var
x, y: Integer;
begin
if not LoggedIn then LoginPlayer;
FindNormalRandoms;
If (not InFight) Then
begin
If FindObjCustom(x, y, ['Rat', 'at'], [4605769, 3882302], 5) Then
begin
ClickMouse2(false);
WaitOption('nt', 2000);
If SRL_infight then
begin
WriteLn('Fighting Rat')
Kills := Kills + 1
Wait(randomrange(800,1200));
Repeat
Antiban;
Wait(randomrange(100,200));
Until(not SRL_infight)
end;
Flag;
Wait(randomrange(800,1200));
end;
end;
end;

Do you guys think using SlushPuppy's Sound plugin to detect being in a fight would work?

Lalaji

2012-11-09 22:11:42

Your proc looks great. Personally, this just seems a bit neater.

Procedure KillRats;
Var
x, y: Integer;
begin
If not LoggedIn then LoginPlayer;
If SRL_InFight Then Exit; //A bit simpler.
FindNormalRandoms;
If FindObjCustom(x, y, ['Rat', 'at'], [4605769, 3882302], 5) Then
begin
ClickMouse2(false);
WaitOption('nt', 2000); //2 seconds may be way too high.
While IsMoving and not(SRL_InFight) do
wait(50); //Or we can use fflag(0) i guess.

If SRL_infight then
Kills := Kills + 1

While SRL_InFight do
begin
Wait(50); //dont need random wait here, right?
If random(3) = 1 then //may have to change the 3 (?)
Antiban; //Dont have to call antiban everytime!
end;
end;
end;

I have no experience working with the sound plugin.

Ian

2012-11-09 22:20:13


Procedure KillRats;
Var
x, y: Integer;
begin
If not LoggedIn then LoginPlayer;
If SRL_InFight Then Exit; //A bit simpler.
FindNormalRandoms;
If FindObjCustom(x, y, ['Rat', 'at'], [4605769, 3882302], 5) Then
begin
ClickMouse2(false);
WaitOption('nt', 2000); //Is the time how long to wait for it to appear? I just raise the number until it finds it. Also it doesn't wait two seconds to chose the option I don't think...
While IsMoving and not(SRL_InFight) do
wait(50); //Or we can use fflag(0) i guess.

If SRL_infight then
Kills := Kills + 1

While SRL_InFight do
begin
Wait(50); //I think static wait is fin because it is just a placeholder really. As long as it is not interacting with the client in static times :)
If random(3) = 1 then //may have to change the 3 (?)
Antiban; //My antiban function just has a 10% chance of activating
end;
end;
end;

I think there is only one script that uses the sound plugin and it's his :D

P1ng

2012-11-10 00:18:02

I'd recommend writing your own InFight procedure to take into account pixel shift, it wouldn't be difficult and if it's good you might even get it committed to the include :)

slushpuppy

2012-11-10 00:26:29

If i am honest, adding this sort of counter slows the script down too much for the added value of a kill counter

Ian

2012-11-10 10:43:35

QUOTE=slushpuppy;1125201]If i am honest, adding this sort of counter slows the script down too much for the added value of a kill counter

Is there a sort of counter that wouldn't slow it down?

Trying out using IsMoving to detect, because when it attacks sucessfully it runs to the rat.
Procedure KillRats;
Var
x, y: Integer;
begin
if not LoggedIn then LoginPlayer;
FindNormalRandoms;
If (not InFight) Then
begin
If FindObjCustom(x, y, ['Rat', 'at'], [4605769, 3882302], 5) Then
begin
ClickMouse2(false);
WaitOption('nt', 2000);
Wait(100);
If IsMoving then
begin
WriteLn('Fighting Rat')
Kills := Kills + 1
Wait(randomrange(800,1200));
Repeat
Antiban;
Wait(randomrange(100,200));
Until(not SRL_infight)
end;
Flag;
Wait(randomrange(800,1200));
end;
end;
end;