SRL Archive - Discussions and Debates

SRL 12 & 13 FindFight / HpPercent


PriSoner

2008-02-05 23:19:37

I've worked out the problem read post #5

Ok.. i've hunted and looked, I may be going word blind but I can't figure out where you're supposed to post bug report with SRL releases so here it is.. Please pass it on to the relevent section if here is not good enough..

I'm experiencing a problem in my script with the SRL FindFight function and reading through other user comments many others appear to be waking up dead. :confused:

The Error applies with or without SMART.

Basically it doesn't work any more. It detects a fight in the area but never returns true.

I've gone though the code bit by bit and tested each if statement and each function within it but can't for the life of me find out where it's failing…

From the behaviour of the function when a fight is in progress I track it down to this if statement: if (HpPercent < 100) then but when I test HpPercent seperatly or even the whole if statement by itself it appears to function correctly..

Am I going mad? What's missing?

{*******************************************************************************
function FindFight: Boolean;
by: Stupid3ooo
Description: Results True if in Fight
*******************************************************************************}

function FindFight: Boolean;
var
xf, yf,CurTab: Integer;
begin

if (FindColor(xf, yf, 65280, 217, 129, 297, 209)) then
begin
Curtab := GetCurrentTab;
if (CheckHpFirst = True) then
begin
GameTab(2);
Wait(500 + Random(100));
if (HpPercent < 100) then
begin
Result := True;
WriteLn('******** FOUND FIGHTING RANDOM ********');
WriteFileString(TheFile, '******** FOUND FIGHTING RANDOM ********' +
Chr(13))
TakeScreen('Found Fight');
Fights := Fights + 1;
end;
end
else
begin
WriteLn('******** FOUND FIGHTING RANDOM ********');
WriteFileString(TheFile, '******** FOUND FIGHTING RANDOM ********' +
Chr(13))
Result := True;
TakeScreen('Found Fight');
Fights := Fights + 1;
end;
GameTab(Curtab);
end;
end;

Negaal

2008-02-06 00:53:27

There is no "Result := True;" in CheckHpFirst…

Daniel.Blaze

2008-02-06 05:29:04

CheckHPFirst is a Constant

PriSoner

2008-02-06 06:34:33

From: Negaal
There is no "Result := True;" in CheckHpFirst…


Correct.. there shouldn't be. at that pont the script has detected a fight in the vicinity and it then uses (HpPercent < 100) to find out if it is you that is involved in the fight.

In the scenarios I have witnessed the gametab keeps switching to Gametab(2) and back again but never writes the line (******** FOUND FIGHTING RANDOM ********) this implies to me that the routine fails because the condition (HpPercent < 100) is never being met. If this condition was met result would equal true. whenever I test that specific part of the function though I always get the correct reults, yet in practice it doesn't work.

PriSoner

2008-02-06 07:07:11

Found it…

The FindFight routine posting below is the one from SRL 12 & 13.. The one I originally posted above was from SRL 11, which was when it was working.. No wonder I couldn;t find what was at fault.! :mad:
{*******************************************************************************
function FindFight: Boolean;
by: Stupid3ooo
Description: Results True if in Fight
*******************************************************************************}

function FindFight: Boolean;
var
xf, yf,CurTab: Integer;
begin

if (FindColor(xf, yf, 65280, 217, 129, 297, 209)) then
begin
Curtab := GetCurrentTab;
if CheckHpFirst then
begin
GameTab(2);
Wait(500 + Random(100));
if (HpPercentEx < 100) then
begin
Result := True;
WriteLn('******** FOUND FIGHTING RANDOM ********');
WriteFileString(TheFile, '******** FOUND FIGHTING RANDOM ********' +
Chr(13))
TakeScreen('Found Fight');
Fights := Fights + 1;
end;
end
else
begin
WriteLn('******** FOUND FIGHTING RANDOM ********');
WriteFileString(TheFile, '******** FOUND FIGHTING RANDOM ********' +
Chr(13))
Result := True;
TakeScreen('Found Fight');
Fights := Fights + 1;
end;
GameTab(Curtab);
end;
end;

if you notice (HpPercent < 100) is now (HpPercentEx < 100)

HpPercentEx is a new function and relies on Players[x].Level[8] being set.

Not something that most scripts do..

FindFight has been changed to use this as HpPercentEx uses GetMMLevels which means that HP can be checked without switching gametabs. Bizarely though all the gametab switching has been left in the function so it still keeps switching anyway!:confused:

I'm not sure I entirely agree with the change as it stands as it has the potential to break so many existing scripts.

