SRL Archive - SRL Suggestions

Shortened + new functions for SRL


Naum

2009-06-22 20:32:55

My Func List!

Hey all, I was roaming through the includes and picked up some code which would either not work or could be made shorter (in my view).

SRL/SRL/Skill/Magic.Scar

SetUpAutoCast(AutoSpell: string; Defensive: Boolean):

function SetUpAutoCast(AutoSpell: string; Defensive: Boolean): Boolean;
var
X, Y, Col, Row, Msk: Integer;
TB : TBox;
Spells, ColArray : TVariantArray;
begin
if not GameTab(1) then exit;
if Defensive then
Mouse(655, 253, 50, 25, True)
else Mouse(665, 320, 50, 25, True);
Spells := ['', 'wind strike', 'water strike', 'earth strike', 'fire strike',
'wind bolt', 'water bolt', 'earth bolt', 'fire bolt',
'wind blast', 'water blast', 'earth blast', 'fire blast',
'wind wave', 'water wave', 'earth wave', 'fire wave'];
ColArray := [835570, 16579836, 16563743, 3003805, 835570];
While (GetColor(587, 363) = 8621205) Do Wait(100 + Random(100));
Try Msk := StrToIntDef(AutoSpell, -1) Except end;
If Msk <> -1 Then
Row := Trunc(Msk Div 4) + 1
Else
For Msk := 0 to High(Spells) Do
If AutoSpell = Spells[Msk] Then
Row := Trunc(Msk Div 4) + 1;

If (Msk Mod 4) = 0 Then Dec(Row);
Col := Msk Mod 4;
If Col = 0 Then Col := 4;
TB.x1 := 571 + 40 * (Col - 1);
TB.y1 := 229 + 60 * (Row - 1);

For Msk := 0 to High(Spells) Do
If (LowerCase(AutoSpell) = Spells[Msk]) or (LowerCase(AutoSpell) = IntToStr(Msk)) Then
Result := FindColor(X, Y, ColArray[Msk Mod 4], TB.x1, TB.y1, TB.x1 + 40, TB.y1 + 60);
If Result <> True Then
Begin
srl_Warn('SetUpAutoCast', '"' + AutoSpell + '" is not a valid autocasting spell.', -2);
Mouse(687, 448, 9, 4, True); // Exits the autocasting Spells setup 'popup'.
End Else
Mouse(x, y, 2, 2, True);
End;

Replaces the current one, I edited it a lot from the first release and it now works! Horaay! However, the last one would not exit the menu as there was a wrong co-ord, this now does.



SRL/SRL/Core/MapWalk.Scar

GetMiniMapDotsIn(WhatDot: String; x1, y1, x2, y2: Integer): TPointArray;

function GetMiniMapDotsIn(WhatDot: String; x1, y1, x2, y2: Integer): TPointArray;
var
Color, I: Integer;
Arr : TVariantArray;
begin
WhatDot := LowerCase(WhatDot);
Arr := [0, 'npc', 'yellow', 60909, 'cape', 'blue', 12742980, 'item', 'red',
789758, 'player', 'white', 16711422, 'friend', 'green', 61440];
For I := 0 to (High(Arr) Div 3)- 1 Do
If (WhatDot = Arr[I*3+1]) Or (WhatDot = Arr[I*3+2]) Then
Color := Arr[I*3+3];
FindColorsSpiralTolerance(MMCX, MMCY, Result, Color, x1, y1, x2, y2, 0);
RAaSTPA(Result, 4);
if (WhatDot = 'player') or (WhatDot = 'white') then
begin
Swap(Result[0], Result[High(Result)]);
SetLength(Result, High(Result));
end;
end;

Hopefully that fixes the access violation error, and hopefully it is shorter.


SRL/SRL/Skill/Cooking.Scar

FindRange(Var X, Y : Integer) : Boolean;

Function FindRange(Var X, Y : Integer) : Boolean;
Begin
X := MSCX;
Y := MSCY;
Result := FindObjTPA(X, Y, 6579308, 10, 2, 10, 10, 20, ['ange']);
If Result <> False Then GetMousePos(x, y);
End;

The last one had an error, I didn't do much here.


SRL/SRL/Skill/Crafting.Scar

FindOven(Var XX, YY : Integer) : Boolean;

Function FindOven(Var XX, YY : Integer) : Boolean;
Begin
XX := MSCX;
YY := MSCY;
Result := FindObjTPA(XX, YY, 3754068, 13, 2, 10, 10, 30, ['ven']);
If Result <> False Then GetMousePos(xx, yy);
End;

Current one will keep on hovering and will not click. Again, I did not do much here.


SRL/SRL/Core/Login.Scar

Function LogOut : Boolean;

Function LogOut : Boolean;
Var I : Integer;
Begin
Result := (LoggedIn <> True);
If Result Then Exit;
If SRL_Procs[srl_OnLogOut] <> nil Then
SRL_Procs[srl_OnLogOut]();
GameTab(14);
Wait(200 + Random(100));
While LoggedIn And (I <= 10) Do
Begin
Inc(I);

If I Mod 2 = 0 Then
If ClickText('here', UpChars, MIX1, MIY1, MIX2, MIY2, True) Then
Begin
Wait(600 + Random(300));
If LoggedIn <> True Then Break;
End;
End;
Result := True;
End;

^ My shot :) ^


SRL/SRL/Core/GameTab.Scar

DoEmote(EmoteNumber : Integer)

