SRL Archive - MSI Suggestions

MSI_PlayerSetup and MSI_AntiBan


Coh3n

2009-12-21 12:04:54

By Naum and Myself. I also made some other small changes. See the Change Log for details.


{==============================================================================\
| MSI Group Scripting Include |
| Mainloop.scar |
|==============================================================================|
| For all the script Artificial Inteligence |
| |
| * function MSI_BestTool: Integer; * by Coh3n |
| * function function MSI_SetupPlayer: Boolean; * by Coh3n |
| * procedure MSI_AntiBan(HowLong : Integer); * by Naum, edited by Coh3n |
\_____________________________________________________________________________}

{ const Hatchet/Pickaze requirements.
Constants representing the requirements to use each pickaxe/hatchet. }
const
REQ_BRONZE = 1;
REQ_IRON = 1;
REQ_STEEL = 6;
REQ_MITHRIL = 21;
REQ_ADAMANT = 31;
REQ_RUNE = 41;
REQ_MAX_LEVEL = 99;

{******************************************************************************}
{ function MSI_BestTool: Integer; }
{ By: Coh3n }
{ Rev: 55 }
{ Date: 26 Dec 09 }
{ Description: Determines the best tool for the job at hand. }
{******************************************************************************}
function MSI_BestTool: Integer;
var
skillsArr: TStringArray;
currSkill, currLevel: Integer;
begin
{ In order for this to work properly, the skillsArr indexes must correspond
to the skills constants in SRL's Players.scar }
skillsArr := [ 'attack', 'strength', 'defence', 'range', 'prayer', 'magic',
'runecrafting', 'hitpoints', 'agility', 'herblore', 'thieving',
'crafting', 'fletching', 'slayer', 'mining', 'smithing',
'fishing', 'cooking', 'firemaking', 'woodcutting', 'farming',
'construction', 'hunting', 'summoning' ];

{ Get the current level of the chosen skill, and then look for the required
tool, starting with the best one for that player's skill level. }
currSkill := Players[CurrentPlayer].Integers[P_SKILL] - 1;
currLevel := GetSkillLevel(skillsArr[currSkill]);

MSI_Debug('MSI_PlayerSetup', 'Current ' + Capitalize(skillsArr[currSkill])
+ ' level is ' + IntToStr(currLevel) + '.', debug_Functions);

case (Players[CurrentPlayer].Integers[P_SKILL]) of
SKILL_WOODCUTTING, SKILL_MINING:
case (currLevel) of
REQ_RUNE..REQ_MAX_LEVEL: Result := HATCHET_RUNE;
REQ_ADAMANT..(REQ_RUNE - 1): Result := HATCHET_ADAMANT;
REQ_MITHRIL..(REQ_ADAMANT - 1): Result := HATCHET_MITHRIL;
REQ_STEEL..(REQ_MITHRIL - 1): Result := HATCHET_STEEL;

else
Result := REQ_IRON;
end;
end;
end;

{******************************************************************************}
{ function MSI_SetupPlayer: Boolean; }
{ By: Coh3n }
{ Rev: 54 }
{ Date: 21 Dec 09 }
{ Description: Sets up the player for autoing. }
{******************************************************************************}
function MSI_SetupPlayer: Boolean;
var
bestTool, x, y, i, k: Integer;
bankCheck: Boolean;
begin
if (not LoggedIn) then
LoginPlayer;

SetAngle(True);
SetRun(True);

{ Starts by looking for the best tool for that player's skill level, and
moves down from there. }
bestTool := MSI_BestTool;
for i := bestTool downto 0 do
begin
Result := MSI_FindTool(i, x, y);
if (Result) then
Break;
end;

{ If the required tool isn't found, then will open the bank and attempt to
withdraw the proper tool. }
if (not Result) then
begin
case (Players[CurrentPlayer].Integers[P_LOC]) of
LOC_VEBANK:
bankCheck := MSI_OpenBank('veb', Players[CurrentPlayer].Pin);

else
MSI_Debug('MSI_SetupPlayer', 'Invalid Player.Integers[P_LOC].',
debug_Functions);
end;

if bankCheck then
for k := bestTool downto 0 do
begin
Result := MSI_Withdraw([k], [1]);
if (Result) then
Break
else

begin
CloseBank;
MSI_Debug('MSI_PlayerSetup', 'Couldn''t Withdraw Tool.',
debug_Functions);
end;
end
else
MSI_Debug('MSI_SetupPlayer', 'Unable to Open Bank.', debug_Functions);
end;
end;

{******************************************************************************}
{ Procedure MSI_AntiBan(HowLong : Integer); }
{ By: Naum, edited by Coh3n }
{ Rev: 54 }
{ Date: 21 Dec 09 }
{ Description: The AntiBan procedure to be used throughout the scripts. }
{******************************************************************************}
Procedure MSI_AntiBan(HowLong : Integer);
Var CurTab, I : Integer;
Begin
Case HowLong Of
0..2000 : Case Random(30) Of
0 : SleepAndMoveMouse(HowLong + Random(HowLong/10));
1 : Begin
CurTab := GetCurrentTab;
GameTab(RandomRange(TAB_Combat, TAB_LogOut));
Wait(HowLong + Random(HowLong/10));
GameTab(CurTab);
End;
2 : RandomRClick;
End;

2001..5000 : Case Random(40) Of
0 : HoverSkill('Random', False);
1 : PickUpMouse;
2 : SleepAndMoveMouse(HowLong + Random(HowLong/10));
3 : For I := 0 To Round(HowLong/800) Do
If I Mod 2 = 0 Then
ExamineInv;
End;

5001..10000 : If Random(20) = 1 Then
RandomMovement
Else
If Random(20) = 10 Then
MSI_AntiBan(Round(HowLong/2) + Random(1000));

10001..20000 : Case Random(30) Of
0 : MSI_AntiBan(Round(HowLong/2) + Random(1000));
1 : BoredHuman;
2 : RandomAngle(1);
End;

20001..999999 : If Random(10) = 5 Then
MSI_AntiBan(7000 + Random(200));
End;
End;


lordsaturn

2009-12-22 17:41:37

in
Procedure MSI_AntiBan(HowLong : Integer);
is HowLong the # of msec to antiban?

Coh3n

2009-12-22 18:42:17

From: lordsaturn
in
Procedure MSI_AntiBan(HowLong : Integer);
is HowLong the # of msec to antiban?

AFAIK, yes.

Sir R. M8gic1an

2009-12-24 12:51:44

Was writting my guild miner, a good case gets there faster than a loop.


{------------------------------------------------------------------------------]
[ Figures out the best axe to use ]
[------------------------------------------------------------------------------}
function BestAxe: integer;
begin
case Players[CurrentPlayer].Level[Skil_Mining] of

LVL_DRAGON .. 99 : Result := AXE_DRAGON ;
LVL_RUNE .. LVL_DRAGON : Result := AXE_RUNE ;
LVL_ADDY .. LVL_RUNE : Result := AXE_ADDY ;
LVL_MITH .. LVL_ADDY : Result := AXE_MITH ;
LVL_STEEL .. LVL_MITH : Result := AXE_STEEL ;
else Result := AXE_IRON;
end;
end;

~RM

Coh3n

2009-12-24 13:22:54

That would work to get the best axe, yes. But, what if they don't have the best axe? Maybe they're F2P or can't afford a Dragon Axe, or are just too lazy to buy a Mithril one. Know what I mean?

EDIT: That's also a reason I use a for..downto..do loop, to speed it up by looking for the best tool first.

Sir R. M8gic1an

2009-12-24 14:00:18


for i := BestAxe DownTo 0 do
//...

;)

e: basically this is just a way of doing the first loop faster, the rest would remain the same

~RM

Coh3n

2009-12-24 16:38:26

From: Rasta Magician

for i := BestAxe DownTo 0 do
//...

;)

