SRL Archive - OSR Help

HpPercent broken?


l6bustank

2013-01-30 05:54:10

Trying to make my script check for hp while its fighting but it keeps stopping with an error in GameTab (right about where the HpPercent function is located).

This is the code that causes the script to stop:

While (SRL_InFight) do
begin
repeat
If (HpPercent<50) then
begin
Writeln('hp less than 50%, stopping');
TerminateScript;
end else
Wait(RandomRange(100, 200));
until TimeFromMark(Counter)>10000
end;

and this is the error:

Error: Out Of Range at line 1631
The following DTMs were not freed: [SRL - Lamp bitmap, 1]
The following bitmaps were not freed: [SRL - Mod bitmap, SRL - Admin bitmap, SRL - Flag bitmap, SRL - NavBar Bitmap, SRL - Options Bitmap, 5]

any advice?

Justin

2013-01-30 06:14:37

I was able to replicate the problem, I didn't have any Player Declarations.

To fix this, add this function:


Procedure DeclarePlayers;
Begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
With Players[0] Do
Begin
Name := '';
Pass := '';
Active := True;
End;
End;

Then after you have

SetupSRL;

Add:

DeclarePlayers;

My test script (Returned Out Of Range)

program new;
{$I SRL/SRL.Simba}

begin
SetupSRL;
writeln(HPPercent);
end.

Script that didn't error and returned a value:


program new;
{$I SRL/SRL.Simba}

Procedure DeclarePlayers;
Begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
With Players[0] Do
Begin
Name := '';
Pass := '';
Active := True;
End;
End;


begin
SetupSRL;
DeclarePlayers;
writeln(HPPercent);
end.

I also noticed that HpPercent returned 400 (400%) because of the EoC Update

HP Level: 99
HP orb: 3960

I know @Ashaman88 has a solution for this in his LRC miner. I have mentioned him in this thread in hope he will read this and also help you with this problem

E: I have just opened a bug report (http://villavu.com/forum/project.php?issueid=34) Hope this issue will get fixed in the next SRL update so you wont need to add a custom function for this.

l6bustank

2013-01-30 06:23:51

lmao, I was missing DeclarePlayers from my main loop :D. Thanks Justin

Justin

2013-01-30 06:28:26

From: l6bustank
lmao, I was missing DeclarePlayers from my main loop :D. Thanks Justin


No worries. Also no need to have DeclarePlayers in your main loop as it only needs to be called once. Let me know if you don't understand what I mean

Sjoe

2013-01-30 06:31:50

From: l6bustank
lmao, I was missing DeclarePlayers from my main loop :D. Thanks Justin


If it's buggy try something like:

Hphealth := GetMMLevels('hp')
HalfHPhealth := HPhealth / 2
if GetMMlevels('hp') =< HalfHPhealth then ..
Just a thought :p , I'm not an advanced scripter ;)

Ashaman88

2013-01-30 07:50:27

Callin me out… I see how it is.


Function HPLevel: Integer;                                        
Var
ColourString: String;
Begin
Result:= GetMMLevels('HP', ColourString);
End;

Function GetMaxHP: Extended;
Var
Text: String;
B, BigBox: TBox;
TPA : TPointArray;
ATPA : T2DPointArray;
I,cts: Integer;
BoxColors: TIntegerArray;
Begin
GameTab(Tab_Combat);
HumanMouseBox(650,394-50,682,401-50);
Wait(RandomRange(500,700));

B := IntToBox(594, 365-50, 694, 394-50);
cts := GetColorToleranceSpeed;
ColorToleranceSpeed(1);
// Black
BoxColors := [1774603];
SetLength(ATPA, Length(BoxColors));
for i := 0 to High(BoxColors) do
FindColorsTolerance(ATPA[i], BoxColors[i], B.X1, B.Y1, B.X2, B.Y2, 0);
TPA := MergeATPA(ATPA);
If Length(TPA) < 10 Then
begin
Writeln('Not enough colors');
ColorToleranceSpeed(cts);
Exit;
end;

ATPA := SplitTPA(TPA, 4);
For i := 0 to High(ATPA) do
begin
B := GetTPABounds(ATPA[i]);
if ((B.x2-B.x1) > 4) and ((B.y2-B.y1) > 4) then
Break
else
B := IntToBox(0, 0, 0, 0);
end;

If (B.x2 = 0) then
begin
ColorToleranceSpeed(cts);
Exit;
end;

BigBox := B;

Text:= GetTextAtExWrap(BigBox.X1, BigBox.Y1, BigBox.X2, BigBox.Y2, 0, 5, 2, 3111603, 10, 'UpChars');
Text:= Copy(Text, 0, High(Text)-1);
If (StrToIntDef(Text, 0)=100) Then
Result:=HPLevel Else
Result:= (HPLevel*100)/(StrToIntDef(Text, 0));
End;


Have a variable called maxhp. Do maxhp:=getmaxhp; once at the setup of your script, then do checks for your hp lvl.


If ((HPLevel < (HP*0.80))) Then
Begin
If HPLevel=-1 Then
Exit;

That 80 you can replace with whatevers