SRL Archive - SRL Suggestions

SpellAvailable; edit


NCDS

2011-01-09 22:27:08


function SpellAvailable(var Coords: TBox; Spell: string): Boolean;
var
t_spArr: TstringArray;
I, II, P, CTS, X, Y, T, Fail: Integer;
Lum, H, S, L: Extended;
CurSet: TBooleanArray;
colArr: TIntegerArray;
si: TSpell;
ss: string;
ScrollB: Boolean;
begin
if not LoggedIn then
Exit;
if not SpellSetUp then
SetupSpells;

{
if (FindColor(X, Y, 2070783, MIX1, MIY1, MIX2, MIY2)) then
begin
MouseBox(MMX1, MMY1, MMX2, MMY2, 3);
Wait(100+Random(300));
end;
}

for I := 0 to 1 do
begin
case BookSortedBy of
BookSort_Level:
t_spArr := ['lumbridge home teleport', 'wind rush', 'wind strike', 'confuse', 'enchant crossbow bolt', 'water strike', 'lvl-1 enchant',
'earth strike', 'mobilising armies teleport', 'weaken', 'fire strike', 'bones to bananas', 'wind bolt', 'curse', 'bind', 'low level alchemy',
'water bolt', 'varrock teleport', 'lvl-2 enchant', 'earth bolt', 'lumbridge teleport', 'telekinetic grab',
'fire bolt', 'falador teleport', 'crumble undead', 'teleport to house', 'wind blast', 'superheat item', 'camelot teleport',
'water blast', 'lvl-3 enchant', 'iban blast', 'snare', 'magic dart', 'ardougne teleport', 'earth blast', 'high level alchemy',
'charge water orb', 'lvl-4 enchant', 'watchtower teleport', 'fire blast', 'charge earth orb', 'bones to peaches',
'saradomin strike', 'claws of guthix', 'flames of zamorak', 'trollheim teleport', 'wind wave', 'charge fire orb',
'teleport to ape atoll', 'water wave', 'charge air orb', 'vulnerability', 'lvl-5 enchant', 'earth wave', 'enfeeble',
'teleother lumbridge', 'fire wave', 'entangle', 'stun', 'charge', 'wind surge', 'teleother falador', 'teleport block', 'water surge',
'lvl-6 enchant', 'earth surge', 'teleother camelot', 'fire surge'];

BookSort_Combat:
t_spArr := ['wind rush', 'wind strike', 'water strike', 'earth strike', 'fire strike', 'confuse', 'weaken', 'curse', 'wind bolt', 'water bolt',
'earth bolt', 'fire bolt', 'bind', 'crumble undead', 'wind blast', 'water blast', 'earth blast', 'fire blast', 'iban blast',
'snare', 'magic dart', 'wind wave', 'water wave', 'earth wave', 'fire wave', 'saradomin strike', 'claws of guthix',
'flames of zamorak', 'wind surge', 'water surge', 'earth surge', 'fire surge', 'vulnerability', 'enfeeble', 'entangle', 'stun', 'charge', 'teleport block', 'lvl-1 enchant',
'lvl-2 enchant', 'lvl-3 enchant', 'lvl-4 enchant', 'lvl-5 enchant', 'lvl-6 enchant', 'enchant crossbow bolt', 'superheat item', 'charge water orb',
'charge earth orb', 'charge fire orb', 'charge air orb', 'low level alchemy', 'high level alchemy', 'telekinetic grab', 'bones to bananas',
'bones to peaches', 'lumbridge home teleport', 'mobilising armies teleport', 'varrock teleport', 'lumbridge teleport', 'falador teleport',
'teleport to house', 'camelot teleport', 'ardougne teleport', 'watchtower teleport', 'trollheim teleport', 'teleport to ape atoll',
'teleother lumbridge', 'teleother falador', 'teleother camelot'];

