SRL Archive - OSR Help

Detecting if your player is in a fight.


ownedlikenoob

2011-06-19 12:07:49

I've looked everywhere for this, is there any guides on this or anything? Can't seem to find one.

Thanks

Dervish

2011-06-19 12:10:02

It is a basic reflection function afaik.

masterBB

2011-06-19 12:41:55

From: Dervish
It is a basic reflection function afaik.


That one is slow. But this has been discussed before. The easiest way is to check if you're interacting with one of the enemies.

Smarter Child

2011-06-19 12:52:36

Well if your using color, just use InFight

trojan

2011-06-19 13:02:52

Yeah you can use your characters animation, however this is in the wrong place though it should be in help

blackfire553

2011-06-19 13:42:17

i use this:
 Me := GetMe;
if (Me.Interacting <> -1) then
begin
writeln('Got a fight');
Result := true;
Exit;
end;
Me.InFight wasn't working for me. Interacting is equal to -1 if you are standing still.

DeSnob

2011-06-20 08:12:19

From: blackfire553
i use this:
 Me := GetMe;
if (Me.Interacting <> -1) then
begin
writeln('Got a fight');
Result := true;
Exit;
end;
Me.InFight wasn't working for me. Interacting is equal to -1 if you are standing still.


Yeah I've tried it before. Just do what I did, and make a color function which detects the green bit of the bar to the very left of the bar.

WT-Fakawi

2011-06-20 08:22:19

I check for the existence of Green and Red above me, and I have the XPbar open and continiously monitor the xp-counter.

Directly copied from HLR, lots of unusable vars, but you get the idea.


//----------------------------------------------------------------------------//

//-- global
FullHitBar := BitmapFromString(56, 1, 'meJxjYrdmYMhhYGgCIkaGLgw0iZlhFjJiYVgIR6wMq+CIg2EjDO3EhTgZDgARhIFHGQZazcRuDQB2WiWA');
GreenInFight = 45611; // mainscreen colors indicating we are in a fight.
RedInFight = 264387;

//----------------------------------------------------------------------------//

function IsDead:Boolean; // checks if fullhitbar in on mainscreen
var // coordbounds depend on Legit being onscreen
Dx, Dy,bx1, by1, bx2, by2:integer; // if no legits then check whole screen
begin // if legits around, only check small bounds
Dx := MMCx; // reach of range is beyond full screen.
Dy := MMCy;
if Distance2Legit > 22 then
begin
bx1 := MSx1;
by1 := MSy1
bx2 := MSx2;
by2 := MSy2;
end
else
begin
bx1 := MSCx - 75;
by1 := MSCy - 75;
bx2 := MSCx + 75;
by2 := MSCy + 75;
end;
Result := FindBitmapToleranceIn(FullHitBar, Dx, Dy, bx1, by1, bx2, by2, 50);
end;

//----------------------------------------------------------------------------//

Function InFightAt(x, y: Integer):Boolean; // Check for green or red in fight
var
dx, dy: Integer;
x1,y1,x2,y2:integer;
begin
GetMousePos(Dx, Dy);
if x - 50 < MSx1 then x1 := MSx1 else x1 := x - 50;
if y - 50 < MSy1 then y1 := MSy1 else y1 := y - 50;
if x + 50 > MSx2 then x2 := MSx2 else x2 := x + 50;
if y + 50 > MSy2 then y2 := MSy2 else y2 := y + 50;

Result := FindColorTolerance(dx, dy, GreenInFight, x1, y1, x2, y2, 20) or // green
FindColorTolerance(dx, dy, RedInFight, x1, y1, x2, y2, 20) // red
end;

//----------------------------------------------------------------------------//


