SRL Archive - SRL Archives

Some Procedures/Function I made


Mr. Doctor

2009-12-09 17:14:20

Here are some of the procedures/functions I made and entered them into the Jr Comp #2.


{*******************************************************************************
Function Function DropFT(FromS: Integer; ToE: Integer): Integer;
By: Junkj
Description: Drops items from FromS to ToE. Like DropTo
*******************************************************************************}

Function DropFT(FromS: Integer; ToE: Integer): Integer;
Var FromF,ToT,I :Integer;
Begin
If(InvEmpty) Then Exit;
FromF := FromS
ToT := ToE
GameTab(tab_inv);
For I:= FromS To ToT do
DropItem(I);
end;

{*******************************************************************************
Function InvOption(Option: integer):integer;
By: Junkj
Description: Goes to your inventory and opens up a random screen
and closes it or opens up your specified window and does not close it
0- Random and close
1- Equipment Stats
2- Price Checker
3- Items on death
*******************************************************************************}

Function InvOption(Option: integer):integer;
Var Op :integer;
begin
Op := Option;
If(Op = 0) then
begin
Gametab(Tab_Equip)
Wait(100+random(50))
Case Random(3) of
0: Mouse(588, 434, 3, 3, True);
1: Mouse(641, 434, 3, 3, True);
2: Mouse(701, 429, 3, 3, True);
end;
Wait(1000+Random(100))
CloseWindow;
end else
Op := Option;
If(Op >= 1) and (Op <= 3) then
begin
Gametab(Tab_Equip)
Wait(100+random(50))
Case op of
1: Mouse(588, 434, 3, 3, True);
2: Mouse(641, 434, 3, 3, True);
3: Mouse(701, 429, 3, 3, True);
end;
end else
Op := Option;
If (Op > 3) or (Op < 0) then
begin
Writeln('Option '+ inttostr(Op) + ' does not exist')
end;
end;
{*******************************************************************************
Procedure SetRandomObj;
By: Junkj
Description: Sets a random objective.
*******************************************************************************}

Procedure SetRandomObj;
var RanObj,NoO,x,y :integer;
begin
NoO := BitmapFromString(23, 12, 'beNqNUQEOwiAQ40Fs2RJdnA4j0' +
'/3/SbO7jnpiNJLLpZT2KCH116G5nZrpEPO5BZ7RjzvDPhc+DYUZjR' +
'lb08TdNbxcxI6JmAmNpuXSMTMbjz5bresKF8vjb5XNwsUhmMwtbwQ' +
'IIfgX6V3EyAANerClS2nklhiW6nZm9vrqFRqiLl6aXCbQ+OcQnirh' +
'jyT4qSX13ugxwP3SiYESXQwm0Eve6z+9BFDC9UhdxQBDLD1IYfHU8' +
'NSXvpgu5qQxW0JiJuc/MnnVQ1mQLdM2GTk3bLcwhq8qxls9AVo+Ey' +
'o=');
RanObj := BitmapFromString(14, 14, 'beNp1kj0Lg2AMhN8fJ52ko6' +
'M4ttS1YJdSKE5O/cX6wMH1CPhyQ3K5fJi4DK/5ui7D7zuB571/TJf' +
'b2AEM3ASMo8lTwQIlpmD/NCH1YujoLmJ4FitkPhP1GFuuBnBoe49U' +
'zsRSJ5XALgVdM5WghLBL4lmRoszu2vlZYn6sD+Rhcg+p9HWssayQ2' +
'GL0A7T2l4mnnfcsV4sFyvI1xawH8tTePw==');
GameTab(tab_Objectives);
If(FindBitmapToleranceIn(NoO,x,y,mix1,miy1,mix2,miy2,20)) then
begin
Writeln('Setting Objective')
If(FindBitmapToleranceIn(RanObj,x,y,mix1,miy1,mix2,miy2,20)) then
begin
Mouse(x,y,3,3,true);
Wait(500+Random(250))
Case Random(5) of
0: Mouse(92, 94, 3, 3, true);
1: Mouse(261, 111, 3, 3, true);
2: Mouse(423, 113, 3, 3, true);
3: Mouse(89, 235, 3, 3, true);
4: Mouse(379, 404, 3, 3, true);
5: Mouse(427, 237, 3, 3, true);
End;
End Else
If(Not(FindBitmapToleranceIn(NoO,x,y,mix1,miy1,mix2,miy2,20))) Then
begin
Writeln('Objective Already Set')
Exit;
end;
end;
end;

{*******************************************************************************
Procedure Function RandomTabs(TimesToSwitch: integer; WaitBetween :integer):integer;
By: Junkj
Description: Switches between random tabs, 0 for randomrange from 1-5.
*******************************************************************************}

