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:
This would completely remove the need for code like this:
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:
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:
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!
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!