SRL Archive - SRL Archives

Assorted Procedures to be looked at.


Nava2

2008-09-05 15:26:05

Text.scar:

{*******************************************************************************
function InChatArr(Text: Array of String) : Boolean;
By: WT-Fakawi, Nava2 & EvilChicken!
Description: Grabs Last Chat Line and performs checks on occurence of text
*******************************************************************************}

function InChatArr(Text: TStringArray): Boolean;

var
I, H : integer;
s : string;

begin
H := High(Text);
if (not (GetLastChatText(s))) then LastChatter(s);
for I := 0 to H do
begin
if (Pos(Lowercase(Text[i]), (Lowercase(s)) > 0) then
begin
Result := true;
Exit;
end;
end;
end;

Its in my AutoResponder. :)

Bank.Scar:

function WithdrawMod(col, row, Amount: Integer): boolean;

Var
ResInt, I, Count : Integer;
P : TPoint;
BBox: TBox;

begin
FixBank;
//FixBankTab;
Result := false;
ResInt := InvCount;
BBox := BankIndexToMSBox(BankPointToBankIndex(Point(Col, Row)));
BBox := IntToBox(BBox.x1 + 8, BBox.y1 + 8, BBox.x2 - 8, BBox.y2 - 8);
GetMousePos(P.x, P.y);
if PointInBox(P, BBox) then
BBox := IntToBox(P.x - 8, P.y - 8, P.x + 8, P.y + 8);
case Amount of
0: begin
MouseBox(BBox.X1, BBox.Y1, BBox.X2, BBox.Y2, 2);
Wait(RandomRange(75, 125));
ChooseOption('Withdraw-All');
end;
1: begin
MouseBox(BBox.X1, BBox.Y1, BBox.X2, BBox.Y2, 1);
Wait(RandomRange(50, 150));
end;
else
begin
MouseBox(BBox.X1, BBox.Y1, BBox.X2, BBox.Y2, 2);
Wait(RandomRange(75, 125));
if not ChooseOption('Withdraw-' +IntToStr(Amount)) then
begin
GetMousePos(P.x, P.y);
MouseBox(P.x - 3, P.y - 3, 3, 3, 2);
Wait(RandomRange(75, 125));
if (ChooseOption('Withdraw-X')) then
begin
Wait(RandomRange(700, 1200));
TypeSend(IntToStr(Amount));
end;
end;
end;
end;
Count := InvCount;
while (Count <= ResInt) or (I < 200) do
begin
Wait(RandomRange(15, 40));
Inc(i);
Count := InvCount;
if Count > ResInt then Break;
end;
Result := ResInt < InvCount;
end;

procedure GetTabBounds(var B : TBox; T : Integer);

begin
if not InRange(T, 1, 9) then Exit;
B := IntToBox(27 + (T - 1) * 48, 51, 75 + (T - 1) * 48, 81);
end;

// Narcle / Nava2
Function ExistsBankTab(T: Integer): Boolean;
var
x, y: integer;
begin
Result := (FindColor(x, y, 65536, 27+(T-1)*48, 51, 75+(T-1)*48, 81) or (T = 1)) and BankScreen;
end;

// Very useful, as users can put all used items into last tab and script can draw from there
function GetLastTab : Integer;

begin
for Result := 9 downto 1 do
if ExistsBankTab(I) then
Break;
end;

// Narcle / Nava2
function BankTab(T: Integer): Boolean;

var
B : TBox;

begin
if not BankScreen then
Exit;
if T = CurrentBankTab then
Begin
Result := True;
Exit;
end;
if not ExistsBankTab(T) then
srl_Warn('BankTab', 'Bank Tab '+inttostr(T) +' does not Exist.', warn_AllVersions)
else
begin
GetTabBounds(B, T);
MouseBox(B.x1, B.y1, B.x2, B.y2, 1);
end;
Result := T = CurrentBankTab;
end;

// P is the MSTPoint.
function AddItemToTab(P : TPoint; T : Integer) : Boolean;

var
B : TBox;

begin
if CurrentBankTab = T then
begin
Result := True;
Exit;
end;
B := BankIndexToMSBox(BankPointToBankIndex(MSTPointToBankPoint(P)));
MouseBox(B.x1, B.y1, B.x2, B.y2, 3);
Wait(RandomRange(150, 200));
GetMousePos(P.x, P.y);
HoldMouse(P.x, P.y, True);
Wait(RandomRange(100, 150));
GetTabBounds(B, T);
MouseBox(B.x1, B.y1, B.x2, B.y2, 3);
GetMousePos(P.x, P.y);
ReleaseMouse(P.x, P.y, True);
Wait(RandomRange(300, 500));
Result := CurrentBankTab = T;
end;