Function RandomTabs(TimesToSwitch: integer; WaitBetween :integer):integer;
var TTS,I,WB :integer;
begin
TTS := TimesToSwitch;
WB := WaitBetween;
If(TTS > 0) then
begin
For I:= 0 to TTS do
Case Random(15) of
0: GameTab(tab_Combat);
1: GameTab(tab_Stats);
2: GameTab(tab_Quest);
3: GameTab(tab_Diary);
4: GameTab(tab_Inv);
5: GameTab(tab_Equip);
6: GameTab(tab_Prayer);
7: GameTab(tab_Magic);
8: GameTab(tab_Friends);
9: GameTab(tab_Ignore);
10: GameTab(tab_Clan);
11: GameTab(tab_Options);
12: GameTab(tab_Emotes);
13: GameTab(tab_Music);
14: GameTab(tab_Notes);
15: GameTab(tab_Logout);
end;
Wait(WB)
end else
TTS := TimesToSwitch;
WB := WaitBetween;
If(TTS <= 0) then
begin
Case Random(4) of
0: TTS := 1;
1: TTS := 2;
2: TTS := 3;
3: TTS := 4;
4: TTS := 5;
end;
For I:= 0 to TTS do
Case Random(15) of
0: GameTab(tab_Combat);
1: GameTab(tab_Stats);
2: GameTab(tab_Quest);
3: GameTab(tab_Diary);
4: GameTab(tab_Inv);
5: GameTab(tab_Equip);
6: GameTab(tab_Prayer);
7: GameTab(tab_Magic);
8: GameTab(tab_Friends);
9: GameTab(tab_Ignore);
10: GameTab(tab_Clan);
11: GameTab(tab_Options);
12: GameTab(tab_Emotes);
13: GameTab(tab_Music);
14: GameTab(tab_Notes);
15: GameTab(tab_Logout);
end;
Wait(WB)
end;
end;

{*******************************************************************************
Function HumanNote(Note: String):String;
By: Junkj
Description: Types in a note that you have specified.
*******************************************************************************}

Function HumanNote(Note: String):String;
Var x,y,AddNote,T :integer;
Var NoteIn:string;
begin
AddNote := BitmapFromString(12, 11, 'beNoz0tBWltZTUwCSQCTEw' +
'QZHEBEjNeVgHxc0Nb0b0oEIrkZfQw6oDKgAiIBsIEJWAxEBImNtZT' +
'Qr4GrgCKgMoqZ1VRwEARVM3JQN52KqaVgegYzQ1MARRBbTLoibIYr' +
'haiAiEDdryopA2BB/wdVA/A5BKlJCQGVaCmIQNWhWAAPHQE0WaBRE' +
'GbJGCIIIWgIAlstNsQ==');
Gametab(Tab_Notes);
MarkTime(T)
Repeat
Wait(500+Random(2500))
Until(FindBitmapToleranceIn(AddNote,x,y,mix1,miy1,mix2,miy2,20)) or (TimeFromMark(T) = 25000)
If(FindBitmapToleranceIn(AddNote,x,y,mix1,miy1,mix2,miy2,20))Then
begin
Mouse(x,y,3,3,True)
FreeBitmap(AddNote)
Wait(500+Random(100));
NoteIn := Note;
Typesend(NoteIn);
end;
end;

