SRL Archive - Jr. Member General Help and Discussion

Need some ideas to check if player is in combat


Ross

2014-08-27 23:49:32

Title!

I'm having trouble coming up with a way to check if a player is in combat. (check health? check adrenaline?) I tried dissecting @The Mayors and @bonsais combat scripts and they proved to be a little too far over my head.

Thanks in advance!

Clarity

2014-08-27 23:56:45

Monster weaknesses can be identified using DTMs. Monster targeting information only appears when you are in combat (some small exceptions due to glitches). You can check to see if your character is in combat by running findDTM a number of times, which will search an area you specify for the DTM. If it finds the DTM, it will return true, and thus a combat check would return true.

Simple version from my Barrows script's combat check:

{FUNCTION -- areWeFighting
Purpose: Checks if we are in combat.
Comments: None.}
function areWeFighting: boolean;
var
x, y, tries, monsterWeakness: integer;
begin
if not isLoggedIn then //Failsafe
exit;
result := false; //Redundant since the default is false, but I like to put this in
ClarityDebug('Checking to see if we are in combat.');
monsterWeakness := DTMFromString('mlwAAAHicY2dgYJjLyMAwE4gXAvEiIJ4GxJOAeAkQRzMzMAQCcRwQh0LpCCCOBOKJX00Z9CslGIQ1RBhU0kQZeEXEGAQlZBkExKQY8AFGPBgKALAoCwQ=');
while tries < 4 do //Failsafe
begin
if findDTM(monsterWeakness, x, y, mainScreen.getBounds()) then
begin
result := true; //We found the DTM, so we must be in combat
ClarityDebug('Currently in combat.');
freeDTM(monsterWeakness); //Always free your DTMs after you are finished using them
exit;
end
else
inc(tries);
end;
ClarityDebug('Not in combat.');
freeDTM(monsterWeakness); //Always free your DTMs after you are finished using them
//Function ends returning false
end;

If you don't know what DTMs are then let me know and I'll elaborate in another post.

In your script, you would use this function to decide whether to do things like check your prayers.

if areWeFighting then
begin
checkPrayers;
checkHealth;
doSomethingElse;
stuff;
end;

bonsai

2014-08-28 01:39:29

This is what I've been using. It looks for a bunch of the indicators like the gold lock, the black popup box areas, the green/red health bars. Some of the reults carry more weight than others and we take a vote at the end.

My choice of colors is probably horrible but it's been working good so I haven't messed with it.

   gold1 := countColorTolerance(2726093, mainscreen.getBounds(), 9, colorSetting(2,0.14,2.16));
red1 := countColorTolerance(3094484, mainscreen.getBounds(), 25, colorSetting(0));
box1 := countColorTolerance(1380618, mainscreen.getBounds(), 0, colorSetting(0));
box2 := countColorTolerance(1381133, mainscreen.getBounds(), 2, colorSetting(0));
green1 := countColorTolerance(3308832, mainscreen.getBounds(), 15, colorSetting(2, 0.27, 1.56));

search := mainscreen.playerBox;
search.expand(35);
green2 := countColorTolerance(45128, search, 9, colorSetting(2, 0.70, 0.00));

if (gold1 > 50) then inc(votes);
if (gold1 > 80) then inc(votes);
if (gold1 > 100) then inc(votes);
if (red1 > 45) then inc(votes);
if (box1 > 150) then votes := votes + 2;
if (box2 > 150) then votes := votes + 2;
if (green1 > 125) then inc(votes);
if (green2 > 40) then inc(votes);

if (votes > 4) then
result := true
else
result := false;

Ross

2014-08-28 08:29:45

From: bonsai
This is what I've been using. It looks for a bunch of the indicators like the gold lock, the black popup box areas, the green/red health bars. Some of the reults carry more weight than others and we take a vote at the end.

My choice of colors is probably horrible but it's been working good so I haven't messed with it.

   gold1 := countColorTolerance(2726093, mainscreen.getBounds(), 9, colorSetting(2,0.14,2.16));
red1 := countColorTolerance(3094484, mainscreen.getBounds(), 25, colorSetting(0));
box1 := countColorTolerance(1380618, mainscreen.getBounds(), 0, colorSetting(0));
box2 := countColorTolerance(1381133, mainscreen.getBounds(), 2, colorSetting(0));
green1 := countColorTolerance(3308832, mainscreen.getBounds(), 15, colorSetting(2, 0.27, 1.56));

search := mainscreen.playerBox;
search.expand(35);
green2 := countColorTolerance(45128, search, 9, colorSetting(2, 0.70, 0.00));

if (gold1 > 50) then inc(votes);
if (gold1 > 80) then inc(votes);
if (gold1 > 100) then inc(votes);
if (red1 > 45) then inc(votes);
if (box1 > 150) then votes := votes + 2;
if (box2 > 150) then votes := votes + 2;
if (green1 > 125) then inc(votes);
if (green2 > 40) then inc(votes);