BookSort_Teleport:
t_spArr := ['lumbridge home teleport', 'mobilising armies teleport', 'varrock teleport', 'lumbridge teleport', 'falador teleport',
'teleport to house', 'camelot teleport', 'ardougne teleport', 'watchtower teleport', 'trollheim teleport', 'teleport to ape atoll',
'teleother lumbridge', 'teleother falador', 'teleother camelot', 'low level alchemy', 'high level alchemy', 'telekinetic grab', 'bones to bananas',
'bones to peaches', 'lvl-1 enchant', 'lvl-2 enchant', 'lvl-3 enchant', 'lvl-4 enchant', 'lvl-5 enchant', 'lvl-6 enchant', 'enchant crossbow bolt', 'superheat item',
'charge water orb', 'charge earth orb', 'charge fire orb', 'charge air orb', 'wind strike', 'water strike', 'earth strike', 'fire strike', 'confuse',
'weaken', 'curse', 'wind bolt', 'water bolt', 'earth bolt', 'fire bolt', 'bind', 'crumble undead', 'wind blast', 'water blast', 'earth blast',
'fire blast', 'iban blast', 'snare', 'magic dart', 'wind wave', 'water wave', 'earth wave', 'fire wave', 'saradomin strike', 'claws of guthix',
'flames of zamorak', 'wind surge', 'water surge', 'earth surge', 'fire surge', 'vulnerability', 'enfeeble', 'entangle', 'stun', 'charge', 'teleport block'];

else
begin
Inc(Fail);
MouseBox(MIX1, MIY2-30, MIX2, MIY2-20, 3);
Wait(200 + random(100));
if (Fail = 2) then
begin
SRL_Warn('Cast', 'Invalid BookSort', warn_AllVersions);
Exit;
end;
end;
end; // case

if (Fail = 0) then Break;
end; //for-loop


if not InStrArr(Spell, t_spArr, False)then
begin
srl_Warn('Cast', 'Incorrect spell', warn_AllVersions);
Exit;
end;

if not InIntArray([SpellMode_Combat, SpellMode_Teleport,
SpellMode_Misc, SpellMode_Skill], SpellIsSort(Spell))then
begin
srl_Warn('Cast', 'Incorrect spellkind', warn_AllVersions);
Exit;
end;

if BookSortedBy = BookSort_Level then
SortBook(BookSort_Level);

CurSet := SpellsAvailable;
I := SpellIsSort(Spell);
if not CurSet[I] then
begin
CurSet[I] := True;
SetSpellMode(CurSet[SpellMode_Combat], CurSet[SpellMode_Teleport], CurSet[SpellMode_Misc], CurSet[SpellMode_Skill]);
end;

for I:=0 to 3 do
if not CurSet[I] then
for II:=0 to High(SpellModes[I])do
if InStrArrEx(SpellModes[I][II].Name, t_spArr, P)then
DeleteValueInStrArray(t_spArr, P);

if not InStrArrEx(Spell, t_spArr, P)then
begin
srl_Warn('Cast', 'Cast function error', warn_AllVersions);
Exit;
end;

if InStrArrEx('enchant crossbow bolt', t_spArr, II)then
if (P > II)then
begin
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.02, 0.70);
if (CountColorTolerance(1147846, MIX1, MIY1, MIX2, MIY2, 13) < 14) then
Dec(P);
ColorToleranceSpeed(CTS);
SetColorSpeed2Modifiers(0.2, 0.2);
end;

ScrollB := (GetColor(734, 207) = 5794936); // True if scrollbar is present

if (ScrollB) then
begin
Coords.X1 := P mod 6 * 24 + 565;
Coords.Y1 := P div 7 * 24 + 217;
Coords.X2 := Coords.X1 + 15;
Coords.Y2 := Coords.Y1 + 15;
end else
begin
Coords.X1 := P mod 7 * 24 + 562;
Coords.Y1 := P div 7 * 24 + 217;
Coords.X2 := Coords.X1 + 15;
Coords.Y2 := Coords.Y1 + 15;
end;

if (ScrollB)and(P > 53)then
begin
ScrollSpellBook(False);
Coords.Y1 := Coords.Y1 - 80;
Coords.Y2 := Coords.Y1 + 15;
end else
ScrollSpellBook(True);