Function WaitFight(Seconds:Integer):Boolean; // waits until fullhitbar or xpdif > 26
var
t, newXP, XPNeededForKill:Integer;
begin
Result := False;
If CoMaRa = 3 then Seconds := Seconds * 5; // Magic requires much longer waits
if fawkidebug then writeln('CoMArA = ' + IntToStr(Comara) + '. Goblin Timeout = ' + IntToStr(Seconds) +' Seconds.');
T := GetSystemTime;
If (Players[CurrentPlayer].Strings[0] = 'magic') or (CoMaRa = 3) then
XPNeededForKill := 76 // 51 is enough, but not always. Isdead is a better check for magic
else
XPNeededForKill := 26; // 26 is exactly ok, for all but magic
repeat
If FawkiProcDebug then writeln('IN WAITFIGHT');
newXP := GetXPBarTotal;
if FawkiDebug then Writeln('OldXP = ' + IntToStr(CurXP) + '. NewXP = ' + IntToStr(newXP) + '. Dif = ' + IntToStr(NewXP-CurXP));
if (newXP > curXP + XPNeededForKill) or IsDead then
begin
if FawkiDebug then Writeln('Full Damage Detected...Exit Fighting Loop');
stats_IncVariable('Goblins Killed', 1);
Result := True;
FTWait(8);
Case Comara of
1: Inc(ComGobs);
2: Inc(RanGobs);
3: Inc(MagGobs);
end;
if not (Players[CurrentPlayer].Strings[2] = 'pure') then PickupEssentials;
FFlag(0);
FTWait(1);
SmallReport;
Exit;
end;

If T + 15000 < GetSystemTime then // exits from any fightloop when 15 secs no fighting activity.
begin
if not InFightAt(MSCx, MSCy) then
begin
if fawkidebug then writeln('exit from waitfight: 15 secs no fight');
Result := False;
Exit;
end;
end;

If not loggedin then begin LeaveLobby; result := false; exit; end; // some quick checks.
if NoFoodBreak then // VERY DIRTY! Prevents Player from dying, by fishing till health is opk.
Begin
Result := False;
FishCycle(Players[CurrentPlayer].Strings[3]);
WhileRawFoodCook(1);
NoFoodBreak := False;
Exit;
End;
if ClickToContinue then HailMyLevel := True;
if not CheckAndRestoreHealth then Begin Result := False; Exit; End;

until (GetSystemTime > (T + (Seconds * 1000)));

Case Comara of // Oooow yes we killed it all right!
1: Inc(ComGobs);
2: Inc(RanGobs);
3: Inc(MagGobs);
end;
stats_IncVariable('Goblins Killed', 1);
if not (Players[CurrentPlayer].Strings[2] = 'pure') then PickupEssentials;
SmallReport;
end;

DeSnob

2011-06-20 08:55:27

From: WT-Fakawi
I check for the existence of Green and Red above me, and I have the XPbar open and continiously monitor the xp-counter.

Directly copied from HLR, lots of unusable vars, but you get the idea.


//----------------------------------------------------------------------------//

//-- global
FullHitBar := BitmapFromString(56, 1, 'meJxjYrdmYMhhYGgCIkaGLgw0iZlhFjJiYVgIR6wMq+CIg2EjDO3EhTgZDgARhIFHGQZazcRuDQB2WiWA');
GreenInFight = 45611; // mainscreen colors indicating we are in a fight.
RedInFight = 264387;

//----------------------------------------------------------------------------//

function IsDead:Boolean; // checks if fullhitbar in on mainscreen
var // coordbounds depend on Legit being onscreen
Dx, Dy,bx1, by1, bx2, by2:integer; // if no legits then check whole screen
begin // if legits around, only check small bounds
Dx := MMCx; // reach of range is beyond full screen.
Dy := MMCy;
if Distance2Legit > 22 then
begin
bx1 := MSx1;
by1 := MSy1
bx2 := MSx2;
by2 := MSy2;
end
else
begin
bx1 := MSCx - 75;
by1 := MSCy - 75;
bx2 := MSCx + 75;
by2 := MSCy + 75;
end;
Result := FindBitmapToleranceIn(FullHitBar, Dx, Dy, bx1, by1, bx2, by2, 50);
end;

//----------------------------------------------------------------------------//