WithdrawItem is now in Bank.Scar, if you would like to look at it, please see your include.
Yay me! :)

GameTab.scar

function GetEquiptItemBounds(Which : String) : TBox;

var
P : TPoint;
I : Byte;

begin
case Lowercase(Which) of
'1', 'helm', 'helmet' :
I := 1;
'2', 'cape' :
I := 2;
'3', 'amulet', 'neck', 'necklace' :
I := 3;
'4', 'arrows', 'bolts' :
I := 4;
'5', 'right hand', 'weapon' :
I := 5;
'6', 'plate', 'chest', 'platebody' :
I := 6;
'7', 'left hand', 'sheild' :
I := 7;
'8', 'legs', 'platelegs', 'skirt', 'plateskirt' :
I := 8;
'9', 'gloves', 'gauntlets' :
I := 9;
'10', 'ring' :
I := 10;
else
begin
SRL_Warn('GetEquiptItemBounds', 'Invalid entry.', Warn_AllVersions);
Result := IntToBox(0, 0, 0, 0);
Exit;
end;
end;
P := EquipmentCoords(I);
Result := IntToBox(P.x - 14, P.y - 14, P.x + 14, P.y + 14);
end;

procedure MouseEquiptItem(Which : String; Left : Integer);

var
B : TBox;

begin
B := GetEquiptItemBounds(Which);
if (B.x1 = 0) and (B.x2 = 0) then Exit;
GameTab(5);
Wait(RandomRange(80, 100));
case Left of
0 : MMouse(B.x1, B.y1, B.x2 - B.x1 + 1, B.y2 - B.y1 + 1);
1 : Mouse(B.x1, B.y1, B.x2 - B.x1 + 1, B.y2 - B.y1 + 1, True);
2 : Mouse(B.x1, B.y1, B.x2 - B.x1 + 1, B.y2 - B.y1 + 1, False);
else
SRL_Warn('MouseEquiptItem', 'Invalid Integer inputted in Left.', Warn_AllVersions);
end;
end;

Misc:

Unknown.scar

// ReArranges an array, from StartingIndex continueing throughout the array and then stopping adding all the point before that after. So: 4, 5, 6, 0, 1, 2, 3. Invert will do this, but invert it as well so that it is 4, 3, 2, 1, 0, 6, 5.
procedure ReArray(var Arr: TPointArray; StartingIndex: Integer; Invert: boolean);

var
I, I2, H, H2 : Integer;
ArrEx : TPointArray;

begin
SetLength(ArrEx, Length(Arr));
H := High(Arr);
case Invert of
true: begin
for I := StartingIndex downto 0 do
begin
ArrEx[I2] := Arr[i];
Inc(I2);
end;
H2 := StartingIndex + 1;
I2 := H2;
for i := H downto H2 do
begin
ArrEx[I2] := Arr[i];
Inc(I2);
end;
end;
false: begin
for I := StartingIndex to H do
ArrEx[i - StartingIndex] := Arr[i];
H2 := StartingIndex - 1;
I2 := H - StartingIndex + 1;
for i := 0 to H2 do
ArrEx[I2 + i] := Arr[i];
end;
end;
Arr := ArrEx;
end;

WorldSwitch.Scar

//Mixster does have a better version to go along with his new parser! :)
(*=====================================================================)
| function RandomWorld(Free: Boolean): Integer; |
| By: Nava2 |
| Instructions: Set 'Free' parameter to which ever type of world |
| that you would like. Simple! |
(=====================================================================*)

function RandomWorld(Free: Boolean): integer;

var
w, Path : string;
i, z : byte;

begin
Path := AppPath + 'Includes\SRL\SCSS\Worlds.INI';
z := StrToInt(ReadINI('Worlds', 'Count', Path));
i := RandomRange(1, z);
if Free then
w := 'Free'
else
w := 'Members';
repeat
Inc(i);
if i = z then
i := 1;
until (ReadINI('World' + IntToStr(i), 'Type', Path) = w);
Result := StrToInt(GetNumbers(ReadINI('World' + IntToStr(i), 'Prefix', Path)));
Writeln('Your Randomly chosen ' + w + ' world is ' + IntToStr(Result) + '.');
end;

Due to older reglulations, I removed my AutoResponder as SRL will not place it in, EVER.

