SRL Archive - SRL Suggestions

Uneccesary 5 second wait in GetMMLevels


NCDS

2010-10-04 19:18:29


*******************************************************************************
Function GetMMLevels(LevelType : String;var ColorSign : String): integer;
By: Raymond / Wizzup / Sabzi
Last Edit: 29 June 2010
Description: Returns the level shown next to the minimap.
Colorsign returns the color of the text (Green,Yellow,Orange,Red).
Returns -1 if failed.
*******************************************************************************}
function GetMMLevels(LevelType: string; var ColorSign: string): Integer;
var
Colors : TIntegerArray;
Signs: TStringArray;
P: TPointArray;
TP: TPoint;
I,cl: Integer;
B: TBox;
{$ifdef Scar}
x,y : integer;
{$endif}
W,H, T: integer;
SearchBox : TBox;
Run: Boolean;
begin;
Result := -1;
ColorSign := '';
case LowerCase(Leveltype) of
'health', 'hp', 'hitpoints', 'constitution': TP := Point(715,27);
'prayer', 'pray' : TP := Point(730,66);
'summon', 'summoning' : TP := Point(715,140);
'run','energy' :
begin
TP := Point(730,105);
Run := True;
end;
else
begin;
srl_Warn('GetMMLevels', 'Invalid LevelType: ''' + LevelType + '', warn_AllVersions);
Exit;
end;
end;
Colors := [65280, 65535, 2070783, 255];
Signs := ['Green', 'Yellow', 'Orange', 'Red'];
GetClientDimensions(w,h); //We donnot want to search out of the clients area!
SearchBox := IntToBox(TP.X, TP.Y, Min(w-1,TP.X + 30), min(h-1,TP.Y + 15));
for I := 0 to 3 do
begin
if Run then
begin
MarkTime(T);
cl := GetColor(749, 118);
repeat
if not IsResting then Break;
{$ifdef Simba}
if CountColorTolerance(cl, 730, 105, 760, 120, 20) = 215 then Break;
{$else}
if not FindColorComp(x, y, clYellow, ccBlue, 730, 107, 742, 108, 130) then Break;
{$endif}
until (TimeFromMark(T) >= 5000);
end; //Do not search outside the client
With SearchBox do
FindColorsTolerance(P, Colors[i], x1, y1, x2, y2, 30);
if Length(P) < 1 then
Continue;
B := GetTPABounds(P);//GetTextAtEx works better for Simba for Run
Result := StrToIntDef(GetNumbers(GetTextAtEx(B.X1 - 1 , B.Y1 - 1, 30, statChars,
False, False, 0, 0, Colors[i], 20, False, tr_Digits)), -1);
if (Result > 0) then
begin
ColorSign := Signs[i];
Exit;
end;
end;
end;
As you can see from the code, any time your getting the level of 'run', or 'energy' the function waits for 5 seconds or until you are not resting anymore.

Might I ask what the purpose of this is?

It's pretty difficult to use this to track your energy percentage while your resting when it waits until you have 100% energy anyways.

It just seems to me that something like that should not be handled in this function. Am I right about this, or do I need to make an MSI_GetMMLevels?

Narcle

2010-10-05 01:03:38

From: NCDS

As you can see from the code, any time your getting the level of 'run', or 'energy' the function waits for 5 seconds or until you are not resting anymore.

Might I ask what the purpose of this is?

It's pretty difficult to use this to track your energy percentage while your resting when it waits until you have 100% energy anyways.

It just seems to me that something like that should not be handled in this function. Am I right about this, or do I need to make an MSI_GetMMLevels?


I was curious about this too, but its there for a reason. When I was trying to fix a bug it was having (which I never did that satisfied me) I found out what it was for. When you are resting there is a yellow haze that fades in and out around the button, due to this it waits until the color count is counted correctly. This is necessary because of the function RestUntil.

Edit:
Note it only goes into that loop if your resting.

NCDS

2010-10-05 08:47:26

From: Narcle
I was curious about this too, but its there for a reason. When I was trying to fix a bug it was having (which I never did that satisfied me) I found out what it was for. When you are resting there is a yellow haze that fades in and out around the button, due to this it waits until the color count is counted correctly. This is necessary because of the function RestUntil.

Edit:
Note it only goes into that loop if your resting.


