SRL Archive - SRL Suggestions

GameTab&AntiRandoms.scar


EvilChicken!

2010-08-05 05:06:13

All right, I've got two suggestions. The one concerning GameTab.scar is rather simple, simply add a "Wait(250 + Random(300));" in the places I've marked with a comment arrow:
function GameTab(Tab: Integer): Boolean;
var
tP: TPoint;
T, Tries: Integer;

begin
Result := false;
if (not(InRange(Tab, Tab_Combat, Tab_LogOut))) then
begin
SRL_Warn('GameTab', 'Tab ' + IntToStr(Tab) + ' is not a valid tab number.', warn_AllVersions);
Exit;
end;

Result := (GetCurrentTab = Tab);
if (Result) then exit;

if (TabExists(Tab)) then
begin
tP := Point((Tab - 21) mod 8 * 30 + RandomRange(527, 545),
(Tab - 21) div 8 * 298 + RandomRange(177, 197));
if (Tab = tab_LogOut) then
tP := Point(RandomRange(747, 760), RandomRange(3, 18));

Tries := 0;
while ((Tries < 3) and (not (Result))) do
begin
Mouse(tP.X, tP.Y, 0, 0, True);

T := GetSystemTime;
while (not Result) and (GetSystemTime - T < 2000) do
begin
Result := (GetCurrentTab = Tab);
Wait(100 + Random(100));
end;

Inc(Tries);
end;
if (Result) then // <-
Wait(250 + Random(300)); // <-
end else
SRL_Warn('GameTab', 'GameTab ' + IntToStr(Tab) + ' is not a valid tab number.', warn_Notice);
end;

This would completely remove the need for code like this:
if (GetCurrentTab <> tab_Equip) then
begin
if (not GameTab(tab_Equip)) then exit;
Wait(250 + Random(300));
end;

To present an actual example of this being a problem; the current CountEquippedItems; in the very same include, rarely functions due to this pseudo-bug. A fix with the current gameTab(); would be this:
function CountEquippedItems: Integer;
var
I: Byte;
begin
Result := -1;

if (GetCurrentTab <> tab_Equip) then
begin
if (not GameTab(tab_Equip)) then exit;
Wait(250 + Random(300));
end;
Result := 0;

for I := 1 to 11 do
if WearingItem(I) then
Inc(Result);
end;
:but with the gameTab(); fix implemented, the above code could be shortened to this:
function CountEquippedItems: Integer;
var
I: Byte;
begin
Result := Integer(GameTab(tab_Equip)) - 1;
if (Result = -1) then exit;

for I := 1 to 11 do
if WearingItem(I) then
Inc(Result);
end;
Much better, no? And remember that the mentioned example is only one of many cases which this issue relates to.
Hahah, I'm sorry to make such a big deal out of two additional lines – but as this is a very commonly used function in SRL, I want to specify clear reasons for altering it.


The second subject relates to FindFight in AntiRandoms.scar, which currently is in a horrible state:
function FindFight: Boolean;
begin
Result := False;
if (not LoggedIn) then exit;
if (CountColor(10496, 200, 130, 280, 180) + CountColor(198716, 200, 130, 280, 180) > 50) then
begin
if (CheckHpFirst) and (HpPercent = 100) then exit;

Result := True;
AddToSRLLog('******** FOUND FIGHTING RANDOM ********');
WriteLn('******** FOUND FIGHTING RANDOM ********');
TakeScreen('Found Fight');
Inc(RandSolved[rand_Fight]);
end;
end;
That doesn't look too reliable in my eyes, at least. Our dear friend Frement has made a little something that looks far more viable, even to such a degree that Coh3n already has committed an earlier version of his work into /skill/Fighting.scar – but I had slightly bigger plans in mind; we take Frement's InFight, move it to /core/AntiRandoms/AntiRandoms.scar, and replace the contents of the current FindFight function (shown above) into simply becoming "Result := InFight;", with the debugging lines and such of course following that line. VoilĂ , you would have an easily accessible function to check for fights (which is a feature not only limited to fighting scripts!) – and SRL gets a stable FindFight. Agree/disagree?

By the way, if/when this gets committed, I'll also commit this in the same go. It's all still related to GameTab.scar anyway.


Any comments, thoughts, suggestions or additional ideas will be greatly appreciated!

Cigue

2010-08-05 05:23:56

There are no fighting randoms anymore? Otherwise, I love your stuff.

ZephyrsFury

2010-08-05 05:34:49

Why is this wait so important? Is it to compensate for lag?

Narcle

2010-08-05 06:00:18