Core / Math.scar

//Seeing as there is not one... :)
function RandomRangeE(From, Ending : Extended): Extended;

begin
Result := From + Rand * (Ending - From);
end;

Post suggestions please, everything here has been tested heavily.

EvilChicken!

2008-09-05 16:45:39

function InChatArr(Text: TStringArray): Boolean;
var
I, H : integer;
S: string;

begin
H := High(Text);
if not GetLastChatText(S) then LastChatter(S);
for I := 0 to H do
if (Pos(Lowercase(Text[i]), (Lowercase(s)) > 0) then
begin
Result := true;
Exit;
end;
end;

function RandWorld: Byte;
var
wINIpath: string;
RndCount: Byte;

begin
Result := 0;
WiniPath := AppPath + 'includes\SRL\SCSS\worlds.ini';
RndCount := StrToIntDef(ReadINI('Worlds', 'Count', wINIpath), 0);
if RndCount = 0 then exit;
repeat
Result := Random(Rndcount) + 1;
until ReadINI('World' + IntToStr(Result), 'Type', wINIpath) = 'Members';
end;


Looks very, very nice!
Gonna take a look at your bankstuff now :D

Nava2

2008-09-06 01:05:36

Haha, you are the reason why I use bytes now. They make sense :).

P.S. Why is only one space after the for loop?

Edit: Added my withdrawing function, which works flawlessly.

Nava2

2008-09-23 08:06:31

Added RandomRangeE.

Wizzup?

2008-09-23 09:01:00

Bytes make nearly no sense in SCAR… They are also a pain for compatibility, and figuring out problems. Using a byte once broke the old Sandwich solver.
Please just stick to Integers… (in SCAR)

EvilChicken!

2008-09-23 10:00:14

From: Wizzup?
Bytes make nearly no sense in SCAR… They are also a pain for compatibility, and figuring out problems. Using a byte once broke the old Sandwich solver.
Please just stick to Integers… (in SCAR)



Oh.
Well, I'll try to remember that then, ..

Thanks.

Nava2

2008-09-23 15:32:18

From: Wizzup?
Bytes make nearly no sense in SCAR… They are also a pain for compatibility, and figuring out problems. Using a byte once broke the old Sandwich solver.
Please just stick to Integers… (in SCAR)


I guess you are right. I mean, the memory saved is PROBABLY pretty limited.

P1nky

2008-09-24 23:18:19

nava thanks for the world switch

going to use for my upcomming script ;)

thanks m8! ill let you know if its reliable/good.

Nava2

2008-09-26 23:59:56

From: ~~Joker~~
nava thanks for the world switch

going to use for my upcomming script ;)

thanks m8! ill let you know if its reliable/good.


Please do ;)

Added some GameTab functions. They are for equipped items etc.

P1nky

2008-09-27 20:59:21

nava, is the randomworld:

a world hopper?
or its used for randomworld so SMART goes to.

Nava2

2008-09-28 01:17:44

Just outputs a random Free or P2P World.

Nava2

2008-10-21 06:44:02

Updated with some better versions, more organization, some more descriptions, and Moved my AutoResponder and my withdraw fix to this post. :)

Please use, or post suggestions :(

HyperSecret

2008-10-27 15:46:41

There is a RandomRange in SCAR already.

Nava2

2008-10-28 08:29:04

From: HyperSecret
There is a RandomRange in SCAR already.


Not for Extendeds ;)

Naum

2008-10-28 10:47:50

Why do you need it for extendedes just use division e.g

For 25.8967 to 98.4257 just do

RandomRange((258967/1000), (984257/1000));


Should be similar. Also why would you need anything in Extendeds for RS, just wondering??

Love your withdraw procedures btw, rep+ :)

Nava2

2008-10-28 16:41:45

From: HyperSecret
There is a RandomRange in SCAR already.


From: NaumanAkhlaQ
Why do you need it for extendedes just use division e.g

For 25.8967 to 98.4257 just do

RandomRange((258967/1000), (984257/1000));


Should be similar. Also why would you need anything in Extendeds for RS, just wondering??

Love your withdraw procedures btw, rep+ :)


Useful for the new TTile system, also for some different uses I haven't thought of.

Edit: Thanks for the complement. I worked really hard on those.

Naum

2008-10-29 13:02:45

Ok Ok. I dont use reflection that much so I frogot, thanks.

Nava2

2008-10-29 20:18:24

Its all good, understandable :)

davidwang95

2008-10-29 20:22:37

Thanks