Anyways if you have experienced the same problem as me and want FindFight to work in your script set Players[CurrentPlayer].Level[8].

Wizzup?

2008-02-06 09:27:27

From: PriSoner
Found it…

The FindFight routine posting below is the one from SRL 12 & 13.. The one I originally posted above was from SRL 11, which was when it was working.. No wonder I couldn;t find what was at fault.! :mad:
{*******************************************************************************
function FindFight: Boolean;
by: Stupid3ooo
Description: Results True if in Fight
*******************************************************************************}

function FindFight: Boolean;
var
xf, yf,CurTab: Integer;
begin

if (FindColor(xf, yf, 65280, 217, 129, 297, 209)) then
begin
Curtab := GetCurrentTab;
if CheckHpFirst then
begin
GameTab(2);
Wait(500 + Random(100));
if (HpPercentEx < 100) then
begin
Result := True;
WriteLn('******** FOUND FIGHTING RANDOM ********');
WriteFileString(TheFile, '******** FOUND FIGHTING RANDOM ********' +
Chr(13))
TakeScreen('Found Fight');
Fights := Fights + 1;
end;
end
else
begin
WriteLn('******** FOUND FIGHTING RANDOM ********');
WriteFileString(TheFile, '******** FOUND FIGHTING RANDOM ********' +
Chr(13))
Result := True;
TakeScreen('Found Fight');
Fights := Fights + 1;
end;
GameTab(Curtab);
end;
end;

if you notice (HpPercent < 100) is now (HpPercentEx < 100)

HpPercentEx is a new function and relies on Players[x].Level[8] being set.

Not something that most scripts do..

FindFight has been changed to use this as HpPercentEx uses GetMMLevels which means that HP can be checked without switching gametabs. Bizarely though all the gametab switching has been left in the function so it still keeps switching anyway!:confused:

I'm not sure I entirely agree with the change as it stands as it has the potential to break so many existing scripts.

Anyways if you have experienced the same problem as me and want FindFight to work in your script set Players[CurrentPlayer].Level[8].


Wrong.
When the level is not set yet, it picks the level.

The only thing you have to change is this:
function HPPercentEx: Integer;

Var
ColorString: String;
Begin
If Players[CurrentPlayer].Level[8] < 1 Then
Players[CurrentPlayer].Level[8] := Max(1, GetSkillInfo('hitpoints', False));

Result := Round(GetMMLevels('hp', ColorString) * 100 / Players[CurrentPlayer].Level[8]);
End;

Replace Min() with Max(), it will be fixed in SRL 14.


HPPercentEx actually has less potential to break, I am sorry if you don't agree on this change, if you instead want to keep it like it was (a gametab changing/clicking madness) go ahead, and change it in your own SRL.

PriSoner

2008-02-06 09:55:43

From: Wizzup?
Wrong.
When the level is not set yet, it picks the level.

Replace Min() with Max(), it will be fixed in SRL 14.

You are indeed, of course correct. please accept my appologies. :redface: The function as it stands though is currently broken and setting a value for Players[CurrentPlayer].Level[8] does work as a temporary fix until SRL is updated.

From: Wizzup?
HPPercentEx actually has less potential to break, I am sorry if you don't agree on this change, if you instead want to keep it like it was (a gametab changing/clicking madness) go ahead, and change it in your own SRL.

I completely agree the gametab clicking changing situation is complete madness and is unecesarry now. My judgement was based on me not reading the true cause of the error in HPPercentEx properly.

Don't forget though that FindFight needs updating to have the gametab switching removed, as even if HPPercentEx was working as it should have been FindFight would still gametab switch. :duh:

btw.. is this the best place to post SRL bugs?

gerauchert

2008-02-06 10:07:17

thanks for clearing that up Wizzup, I just edited the GetMMLevels to my own version because I had no clue how it would actually know your HP…makes sense now :D

Wizzup?

2008-02-15 05:36:36

From: PriSoner
You are indeed, of course correct. please accept my appologies. :redface: The function as it stands though is currently broken and setting a value for Players[CurrentPlayer].Level[8] does work as a temporary fix until SRL is updated.


I completely agree the gametab clicking changing situation is complete madness and is unecesarry now. My judgement was based on me not reading the true cause of the error in HPPercentEx properly.

Don't forget though that FindFight needs updating to have the gametab switching removed, as even if HPPercentEx was working as it should have been FindFight would still gametab switch. :duh:

btw.. is this the best place to post SRL bugs?


Hah… I'll remove the tab switching… Thanks. ;)