e: basically this is just a way of doing the first loop faster, the rest would remain the same

~RM

Ohhh I see. I thought you were talking about replacing the downto loop. I wasn't thinking about the first one. I'll update it as soon as I get time. Probably in the next couple days. Christmas is busy busy. :p

Coh3n

2009-12-26 23:16:18

Updated, check first post. :)

Sir R. M8gic1an

2009-12-27 08:10:17

Looking good, and you don't actually need to do (Req - 1) as it'll fall onto the previous statement if it = req ;)

~RM

Coh3n

2009-12-27 10:24:06

You sure?

program New;

var
i: Integer;
begin
i := 5;
case i of
0..5: Writeln('i = hello.');
6..10: Writeln('i = goodbye.');
11..15: Writeln('i = wtf.');
end;
end.
I think you may be confused about my constants being 21, 31, 41. Those are the actual requirements for hatchets and pickaxes, unlike armour and weapons which require 20, 30, 40.

Sir R. M8gic1an

2009-12-28 15:32:09

From: Coh3n
You sure?

program New;

var
i: Integer;
begin
i := 5;
case i of
0..5: Writeln('i = hello.');
6..10: Writeln('i = goodbye.');
11..15: Writeln('i = wtf.');
end;
end.
I think you may be confused about my constants being 21, 31, 41. Those are the actual requirements for hatchets and pickaxes, unlike armour and weapons which require 20, 30, 40.


Case it from biggest to smallest ;)

program New;

var
i: Integer;
begin
for i := 0 to 31 do
case i of
21..31: Writeln(IntToStr(i) + ' = mith.');
6..21: Writeln(IntToStr(i) + ' = steel.');
0..6: Writeln(IntToStr(i) + ' = iron');
end;
end.


0 = iron
1 = iron
2 = iron
3 = iron
4 = iron
5 = iron
6 = steel.
7 = steel.
8 = steel.
9 = steel.
10 = steel.
11 = steel.
12 = steel.
13 = steel.
14 = steel.
15 = steel.
16 = steel.
17 = steel.
18 = steel.
19 = steel.
20 = steel.
21 = mith.
22 = mith.
23 = mith.
24 = mith.
25 = mith.
26 = mith.
27 = mith.
28 = mith.
29 = mith.
30 = mith.
31 = mith.


~RM

Coh3n

2009-12-28 16:53:38

Alright, let me see if I understand this right. Because the case is in reverse order, the loop will hit the 21..31 first, therefore being in the mith category. So my version would still work properly, it's just unnecessary to have the '- 1' part?

I hope that makes sense. :p

Sir R. M8gic1an

2009-12-28 18:20:58

From: Coh3n
Alright, let me see if I understand this right. Because the case is in reverse order, the loop will hit the 21..31 first, therefore being in the mith category. So my version would still work properly, it's just unnecessary to have the '- 1' part?

I hope that makes sense. :p


Exactly :)

~RM

Coh3n

2009-12-28 19:15:21

From: Rasta Magician
Exactly :)

~RM


Awesome, two months ago I would have never figured that out. Haha :p

Nava2

2009-12-28 19:57:11

From: Coh3n
Awesome, two months ago I would have never figured that out. Haha :p


It just looks for the first occurrence in which the condition would return true.

There is a way to use a case..of as a loop, but I don't remember how.. you can manipulate the condition or something.. Bullzeye knows.