{*******************************************************************************
Function ExamineAtSlot(InvSpot: Integer; RandomSpot: Integer): integer;
By: Junkj
Description: Examines at specified slot, or picks a random spot and
examines it.
1-Random (For RandomSpot: Integer;
0-YourSpot
*******************************************************************************}

Function ExamineAtSlot(InvSpot: Integer; RandomSpot: Integer): Integer;
var Spot,EXAMORIGNMOSSPED,x,y,I,RR :integer;
begin
If(invempty)then exit;
I := RandomSpot;
If(I = 0)then
begin
Spot := InvSpot;
Writeln('Examining at spot '+ inttostr(InvSpot))
EXAMORIGNMOSSPED := MouseSpeed;
MouseSpeed := 15;
MMouseItem(Spot);
getmousepos(x,y);
Mouse(x,y,3,3,false);
waitoption('xamine',500);
MouseSpeed := EXAMORIGNMOSSPED;
end else
If(invempty)then exit;
I := RandomSpot;
If(I = 0)then
begin
Spot := InvSpot;
If(not(existsitem(Spot)))then
begin
writeln('No item specified at slot '+ inttostr(spot));
exit;
end else
If(invempty)then exit;
I := RandomSpot;
If(I = 0)then
begin
spot := InvSpot;
if(spot > 28) or
(spot < 1) then
begin
Writeln('Inventory spot specified does not exist!');
exit;
end else
If(invempty)then exit;
I := RandomSpot;
if(I = 1) then
begin
repeat
RR:= RandomRange(1,28)
until(existsitem(RR))
EXAMORIGNMOSSPED := MouseSpeed;
MouseSpeed := 15;
MMouseItem(RR);
getmousepos(x,y);
Mouse(x,y,3,3,false);
waitoption('xamine',500);
MouseSpeed := EXAMORIGNMOSSPED;
end;
end;
end;
end;


Someone should edit DragItem because it moves the mouse too fast and may skip the item.

Method

2009-12-09 17:57:02

How come you make new local variables inside those functions and assign the parameter values to them when you could just use the parameter values? It also looks like you could use an array in RandomTabs instead of those two massive case statements.

Otherwise they look all right, for the most part.

YoHoJo

2009-12-09 18:01:22

MMouseItem(Spot);
getmousepos(x,y);
Mouse(x,y,3,3,false);

That moves mouse to Inventory spot, and then spazzes mouse (3,3) and then does the option. I don't like that :p, get rid of the last two lines of it.

ExamineAtSlot is kindof confusing to me. And this
   repeat
RR:= RandomRange(1,28)
until(existsitem(RR))

Looks dangerous!

Good job making some functions for Objectives though, those will be nice for antiban purposes. :D Ill talk about them more later, but good job making stuff, way to go!

Rick

2009-12-09 18:20:36

Good ideas. Heres some feedback:

You could shorten the drop to function like so. Remove the local vars, and use the parameters instead.

function DropFT(FromI, ToI: Integer): Integer;
var
i :Integer;
begin
GameTab(tab_inv);
if InvEmpty then Exit;
for i := FromI to ToI do
DropItem(i);
end;

In InvOption you keep assigning Op := Option. You only have to do this once! :p
You also use the same case statement twice, you could eliminate this to only once.
You should if InIntArray to check for input and use srl_warn if there is an error.
Which means it could be shortened to this:


function InvOption(Option: Integer): Integer;
begin
if not InIntArray([0, 1, 2, 3], Option) then
begin
srl_Warn('InvOption', 'Invalid Option', Warn_AllVersions);
Exit;
end;
Gametab(Tab_Equip)
Wait(100 + Random(50))
if Option = 0 then
Option := RandomRange(1, 3);
case Option of
1: Mouse(588, 434, 3, 3, True);
2: Mouse(641, 434, 3, 3, True);
3: Mouse(701, 429, 3, 3, True);
end;
Wait(1000 + Random(100))
CloseWindow;
end;

I do not recommend using bitmaps for things that could be done without, have a look at these Functions to see how you could go about assigning random objectives: http://www.villavu.com/forum/showthread.php?p=640557

You should group your parameters:

Function RandomTabs(TimesToSwitch: integer; WaitBetween :integer):integer;
becomes

function RandomTabs(TimesToSwitch, WaitBetween: Integer): Integer;

RandomTabs could become this:

function RandomTabs(TimesToSwitch, WaitBetween: Integer): Integer;
var
i : Integer;
begin
if TimesToSwitch = 0 then
TimesToSwitch := Random(4)
for i := 0 to TimesToSwitch do
begin
case Random(15) of
0: GameTab(tab_Combat);
1: GameTab(tab_Stats);
2: GameTab(tab_Quest);
3: GameTab(tab_Diary);
4: GameTab(tab_Inv);
5: GameTab(tab_Equip);
6: GameTab(tab_Prayer);
7: GameTab(tab_Magic);
8: GameTab(tab_Friends);
9: GameTab(tab_Ignore);
10: GameTab(tab_Clan);
11: GameTab(tab_Options);
12: GameTab(tab_Emotes);
13: GameTab(tab_Music);
14: GameTab(tab_Notes);
15: GameTab(tab_Logout);
end;
Wait(WaitBetween)
end;
end;
Eliminate your second case statement. I'm sure you could do something about that large case, it doesn't look too pleasant.

You should try to keep your standards consistent, it would make it a lot easier to read. I'm just going through the last function which seems like it could be shortened a lot.

I wouldn't adjust the mouse speed, I would leave that up to the user.

Also, you should check the item doesn't exist before you attempt to manipulate it :p You also checked twice for an invalid slot …

I would recommend RandomItem to be a boolean rather than an Integer. True/False makes more sense than 0/1.

Meaning ExamineAtSpot becomes:


function ExamineAtSlot(InvSpot: Integer; RandomSpot: Boolean): Integer;
var
x, y, RR: Integer;
begin
GameTab(tab_Inv);
if InvEmpty then Exit;
if RandomSpot then
while not(ExistsItem(RR)) do
RR:= RandomRange(1,28)
if not ExistsItem(InvSpot)))then
begin
srl_Warn('ExamineAtSlot', 'Item Does Not Exist At Slot: ' + IntToStr(RandomSpot), Warn_AllVersions);
Exit;
end;
Writeln('Examining at spot '+ IntToStr(InvSpot))
MMouseItem(InvSpot);
GetMousePos(x, y);
Mouse(x, y, 3, 3, False);
WaitOption('amine', 500);
end;

Much nicer no?

Good Job :)

I will keep editing and providing feedback.

@YoHoJo: I made these Objective Functions a while ago. http://www.villavu.com/forum/showthread.php?p=640557

Mr. Doctor

2009-12-10 07:07:19

Thanks R!ch!e. I really didn't know how to make that function line, but it's a start.