In some cases the wait after switching GameTabs isn't needed, however I believe the short wait wouldn't be bad. When you switch to the inventory tab for instance the items don't load instantly so anything dealing with items doesn't work (but you don't really notice this as 99% of the time the invy tab is open) - this is also why the wait in equipment is necessary correct? All in all I would sacrifice the time it "wastes" to make sure the following functions work in conjunction with it.

As Cigue mentioned there is no more fighting randoms so really that function can be removed. I think a reliable InFight function should be in the core though, this is used for more then just fighting scripts.

EvilChicken!

2010-08-05 13:31:48

From: Narcle
In some cases the wait after switching GameTabs isn't needed, however I believe the short wait wouldn't be bad. When you switch to the inventory tab for instance the items don't load instantly so anything dealing with items doesn't work, this is also why the wait in equipment is necessary correct?


Yes, that is exactly what I mean – and also answers your question well, Zeph.

From: Narcle
All in all I would sacrifice the time it "wastes" to make sure the following functions work in conjunction with it.


So you're okay with this change?

From: Narcle
As Cigue mentioned there is no more fighting randoms so really that function can be removed. I think a reliable InFight function should be in the core though, this is used for more then just fighting scripts.


All right, I'll remove InFight in /AntiRands/ and /skill/. In what include would a general InFight go?
And, would it be any harm in simply removing FindFight without having to have it refer to any other functions? I mean, I don't think the current FindFight is used in many scripts.. :p

Narcle

2010-08-05 16:14:54

From: EvilChicken!
So you're okay with this change?

Yes I am.
From: EvilChicken!

All right, I'll remove InFight in /AntiRands/ and /skill/. In what include would a general InFight go?
And, would it be any harm in simply removing FindFight without having to have it refer to any other functions? I mean, I don't think the current FindFight is used in many scripts.. :p


Pretty sure FindFight can be removed without problems, it will only mess up the old out of date scripts. I'm not sure where InFight would go. The only thing this might mess up is some fighters use the name InFight for their function and don't include fighting.scar. Fighting is so common though, it definitely should be in the core somewhere. /ponder

EvilChicken!

2010-08-05 16:40:10

From: Narcle
The only thing this might mess up is some fighters use the name InFight for their function and don't include fighting.scar. Fighting is so common though, it definitely should be in the core somewhere. /ponder


"srl_InFight"?

And, the most fitting place in my opinion would be Globals.scar, no?

Frement

2010-08-05 17:18:40

So this is the final version of InFIght:

var
HP_BAR_GREEN, HP_BAR_RED, HP_BAR_HITS: TIntegerArray;
HP_BAR_MIN, HP_BAR_MAX: Integer;

const
HP_BAR_TOL = 3;
HP_BAR_WIDTH = 57;
HP_BAR_HEIGHT = 7;

procedure DeclareHPBar;
begin
HP_BAR_GREEN := [49499, 52611, 51081, 52641, 47667];
HP_BAR_RED := [590010, 590002, 131211, 524453, 594402];
HP_BAR_HITS := [1325811, 1320341, 16294162, 12937740, 14185741, 4297620];
HP_BAR_MIN := HP_BAR_WIDTH * HP_BAR_HEIGHT / 10 - HP_BAR_TOL;
HP_BAR_MAX := HP_BAR_WIDTH * HP_BAR_HEIGHT * 3 / 2 + HP_BAR_TOL;
end;

function InFight: Boolean;
var
TPA1, TPA2: TPointArray;
Colors: T2DIntegerArray;
I, C: Integer;
begin
Colors := [HP_BAR_GREEN, HP_BAR_RED, HP_BAR_HITS];
for I := 0 to 1 do
begin
for C := 0 to High(Colors[I]) do
begin
FindColorsTolerance(TPA1, Colors[I][C], MSCX - 25, MSCY - 40, MSCX + 25, MSCY - 15, 30);
TPA2 := CombineTPA(TPA1, TPA2);
end;
end;
Result := InRange(GetArrayLength(TPA2), HP_BAR_MIN, HP_BAR_MAX);
end;

NCDS

2010-08-05 17:41:55

Why not just use WaitFunc() for the GameTab fix? Surely if you were to wait 250ms each loop it would give enough time for the items pic's to load?

EvilChicken!

2010-08-05 19:25:47

Globals.scar:
- Added a version of Frement's srl_InFight; function, put it in /core/Globals.scar.
> Made InFight in /skill/Fighting.scar refer to srl_InFight;

AntiRandoms/AntiRandoms.scar:
- Removed FindFight.

GameTab.scar:
- Altered GameTab();
> http://villavu.com/forum/showthread.php?p=728901
> Also removed the second srl_Warn regarding updating constants; it would anyway never be called as the first srl_warn would exit the function

if the requested tab was invalid.
- Slightly shortened CountEquippedItems; and WearingItem();
- added R!ch!e's Objective functions, slightly altered.
> http://villavu.com/forum/showthread.php?t=51515

/misc/Path.scar:
- Not sure if anyone even aknowledges it's existense, but I anyway made it compile with Simba in order to get Compile SRL.scar to work again. Not sure if I did everything correctly, but it should be working again.

Compile SRL.scar:
- I'm surprised nobody has fixed this earlier, but it anyway compiles again now. Luckily all that needed to be fixed was Path.scar.


I guess we can add a "committed" tag to this thread now.