Procedure DoEmote(EmoteNumber : Integer);
Var Ex, Ey, Row, Col : Integer;
Begin
If (EmoteNumber / 46 > 1) Or (EmoteNumber * 34729237 = 0) Then
Begin
srl_Warn('DoEmote', 'Invalid EmoteNumber: ' + IntToStr(EmoteNumber) + ', Valid Emotes: 1..46', warn_AllVersions);
Exit;
End;
GameTab(12);

If EmoteNumber <= 20 Then
If GetColor(724, 222) = 1975337 Then
Mouse(724, 233, 5, 5, True);

If InRange(EmoteNumber, 21, 40) Then
Begin
If GetColor(727, 360) = 2106924 Then
Mouse(727, 360, 5, 5, True);
EmoteNumber := EmoteNumber - 20;
End;

If InRange(EmoteNumber, 41, 46) Then
Begin
If GetColor(723, 443) = 1975337 Then
Mouse(723, 443, 3, 3, True);
EmoteNumber := EmoteNumber - 28;
End;

Row := (Trunc(EmoteNumber / 4) + 1);
If EmoteNumber Mod 4 = 0 Then Dec(Row);
Col := EmoteNumber Mod 4;
If Col = 0 Then Col := 4;

Ex := 562 + 37 * (Col - 1);
Ey := 231 + 44 * (Row - 1);

If CountColor(65536, Ex, Ey, Ex + 37, Ey + 44) >= 5 Then
Begin
Mouse(Ex, Ey, 23, 25, True);
Wait(1200 + Random(700));
End;
End;

DoEmote wasn't working and 9 new emotes have been added.


Hopefully people can give me tips to improve :).
Thanks

Nava2

2009-06-22 23:40:18

Moved on request..

Richard

2009-06-23 00:02:14

I'm failing to see the point in shortening code, someone point out why its better?

Nice collection of functions though, perhaps use srl_Explode for SetupAutoCast? Instead of having a huge array with all the spells.

Dynamite

2009-06-23 00:09:29

Shorter = more efficient (faster) code
I think ^^

Well done Naum ;)

T~M

Richard

2009-06-23 00:39:05

From: The Man
Shorter = more efficient (faster) code
I think ^^

Well done Naum ;)

T~M


Not necessarily, things like changing a mass of If's to a case will make it more efficient, but sometimes longer can be better, like with larger arrays, SCAR will have to go through the entire array every time it searches for a specific thing.

Naum

2009-06-23 19:12:22

Richard, I can easily change the array to make it faster, just add a begin after the if statement and make it:

If Result Then Exit

So it won't loop through all of the array,

Thanks for the comments though :)

Dan Cardin

2009-06-23 21:11:49

Hurrah for agreeances. Exactly my point of that thread (i'm just probably not the best person to do it for many of the really rs'y ones).

idk why i didnt think of putting the strings in an array, when you added that i was like…wut?! Naice jobs.

Naum

2009-06-25 00:07:27

From: Dan Cardin
Hurrah for agreeances. Exactly my point of that thread (i'm just probably not the best person to do it for many of the really rs'y ones).

idk why i didnt think of putting the strings in an array, when you added that i was like…wut?! Naice jobs.


Thanks :). Naice to see someone likes :)

Da 0wner

2009-06-25 19:42:45

procedure AreaInfo(area : string; var x1, y1, RowSize, ColSize, ColNum, RowNum : Integer);
var
Info : array [0..4] of TVariantArray;
h, i : integer;
begin
Info[0] := [560, 212, 36, 42, 4, 7, 'inventory'];
Info[1] := [63, 97, 55, 39, 21, 4, 'shop'];
Info[2] := [35, 91, 44, 44, 10, 5, 'bank'];
Info[3] := [310, 75, 32, 49, 4, 7, 'trade'];
Info[4] := [24, 75, 32, 49, 4, 7, 'your trade'];
h := high(Info);
area := lowercase(area);
for i := 0 to h do
begin
if area <> Info[i][6] then
Continue;
x1 := Info[i][0];
y1 := Info[i][1];
RowSize := Info[i][2];
ColSize := Info[i][3];
ColNum := Info[i][4];
RowNum := Info[i][5];
exit;
end;
end;
:p

ZephyrsFury

2009-06-25 20:27:40


for i := 0 to 6 do

Beat both of yous…

Da 0wner

2009-06-25 20:30:47

Of course, but I have it like that so you can add them easily.

ZephyrsFury

2009-06-25 20:37:31

From: Da 0wner
Of course, but I have it like that so you can add them easily.


What would you need to add though?

Da 0wner

2009-06-25 20:50:42

I don't even know what the function does tbh. I just did that because Naum did it :p. If it should be static then yes, we could use what you put.

Blender

2009-06-25 22:08:20

I don't see a difference in shortening code.

In C++, when I compile a simple program with a "for" loop and a "while" loop with variables, both turn out to be the exact same file.

SCAR runs with a compiler, so it wouldn't make that much of a difference.

Naum

2009-06-26 01:30:02

Would you like to eat your words and time it using Niels's timer?
Believe me, me and Da0wner had a heated contest..

Dan Cardin

2009-06-26 02:37:54

He very much wants to have some exact timing with the best 3 out of five..

Naum

2009-06-27 13:24:50

Sorry guys, I completely scored the last one. It was because the current one is easier to edit.
Furthermore, my one gave an out of range error which could be easily fixed by adding another line.

Edit : Added another fix, this one is for DoEmote.