if (votes > 4) then
result := true
else
result := false;



Oh wow that's sexy, I'm going to steal that and edit it a bit if you don't mind!

Ross

2014-08-28 10:28:34

From: Clarity
Monster weaknesses can be identified using DTMs. Monster targeting information only appears when you are in combat (some small exceptions due to glitches). You can check to see if your character is in combat by running findDTM a number of times, which will search an area you specify for the DTM. If it finds the DTM, it will return true, and thus a combat check would return true.

Simple version from my Barrows script's combat check:

{FUNCTION -- areWeFighting
Purpose: Checks if we are in combat.
Comments: None.}
function areWeFighting: boolean;
var
x, y, tries, monsterWeakness: integer;
begin
if not isLoggedIn then //Failsafe
exit;
result := false; //Redundant since the default is false, but I like to put this in
ClarityDebug('Checking to see if we are in combat.');
monsterWeakness := DTMFromString('mlwAAAHicY2dgYJjLyMAwE4gXAvEiIJ4GxJOAeAkQRzMzMAQCcRwQh0LpCCCOBOKJX00Z9CslGIQ1RBhU0kQZeEXEGAQlZBkExKQY8AFGPBgKALAoCwQ=');
while tries < 4 do //Failsafe
begin
if findDTM(monsterWeakness, x, y, mainScreen.getBounds()) then
begin
result := true; //We found the DTM, so we must be in combat
ClarityDebug('Currently in combat.');
freeDTM(monsterWeakness); //Always free your DTMs after you are finished using them
exit;
end
else
inc(tries);
end;
ClarityDebug('Not in combat.');
freeDTM(monsterWeakness); //Always free your DTMs after you are finished using them
//Function ends returning false
end;

If you don't know what DTMs are then let me know and I'll elaborate in another post.

In your script, you would use this function to decide whether to do things like check your prayers.

if areWeFighting then
begin
checkPrayers;
checkHealth;
doSomethingElse;
stuff;
end;




I actually ended up going with this and using the DTM of the gold lock that appears. It's working well at the moment, thank you.

Clarity

2014-08-28 11:49:34

From: bonsai
This is what I've been using. It looks for a bunch of the indicators like the gold lock, the black popup box areas, the green/red health bars. Some of the reults carry more weight than others and we take a vote at the end.


Really like the votes/threshold idea. Clever!

Lucidity

2014-08-31 11:37:49

How would you go about seeing if they're in combat with another player?

Lipcot

2014-08-31 15:26:43

I´ve set the health of the monster im fighting to appear on top of my invetory so it doesent get confused with anything else and search for some DTM that appears always in there and check it every 50ms, works perfectly! if you cant get this to work just tell me and ill post my procedure.

bonsai

2014-08-31 18:44:13

I PMed undorak because I wasn't sure what he was saying. He's saying you can move that whole targeting window that pops up anywhere you want like the xp tracker.

Duh, why don't we all know this? !!!

Should pretty much eliminate false positives.

lanadekat

2014-09-01 12:55:46

Bookmarked this thread, thanks to all people who posted methods here, I can probably use this in the future :)

The Spark

2014-09-01 12:58:03

You can also check for the red ring around the mob that only appears when you are fighting.

bonsai

2014-09-11 22:46:33

I worked up this DTM for finding that last green '0' in the combat popup (when they run out of health).

There must be a way to turn it into a DTM string but I haven't figured it out

You can't make it in the editor because the dots are right next to each other.

The returned integet is a dtm like any other, use findDTM, etc with it.



function __makeEnemy0DTM(): integer;

const
REDDISH = 1381690;
GOLDISH = 442049;
var
ts: TSDTM;
i: integer;

begin
with ts.mainpoint do
begin
x := 0;
y := 0;
color := GOLDISH;
tolerance := 44;
end;
setLength(ts.subpoints, 11);

for i := 0 to 10 do
with ts.subpoints[i] do
begin
x := 0;
y := 0;
color := REDDISH;
tolerance := 33;
end;
ts.subpoints[5].color := GOLDISH;
ts.subpoints[5].tolerance := 44;

ts.subpoints[0].x := -8;
ts.subpoints[1].x := -7;
ts.subpoints[2].x := -6;
ts.subpoints[3].x := -5;
ts.subpoints[4].x := -4;
ts.subpoints[5].x := 4;
ts.subpoints[6].x := 8;
ts.subpoints[7].x := 9;
ts.subpoints[8].x := 10;
ts.subpoints[9].x := 11;
ts.subpoints[10].x := 12;
result := AddSDTM(ts);
end;

cosmasjdz

2014-09-12 09:01:35

From: bonsai


Duh, why don't we all know this? !!!

Should pretty much eliminate false positives.


Using this over a month, static thing is a good thing. Talking about static, all i do is search for orange lock color in one of the dots since its static:D reduces cpu usage alittle bit. Also i try everywhere i can use static colors, if one pixel sometimes at test fails then go for 2 or 3 in different locations.