Function InFightAt(x, y: Integer):Boolean; // Check for green or red in fight
var
dx, dy: Integer;
x1,y1,x2,y2:integer;
begin
GetMousePos(Dx, Dy);
if x - 50 < MSx1 then x1 := MSx1 else x1 := x - 50;
if y - 50 < MSy1 then y1 := MSy1 else y1 := y - 50;
if x + 50 > MSx2 then x2 := MSx2 else x2 := x + 50;
if y + 50 > MSy2 then y2 := MSy2 else y2 := y + 50;

Result := FindColorTolerance(dx, dy, GreenInFight, x1, y1, x2, y2, 20) or // green
FindColorTolerance(dx, dy, RedInFight, x1, y1, x2, y2, 20) // red
end;

//----------------------------------------------------------------------------//


Function WaitFight(Seconds:Integer):Boolean; // waits until fullhitbar or xpdif > 26
var
t, newXP, XPNeededForKill:Integer;
begin
Result := False;
If CoMaRa = 3 then Seconds := Seconds * 5; // Magic requires much longer waits
if fawkidebug then writeln('CoMArA = ' + IntToStr(Comara) + '. Goblin Timeout = ' + IntToStr(Seconds) +' Seconds.');
T := GetSystemTime;
If (Players[CurrentPlayer].Strings[0] = 'magic') or (CoMaRa = 3) then
XPNeededForKill := 76 // 51 is enough, but not always. Isdead is a better check for magic
else
XPNeededForKill := 26; // 26 is exactly ok, for all but magic
repeat
If FawkiProcDebug then writeln('IN WAITFIGHT');
newXP := GetXPBarTotal;
if FawkiDebug then Writeln('OldXP = ' + IntToStr(CurXP) + '. NewXP = ' + IntToStr(newXP) + '. Dif = ' + IntToStr(NewXP-CurXP));
if (newXP > curXP + XPNeededForKill) or IsDead then
begin
if FawkiDebug then Writeln('Full Damage Detected...Exit Fighting Loop');
stats_IncVariable('Goblins Killed', 1);
Result := True;
FTWait(8);
Case Comara of
1: Inc(ComGobs);
2: Inc(RanGobs);
3: Inc(MagGobs);
end;
if not (Players[CurrentPlayer].Strings[2] = 'pure') then PickupEssentials;
FFlag(0);
FTWait(1);
SmallReport;
Exit;
end;

If T + 15000 < GetSystemTime then // exits from any fightloop when 15 secs no fighting activity.
begin
if not InFightAt(MSCx, MSCy) then
begin
if fawkidebug then writeln('exit from waitfight: 15 secs no fight');
Result := False;
Exit;
end;
end;

If not loggedin then begin LeaveLobby; result := false; exit; end; // some quick checks.
if NoFoodBreak then // VERY DIRTY! Prevents Player from dying, by fishing till health is opk.
Begin
Result := False;
FishCycle(Players[CurrentPlayer].Strings[3]);
WhileRawFoodCook(1);
NoFoodBreak := False;
Exit;
End;
if ClickToContinue then HailMyLevel := True;
if not CheckAndRestoreHealth then Begin Result := False; Exit; End;

until (GetSystemTime > (T + (Seconds * 1000)));

Case Comara of // Oooow yes we killed it all right!
1: Inc(ComGobs);
2: Inc(RanGobs);
3: Inc(MagGobs);
end;
stats_IncVariable('Goblins Killed', 1);
if not (Players[CurrentPlayer].Strings[2] = 'pure') then PickupEssentials;
SmallReport;
end;


How would you get a bot to monitor the xp bar? I say this because it can make color bots far more accurate while woodcutting or fishing.

WT-Fakawi

2011-06-20 09:49:56

First:
  if not IsXPBarOpen then ToggleXPBar(True);
and then monitor
yourtotal := GetXPBarTotal;

Thats all :D

Home

2011-06-27 14:02:16

Moved to Scripting Help Section.

~Home

DeSnob

2011-06-28 10:44:05

From: WT-Fakawi
First:
  if not IsXPBarOpen then ToggleXPBar(True);
and then monitor
yourtotal := GetXPBarTotal;

Thats all :D


Never even knew those functions existed :O

BraK

2011-06-28 12:12:58

They are pretty new IIRC.

~BraK