Wouldn't it seem that the wait should be handled in RestUntil then? That's basically what I'm implementing into MSI, but it's a random 'Energy', and therefor has little time to be waiting 5 seconds no matter what. Still, that would be quite inaccurate to wait 5 seconds in the function that is only supposed to wait until your energy is at a certain level. I would imagine RestUntil has the same problems I was having until I saw this. I can confirm whether or not that's true in just a little while.

Also, even when you have 100% energy, if your still resting, it's still waiting if that 5 seconds isn't up yet.

Idk, just seems a bit foolish to me to have it executed that way, but I can just put an edited version in MSI I suppose.

Narcle

2010-10-05 13:32:16

From: NCDS
Wouldn't it seem that the wait should be handled in RestUntil then? That's basically what I'm implementing into MSI, but it's a random 'Energy', and therefor has little time to be waiting 5 seconds no matter what. Still, that would be quite inaccurate to wait 5 seconds in the function that is only supposed to wait until your energy is at a certain level. I would imagine RestUntil has the same problems I was having until I saw this. I can confirm whether or not that's true in just a little while.

Also, even when you have 100% energy, if your still resting, it's still waiting if that 5 seconds isn't up yet.

Idk, just seems a bit foolish to me to have it executed that way, but I can just put an edited version in MSI I suppose.


I just checked again and recalled exactly why. When your resting the 'haze' actually distorts the reading of the text. So it goes into the loop and waits until it can read the text correctly.

NCDS

2010-10-05 14:08:39

From: Narcle
I just checked again and recalled exactly why. When your resting the 'haze' actually distorts the reading of the text. So it goes into the loop and waits until it can read the text correctly.


Ah I see what your saying. I guess I'll see what I can do to work around that. However, if you change CountColorTolerance() = 215 to CountColorTolerance() > 215, it work's great.

Only was tested like that once, but like I said, I'll work with it.

Sabzi

2010-10-05 17:15:30

Most of the time it won't wait that 5 sec, but breaks out iirc.
And the reason is what Narcle said.
Feel free to change it for a better alternative.
I myself is not satisfied with that fix, but I was still a noob when made that :D.

EDTI: Actually, I am surprised it's still there.

Coh3n

2010-10-05 17:19:34

From: NCDS
Ah I see what your saying. I guess I'll see what I can do to work around that. However, if you change CountColorTolerance() = 215 to CountColorTolerance() > 215, it work's great.

So if making that change will get rid of the needless wait, I don't see any reason for it not to be committed. As long as it still works for all MM levels, while and while not resting, no confusing, etc.

NCDS

2010-10-05 18:10:38

From: Sabzi
Most of the time it won't wait that 5 sec, but breaks out iirc.
And the reason is what Narcle said.
Feel free to change it for a better alternative.
I myself is not satisfied with that fix, but I was still a noob when made that :D.

EDTI: Actually, I am surprised it's still there.


if Run then
begin
MarkTime(T);
cl := GetColor(749, 118);
repeat
if not IsResting then Break;
{$ifdef Simba}
if CountColorTolerance(cl, 730, 105, 760, 120, 20) = 215 then Break;
{$else}
if not FindColorComp(x, y, clYellow, ccBlue, 730, 107, 742, 108, 130) then Break;
{$endif}
until (TimeFromMark(T) >= 5000);
end;
"if CountColorTolerance(cl, 730, 105, 760, 120, 20) = 215 then" is only true if not resting. Therefor, this function waits 5 seconds, no matter what, as long as your resting. Keep in mind, you can still be resting even with 100% energy.

From: Coh3n
So if making that change will get rid of the needless wait, I don't see any reason for it not to be committed. As long as it still works for all MM levels, while and while not resting, no confusing, etc.

After messing with it a bit more, changing "if CountColorTolerance(cl, 730, 105, 760, 120, 20) = 215 then" to "if CountColorTolerance(cl, 730, 105, 760, 120, 20) > 215 then" works quite well.

However, like Narcle said, when resting it does occasionally mis-read the value of your energy, but usually gets it right the try after it missed.

Therefor, the only time this would mess anything up would be if you were checking your energy % without a loop. Who/What would be the purpose of doing that? I couldn't think of one either..

As for effecting RestUntil…if anything, this should make it work, as I don't see how it could have before…it was waiting 5 seconds every time it looped through, which would have caused it to wait until the player had 100% energy in most cases anyways. I can test/verify this if needed.