si := GetSpellInfo(Spell);
ss := Copy(si.Name, 2, 3);
if (not (WaitUpText(ss, 500))) then
MouseBox(Coords.X1, Coords.Y1, Coords.X2, Coords.Y2, 3);
T := GetSystemTime + 2000;
while (GetSystemTime < T) do
if FindColor(X, Y, 2070783, MIX1, MIY1, MIX2, MIY2) then
Break;

colArr := GetColors(TPAFromBox(Coords));
ClearSameIntegers(colArr);
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.72, 1.05);
for II := 0 to High(colArr) do
begin
if (SimilarColors(colArr[II], 3292228, 3)) then Continue;
ColorToHSL(colArr[II], H, S, L);
Lum := MaxE(Lum, L);
end;
SetColorSpeed2Modifiers(0.2, 0.2);
ColorToleranceSpeed(CTS);
Result := (Lum > 40.0);
end;
Specifically:

si := GetSpellInfo(Spell);
ss := Copy(si.Name, 2, 3);
if (not (WaitUpText(ss, 500))) then
MouseBox(Coords.X1, Coords.Y1, Coords.X2, Coords.Y2, 3);

What this does is checks to see if the mouse is already hover the spell it's about to cast.

Why? Because when casting spells such as High Alchemy, Most people (or at least me personally) don't move the mouse every time they click to cast the spell. Before, it would always move the mouse because MouseBox was always called. With this edit however, it will check the UpText to see if you are already hovering the spell and just click instead of moving the mouse over the same spell your already hovering to click it.

Not a big deal, but I certainly think it looks more human-like.

I've tested this and yes it does work.

Let me know if there are any questions. My apologies if anything is unclear, I've been drinking a bit. >.<

kitchenrange

2011-01-09 23:07:38

I've added something similiar to my fighting script. The same situation comes up and I also believe it looks much more humanlike.

Frement

2011-01-10 00:44:12

Nice, finally! :)

lordsaturn

2011-01-10 12:20:04

Next time post diff.

NCDS

2011-01-10 14:57:31

From: lordsaturn
Next time post diff.



Index: magic.scar
===================================================================
--- magic.scar (revision 674)
+++ magic.scar (working copy)
@@ -646,6 +646,8 @@
Lum, H, S, L: Extended;
CurSet: TBooleanArray;
colArr: TIntegerArray;
+ si: TSpell;
+ ss: string;
ScrollB: Boolean;
begin
if not LoggedIn then
@@ -786,7 +788,10 @@
end else
ScrollSpellBook(True);

- MouseBox(Coords.X1, Coords.Y1, Coords.X2, Coords.Y2, 3);
+ si := GetSpellInfo(Spell);
+ ss := Copy(si.Name, 2, 3);
+ if (not (WaitUpText(ss, 500))) then
+ MouseBox(Coords.X1, Coords.Y1, Coords.X2, Coords.Y2, 3);
T := GetSystemTime + 2000;
while (GetSystemTime < T) do
if FindColor(X, Y, 2070783, MIX1, MIY1, MIX2, MIY2) then
@@ -842,7 +848,7 @@
GetMousePos(X, Y);
if AutoCast then
begin
- if not WaitUpText('Autocast', 120+Random(100)) then
+ if not WaitUpTextMulti(['Autocast', 'ocast', 'utoca'], 300+Random(100)) then
Exit;

if not(CountColor(16711422, B.X1-10, B.Y1-10, B.X2+10, B.Y2+10) > 50) then
@@ -855,9 +861,9 @@

Mouse(X, Y, 0, 0, not SInfo.AutoCast);
if SInfo.AutoCast then
- Result := WaitOption('Cast', 120+Random(100))
+ Result := WaitOptionMulti(['Cast', 'ast', 'Cas'], 300+Random(100))
else
- Result := WaitUpText('Cast', 120+Random(100));
+ Result := WaitUpTextMulti(['Cast', 'ast', 'Cas'], 500+Random(100));
end;
I would have originally but it was only 2 lines so I didn't bother.

Not sure why the WaitOption stuff is in there, I thought that had been committed long ago?

Coh3n

2011-01-11 22:47:59

Committed. :)