Coh3n

2010-10-05 23:13:58

From: NCDS

Therefor, the only time this would mess anything up would be if you were checking your energy % without a loop. Who/What would be the purpose of doing that? I couldn't think of one either..

RunEnergy() sets your run to true when you're at a certain energy level. I'm assuming it doesn't use a loop.

When you say it fails.. does it return -1 or does it return the wrong number?

Sabzi

2010-10-06 11:43:54

From: NCDS
"if CountColorTolerance(cl, 730, 105, 760, 120, 20) = 215 then" is only true if not resting. Therefor, this function waits 5 seconds, no matter what, as long as your resting. Keep in mind, you can still be resting even with 100% energy.


Then I didn't recall correctly :), my bad.

[off]Is it just me or villavu gone bold letters?[/off]

NCDS

2010-10-06 12:11:40

From: Coh3n
RunEnergy() sets your run to true when you're at a certain energy level. I'm assuming it doesn't use a loop.

When you say it fails.. does it return -1 or does it return the wrong number?

Wrong number.
I'll hopefully have a bit of time today to see what we can do to work around this.

From: Sabzi
Then I didn't recall correctly :), my bad.

Not a big deal ;)

NCDS

2010-10-06 19:57:43

Ok, so as is with the change in GetMMLevels, RunEnergy works 7/10 times that I tested. Clearly not reliable enough.

However, by adding these few changes/additions to RunEnergy (where the 5 second wait really should have been the whole time), it works a perfect 10/10.


function RunEnergy(Min: Integer): Boolean;
var
T: Integer;
s: String;
begin
T := GetSystemTime + 5000;
while (T > GetSystemTime) do
begin
Result := (GetMMLevels('run', s) >= Min);
if (Result) then
begin
SetRun(True);
Exit;
end;
end;
end;

Coh3n

2010-10-06 20:08:03

So what are the overall changes?

The wait in GetMMLevels is removed and added to RunEnergy? And both functions work 10/10 with these changes?

NCDS

2010-10-06 20:13:13

You got it :)

Both new functions:

function GetMMLevels(LevelType: string; var ColorSign: string): Integer;
var
Colors : TIntegerArray;
Signs: TStringArray;
P: TPointArray;
TP: TPoint;
I,cl: Integer;
B: TBox;
{$ifdef Scar}
x,y : integer;
{$endif}
W,H, T: integer;
SearchBox : TBox;
begin;
Result := -1;
ColorSign := '';
case LowerCase(Leveltype) of
'health', 'hp', 'hitpoints', 'constitution': TP := Point(715,27);
'prayer', 'pray' : TP := Point(730,66);
'summon', 'summoning' : TP := Point(715,140);
'run','energy' : TP := Point(730,105);
else
begin;
srl_Warn('GetMMLevels', 'Invalid LevelType: ''' + LevelType + '', warn_AllVersions);
Exit;
end;
end;
Colors := [65280, 65535, 2070783, 255];
Signs := ['Green', 'Yellow', 'Orange', 'Red'];
GetClientDimensions(w,h); //We donnot want to search out of the clients area!
SearchBox := IntToBox(TP.X, TP.Y, Min(w-1,TP.X + 30), min(h-1,TP.Y + 15));
for I := 0 to 3 do
begin
With SearchBox do
FindColorsTolerance(P, Colors[i], x1, y1, x2, y2, 30);
if Length(P) < 1 then
Continue;
B := GetTPABounds(P);//GetTextAtEx works better for Simba for Run
Result := StrToIntDef(GetNumbers(GetTextAtEx(B.X1 - 1 , B.Y1 - 1, 30, statChars,
False, False, 0, 0, Colors[i], 20, False, tr_Digits)), -1);
if (Result > 0) then
begin
ColorSign := Signs[i];
Exit;
end;
end;
end;

function RunEnergy(Min: Integer): Boolean;
var
T: Integer;
s: String;
begin
T := GetSystemTime + 5000;
while (T > GetSystemTime) do
begin
Result := (GetMMLevels('run', s) >= Min);
if (Result) then
begin
SetRun(True);
Exit;
end;
end;
end;
10/10.

Coh3n

2010-10-06 20:21:12

Okay, committed. :)