SRL Archive - Senior Scripts and Snippets

SRGM Guild Miner


Sir R. M8gic1an

2011-02-10 10:10:33

Scar & Simba, RM Mining Guild Miner


Just making the tittle pretty, cus I finally decided to rescue this piece of code.

Thanks for all the help Ray :)

Instructions:
1. Fill in Declare Players
2. Hit Run
3. Post Error Reports (if any)
4. Post Feeback (I guess we should all watch out for our characters, so I defo wouldn't leave it with someone else's script without knowing the script works well)
5. Post Proggies


{ Last Updated: 11:32 GMT 10th Feb 2010 }
// SRGM Guild Miner

//Compatability should still be there, if you wish to find when it was last made compatiable..
//Well, check the logs.

//Update Log
- Updated by Ray to Simba Compatability around time of Official Simba Release

//Release Log
- RM Released to JM as proof of concept of SmartColors
- Ray Converted to Simba
- RM Released to SSRL

{$define SMART}
{.include srl/srl.scar}
{.include srl/srl/misc/SmartColors.scar}
{.include srl/srl/misc/Reports.scar}


{||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||}
{|||| REMEMBER TO ALWAYS USE THE LATEST DEVELOPER REVISION |||}
{||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||}

{
avoid rocks with animation
magic mining
detecting where players are far from rocks
avoid clicking black guild
WhileMining
Unwielded pick
}

{$define SmartDebug}
{$define SimbaDebugConsole}
const
//SRL Stats
SCRIPT_ID = '43';
USER_ID = '';
USER_PW = '';

//Custom Vars
STATS_LOADS = 1;

//Player Modifiable
//Debug
SCRIPT_DEBUG = true; //false to not debug. I WILL NOT BE ABLE TO PROPERLY HELP YOU WITHOUT DEBUG
//SMART
RM_SERVER = 124; //SMART Server
RM_SIGNED = True;

//Playing time per player (minutes)
FIXED_TIME = 20; //minimum time it will run
RAND_TIME = 10; // + random(RAND_TIME)

DETECT_ROCK_TIME = 750;

//UpText waits
UT_WAIT_FRENZY = 300;
UT_WAIT_FAST = 600;
UT_WAIT_HUMAN = 1000;

//InvCount waits
IC_WAIT_FRENZY = 10000;
IC_WAIT_FAST = 15000;
IC_WAIT_HUMAN = 7000;

//Random wait after rock
R_WAIT_FRENZY = 300;
R_WAIT_FAST = 500;
R_WAIT_HUMAN = 750;

//Script Management
MIN_DOOR_DIST = 55; //Distance to Guild Door
MAX_BANK_TRIES = 2; //Attempts to bank before going false
WALK_ATTEMPTS = 2; //Attempts to walk ToBank or ToGuild before going false


//Script Only
AUTHOR = 'Rasta Magician';
VERSION = '0.73';
SCRIPT_NAME = 'RM Guild Miner';


//Player Indexes

//bools
P_WIELDED = 0;

//ints
P_MITHP = 0; // x / 100 to check for mith
P_BANK_TRIES = 1;

W_GUILD = 2; //Attempts to walk to Guild
W_BANK = 3; //Attempts to walk to bank

//Location Indexes
LOC_BANK = 0;
LOC_OUT = 1;
LOC_GUILD = 2;

//Inside Guild Locs
GUILD_ENTRANCE = 3;
GUILD_LEFT = 4;
GUILD_CENTER = 5;
GUILD_TOP = 6;

//Symbols
SYMBOL_BANK = 0;
SYMBOL_DUNGEON = 1;
SYMBOL_MINING = 3;

//SmartColors indexes
ROCK_COAL = 0;
ROCK_MITH = 1;

LADDER_OUTSIDE = 2;
LADDER_INSIDE = 3;

BANK_BOOTH = 4;

//Black Counts
PICK_BLACK_COUNT = 95;

//PickAxe Indexes
AXE_BRONZE = 0;
AXE_IRON = 1;
AXE_STEEL = 2;
AXE_MITH = 3;
AXE_ADDY = 4;
AXE_RUNE = 5;
AXE_DRAGON = 6;

//PickAxe Level Requirements
LVL_BRONZE = 1;
LVL_IRON = 1;
LVL_STEEL = 6;
LVL_MITH = 21;
LVL_ADDY = 31;
LVL_RUNE = 41;
LVL_DRAGON = 61;

//Mining Mode
FRENZY = 0;
FAST = 1;
HUMAN = 2;

//Mining Stages
STAGE_TO_ROCK = 0;
STAGE_WAIT_ROCK = 1;

//Mining Messages & Indexes
SWING_PICK = 0;
MANAGE_MINE = 1;
NO_ORE = 2;

MSG_SWING_PICK = 'swing your pick' ;
MSG_MANAGE_MINE = 'manage to mine' ;
MSG_NO_ORE = 'no ore currently';

//Preset Colors
BLACK_OUTLINE = 65536;
SYMBOL_OUTLINE = 65536;
SYMBOL_FILL = 12632256;

MM_BLACK = 66819; {66309, 67328}
MM_DOOR = 15921921; {133101, 197111, 239, 394231, 328180}
MM_NPC = 128501; {60909, 195836, 1179390, 1179390, 56797, 195836}

_Coal = 0;
_Mith = 1;
_Bank = 2;
_LadderOutside = 3;
_LadderInside = 4;

COLOR_COAL = 2371118;
COLOR_MITH = 7559513; {7954013, 8085343, 7822428, 7822428, 7493719, 6770768, 7230805}
COLOR_BANK = 4153982;
COLOR_OUT_LADDER = 3958140;
COLOR_IN_LADDER = 3754838;

{$ifndef Smart}
{$undef SmartDebug}
{$endif}

{$ifndef Simba}
{$undef SimbaDebugConsole}
{$endif}

type
TMode = record
WaitUpText : integer;
WaitInvCount : integer;
WaitRandom : integer;
end;

TSymbol = record
Color : integer;
Tol : integer;
Hue : extended;
Sat : extended;
end;

TPlayerTime = record
StartTime : integer;
PreviousTime : integer;
CurrTime : integer;
end;

TRMColor = record
Color : integer;
Tol : integer;
CTS : integer;
h, s : extended;
end;

var
RMColors : Array[0..5] of TRMColor;

Procedure RMLoadColors;
var
i,
totalcolors: integer; //Not as constant for ease of maintainability
begin
totalcolors := 5;

for i:=0 to totalcolors do
case i of
_Coal :
with RMColors[_Coal] do
begin
Color := COLOR_COAL;
Tol := 10;
CTS := 2;
h := 0.35;
s := 0.43;
end;

_Mith :
with RMColors[_Mith] do
begin
Color := COLOR_MITH;
Tol := 10;
CTS := 2;
h := 0.13;
s := 0.14;
end;

_Bank :
with RMColors[_Bank] do
begin
Color := COLOR_BANK;
Tol := 5;
CTS := 2;
h := 0.03;
s := 1.08;
end;

_LadderOutside :
with RMColors[_LadderOutside] do
begin
Color := COLOR_OUT_LADDER;
Tol := 5;
CTS := 2;
h := 0.05;
s := 1.21;
end;

_LadderInside :
with RMColors[_LadderInside] do
begin
Color := COLOR_IN_LADDER;
Tol := 5;
CTS := 2;
h := 0.05;
s := 1.55;
end;

end;

end;

var
UseMode: TMode;
Loads: integer;
TimeGoing: integer;
BankDTM: integer;
PickDTM: integer;
PTime: TPlayerTime;




{ RM --------------------------------------------------------------------------]
[ End User Input for players ]
[------------------------------------------------------------------------------}
Procedure DeclarePlayers;
var
i: integer;
begin
NumberOfPlayers(1);
CurrentPlayer := 0;

for i := 0 to HowManyPlayers-1 do
Players[i].BoxRewards := ['mote', 'ostume', 'ystery', 'XP', 'Gem', 'ithril', 'oal', 'une', 'oins'];


with Players[0] do
begin
Name :='';
Pass :='';
Nick :='';
Active := True;

Integers[P_MITHP] := 100; // x / 100 to check for mith
Booleans[P_WIELDED] := true; //False => Inv 1st Spot!
end;

end;

//-------------------- SRL Stats Functions by Nielsie95 ----------------------//
{$IFNDEF RM}
const
Stats_Link = 'http://scriptmanager.freehostia.com/submit.php';

var
Stats_UserID, Stats_Password, Stats_ScriptID: string;
Stats_LastTime: Integer;

Stats_CustomVars: array [1..20] of Integer;

procedure Stats_CheckOutput(s: string);
var
i: Integer;
sa: TStringArray;
begin
sa := Explode(#10, s);
for i := 0 to High(sa) do
if (Trim(sa[i]) <> '') then
if StartsWith('ERROR(1)', sa[i]) then
begin
writeln('STATS: "' + sa[i] + '"');
Stats_UserID := '';
Stats_Password := '';
end
else if StartsWith('ERROR(2)', sa[i]) then
begin
writeln('STATS: "' + sa[i] + '"');
Stats_ScriptID := '';
end
else
writeln('STATS: "' + sa[i] + '"');

end;

function Stats_GetScriptInfo(out Version, News, Link: string; out OutDated: Boolean; out LastUpdate_HoursAgo: Integer): Boolean;
var
Client: Integer;
s: string;
sa: TStringArray;
begin
Result := False;
if (Stats_ScriptID = '') then
Exit;

Client := InitializeHTTPClient(False, False);
ClearPostData(Client);
AddPostVariable(Client, 'do', 'getinfo');
AddPostVariable (Client, 'sID', Stats_ScriptID);

s := PostHTTPPageEx(Client, Stats_Link);
sa := Explode(#10'GLUE'#10, s);
if (Length(sa) = 5) then
begin
Result := True;
Version := sa[0];
News := sa[1];
Link := sa[2];
OutDated := sa[3] = '1';
LastUpdate_HoursAgo := StrToIntDef(sa[4], -1);
end
else
Stats_CheckOutput(s);

FreeHTTPClient(Client );
end;

var
Stats_GlobalVars: array[1..24] of Integer;

procedure Stats_SendReport;
var
i, Client, Time: Integer;
s: string;
begin
if (Stats_UserID = '') and (Stats_Password = '') and (Stats_ScriptID = '') then
Exit;

Client := InitializeHTTPClient(False, False);
ClearPostData(Client);
AddPostVariable(Client, 'do', 'submit');

Time := (GetTimeRunning - Stats_LastTime) div 1000 div 60;
if (Time < 5) then
Time := 0
else
Stats_LastTime := GetTimeRunning;
AddPostVariable(Client, 'sTime', IntToStr(Time));

if (Stats_UserID <> '') and (Stats_Password <> '') then
begin
AddPostVariable(Client, 'uID', Stats_UserID);
AddPostVariable(Client, 'uPass', Stats_Password);
end
else
begin
AddPostVariable(Client, 'uID', '-1');
AddPostVariable(Client, 'uPass', '');
end;

if (Stats_ScriptID <> '') then
begin
AddPostVariable (Client, 'sID', Stats_ScriptID);

for i := Low(Stats_CustomVars) to High(Stats_CustomVars) do
begin
AddPostVariable(Client, 'rndCustom' + IntToStr(i), IntToStr(Stats_CustomVars[i]));
Stats_CustomVars[i] := 0;
end;
end
else
begin
AddPostVariable (Client, 'sID', '-1');
end;

for i := Low(Stats_GlobalVars) to High(Stats_GlobalVars) do
begin
case i of
1: s := IntToStr(SRL_Logs - Stats_GlobalVars[i]);
2: s := IntToStr(Banks - Stats_GlobalVars[i]);
3: s := IntToStr(RandSolved[rand_Death] - Stats_GlobalVars[i]);
else if ((i - 3) < Length(RandSolved) - 1 {for Death}) then
s := IntToStr(RandSolved[i - 3] - Stats_GlobalVars[i]);
end;
AddPostVariable(Client, 'rndGlobal' + IntToStr(i), s);
Stats_GlobalVars[i] := Stats_GlobalVars[i] + StrToInt(s);
end;

s := PostHTTPPageEx(Client, Stats_Link);
Stats_CheckOutput(s);
FreeHTTPClient(Client);

if (SRL_Procs[srl_OnSendStats] <> nil) then
SRL_Procs[srl_OnSendStats]();
end;

procedure Stats_SendAccountInfo;
var
i, Client: Integer;
Accounts: TStringArray;
begin
if (Stats_UserID = '') and (Stats_Password = '') then
Exit;

Client := InitializeHTTPClient(False, False);
ClearPostData(Client);
AddPostVariable(Client, 'do', 'setaccounts');
AddPostVariable(Client, 'uID', Stats_UserID);
AddPostVariable(Client, 'uPass', Stats_Password);
if (Stats_ScriptID <> '') then
AddPostVariable (Client, 'sID', Stats_ScriptID)
else
AddPostVariable (Client, 'sID', '-1');

SetLength(Accounts, HowManyPlayers);
for i := 0 to HowManyPlayers - 1 do
Accounts[i] := Implode('.|?stat?|.', [Players[i].Name, Players[i].Loc, IntToStr(Integer(Players[i].Active))]);

AddPostVariable(Client, 'accInfo', Implode(#10'ACC'#10, Accounts));
Stats_CheckOutput(PostHTTPPageEx(Client, Stats_Link));
FreeHTTPClient(Client);
end;

procedure Stats_ManageAccounts;
var
i, ii, Client: Integer;
s: string;
Accounts, Stats: TStringArray;
begin
if (Stats_UserID = '') and (Stats_Password = '') then
Exit;

Client := InitializeHTTPClient(False, False);
ClearPostData(Client);
AddPostVariable(Client, 'do', 'getaccounts');
AddPostVariable(Client, 'uID', Stats_UserID);
AddPostVariable(Client, 'uPass', Stats_Password);
AddPostVariable (Client, 'sID', '-1');

s := PostHTTPPageEx(Client, Stats_Link);
Accounts := Explode(#10'ACC'#10, s);
for i := 0 to High(Accounts) do
begin
Stats := Explode('.|?stat?|.', Accounts[i]);
if (Length(Stats) = 3) then
begin
for ii := 0 to HowManyPlayers - 1 do
if (LowerCase(Players[ii].Name) = LowerCase(Stats[0])) then
begin
Players[ii].Loc := Stats[1];
Players[ii].Active := Stats[2] = '1';
Break;
end;
end
else
begin
Stats_CheckOutput(s);
Break;
end;
end;

FreeHTTPClient(Client);
stats_SendAccountInfo;
end;
{$ENDIF}
//-------------------- SRL Stats Functions by Nielsie95 ----------------------//

{ RM --------------------------------------------------------------------------]
[ Gets CTS Info ]
[------------------------------------------------------------------------------}
procedure GetCTS(var speed: integer; var H, S: extended);
begin
speed := GetColorToleranceSpeed;
GetColorspeed2Modifiers(H, S);
end;

{ RM --------------------------------------------------------------------------]
[ Sets CTS info ]
[------------------------------------------------------------------------------}
procedure SetCTS(speed: integer; H, S: extended);
begin
ColorToleranceSpeed(speed);
SetColorspeed2Modifiers(H, S);
end;

{ RM --------------------------------------------------------------------------]
[ Progress Report ]
[------------------------------------------------------------------------------}
Procedure RMDebug(What: String);
begin
if SCRIPT_DEBUG then
begin
{$ifdef SimbaDebugConsole}
DebugLn('[' + MsToTime(GetTimeRunning,Time_Bare)+']: '+Players[CurrentPlayer].Name+': '+What);
{$else}
Writeln('[' + MsToTime(GetTimeRunning,Time_Bare)+']: '+Players[CurrentPlayer].Name+': '+What);
{$endif}
{$ifndef Simba}
DisGuise(What);
{$endif}
end;
end;

{ RM --------------------------------------------------------------------------]
[ Does not move mouse onto 'BlackGuildMap'; Else moves normally. ]
[------------------------------------------------------------------------------}
function RMMMouse(x, y, rx, ry: integer; RMClick: (LeftC, RightC, Move)): boolean;
var
xb, yb, CTS: integer;
h, s: extended;
begin
GetCTS(CTS, h, s);
SetCTS(1, 0.20, 0.20);
for xb := 0 to 2 do
begin
for yb:= 0 to 2 do
if not SimilarColors(GetColor(x+ xb, y + yb), MM_BLACK, 10) then
break
else
writeln(GetColor(x+ xb, y + yb));

if (yb < 3) then break;
end;

if (xb < 3) then
case RMClick of
LeftC : Mouse(x, y, rx, ry, true);
RightC : Mouse(x, y, rx, ry, false);
Move : MMouse(x, y, rx, ry);
end
else exit;

Result := true;

SetCTS(CTS, h, s);
end;

{ RM --------------------------------------------------------------------------]
[ Makes a box of BoxSize with center SPoint, within the MS ]
[------------------------------------------------------------------------------}
function MakeMSBox(SPoint: TPoint; BoxSize: integer): TBox;
begin
Result.x1 := Max(SPoint.x - BoxSize, MSX1);
Result.x2 := Min(SPoint.x + BoxSize, MSX2);
Result.y1 := Max(SPoint.y - BoxSize, MSY1);
Result.y2 := Min(SPoint.y + BoxSize, MSY2);
end;

{ RM --------------------------------------------------------------------------]
[ FindColorsTolerance in a TBox ]
[------------------------------------------------------------------------------}
function FindColorsToleranceBox(var TPA: TPointArray; Color, Tolerance: Integer; Box: TBox): boolean;
begin
Result := FindColorsTolerance(
TPA,
Color,
Box.x1,
Box.y1,
Box.x2,
Box.y2,
Tolerance
);
end;

{ RM --------------------------------------------------------------------------]
[ Finds an ore. I'm really lazy. ]
[------------------------------------------------------------------------------}
function FindOreBox(var TPA: TPointArray; Rock: integer; Box: TBox): boolean;
var
H, S: extended;
CTS, color, tol: integer;
begin
GetCTS(CTS, H, S);

if Rock = ROCK_COAL then
begin
color := RMColors[_Coal].Color;
tol := RMColors[_Coal].Tol;

SetCTS(
RMColors[_Coal].CTS,
RMColors[_Coal].h,
RMColors[_Coal].s
);

end else begin
color := RMColors[_Mith].Color;
tol := RMColors[_Mith].Tol;

SetCTS(
RMColors[_Mith].CTS,
RMColors[_Mith].h,
RMColors[_Mith].s
);
end;

Result := FindColorsToleranceBox(TPA, color, tol, Box);

SetCTS(CTS, H, S);
end;

{ RM --------------------------------------------------------------------------]
[ Clears Canvas ]
[------------------------------------------------------------------------------}
Procedure ClearSmartPaint(canvas: TCanvas);
{$ifdef SmartDebug}
var
CleanBMP: integer;
{$endif}
begin
{$ifdef SmartDebug}
CleanBMP := BitmapFromString(MIX2, MIY2, '');
{$ifdef Simba}
DrawBitmap(CleanBMP,Canvas,0,0);
{$else}
SafeDrawBitmap(CleanBMP, canvas, 0, 0);
{$endif}

try
FreeBitmap(CleanBMP);
except end;
{$endif}
end;

{ caused edited by RM ---------------------------------------------------------]
[ Paint a TPA onto the Smart Debug Canvas ]
[------------------------------------------------------------------------------}
procedure DrawDots(pixels : TpointArray);
{$ifdef SmartDebug}
var
i : integer;
drawing : TBitmap;
begin
drawing := TBitmap.Create;
drawing.canvas.handle := SmartGetDebugDC;
drawing.canvas.Pen.Color := clRed;

ClearSmartPaint(drawing.canvas);

for i:= 0 to high(pixels) do
begin
drawing.canvas.moveto(pixels[i].x-1,pixels[i].y);
drawing.canvas.LineTo(pixels[i].x,pixels[i].y);
end;

try
FreeBitmap(drawing);
except end;
{$else}
begin
{$endif}
end;

{ RM based on DrawBoxes by caused ---------------------------------------------]
[ Draws a box, Rock size. ]
[------------------------------------------------------------------------------}
procedure DrawBox(Box: TPointArray; color: TColor);
{$ifdef SmartDebug}
var
drawing : TBitmap;
TP : TPoint;
B: TBox;
begin
drawing := TBitmap.Create;
drawing.canvas.handle := SmartGetDebugDC;
drawing.canvas.Pen.Color := color;

ClearSmartPaint(drawing.canvas);

TP := MiddleTPA(Box);
B := MakeMSBox(TP, 20);

drawing.canvas.moveto(B.x1,B.y1);
drawing.canvas.LineTo(B.x2,B.y1);
drawing.canvas.LineTo(B.x2,B.y2);

drawing.canvas.LineTo(B.x1,B.y2);
drawing.canvas.LineTo(B.x1,B.y1);

try
FreeBitmap(drawing);
except end;
{$else}
begin
{$endif}
end;

{ RM --------------------------------------------------------------------------]
[ Progress Report ]
[------------------------------------------------------------------------------}
Procedure ProgressReport;
begin
{$ifndef Simba}
ClearReport;
{$endif}

PTime.CurrTime := GetSystemTime - PTime.StartTime;
Players[CurrentPlayer].Worked := PTime.PreviousTime + PTime.CurrTime;

SRLProgressReport(
ResultReportBox, SCRIPT_NAME, AUTHOR, VERSION,
['Time running', 'Total Loads'],
[TimeRunning, Loads]
);

SRLPlayerReport(
ResultReportBox, SKILL_MINING, false,
[true, true, true, true, false, false],
[],
[], [], [], []
);

Players[CurrentPlayer].Worked := PTime.PreviousTime;
Stats_SendReport;
Stats_ManageAccounts;
end;

{ RM --------------------------------------------------------------------------]
[ Checks for Bank or Pin Screen ]
[------------------------------------------------------------------------------}
function RMRandoms(RDebug: boolean): boolean;
var s: string;
begin
if RDebug then
RMDebug('Checking for randoms');

Result := FindNormalRandoms;

if IsFKeyDown(12) then
begin
s := Readln('What would you like to type ingame?');

if s = '' then
exit;

TypeSend(s);
end;
end;

{ RM --------------------------------------------------------------------------]
[ Checks for Bank or Pin Screen ]
[------------------------------------------------------------------------------}
function BorPScreen: boolean;
begin
Result := ((BankScreen)or(PinScreen));
RMDebug('BorPScreen: ' + BoolToStr(Result));
end;

{ RM --------------------------------------------------------------------------]
[ Figures out the best axe to use ]
[------------------------------------------------------------------------------}
function BestAxe: integer;
begin

case Players[CurrentPlayer].Level[Skill_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 --------------------------------------------------------------------------]
[ Sets a Player to False ]
[------------------------------------------------------------------------------}
Procedure DeActivatePlayer(Reason: String);
begin
LogOut;
Players[CurrentPlayer].Active := false;
Players[CurrentPlayer].Loc := Reason;
RMDebug('Logged Out - '+Reason);
end;

{ RM --------------------------------------------------------------------------]
[ Checks where the PickAxe is. ]
[------------------------------------------------------------------------------}
Function CheckPickAxe: boolean;
var
CT, i, x, y : Integer;
TC: TIntegerArray;
begin
Result := true;
exit;

RMRandoms(true);
if not LoggedIn then exit;

SetLength(TC, 2);
CT := GetCurrentTab;
if CT = TAB_INV then
TC := [TAB_INV, TAB_EQUIP]
else
TC := [TAB_EQUIP, TAB_INV];


for i:= 0 to 1 do
begin
GameTab(TC[i]);
if FindDTM(PickDTM, x, y, MIX1, MIY1, MIX2, MIY2) then
begin
Result := true;
Players[CurrentPlayer].Booleans[P_WIELDED] := (TC[i] = TAB_EQUIP);
if Players[CurrentPlayer].Booleans[P_WIELDED] then
RMDebug('Pick is Equipped')
else
RMDebug('Pick is in Inv');
exit;
end else
RMDebug('No Pick, Tab: '+IntToStr(TC[i]));
end;

if i > 1 then
DeActivatePlayer('No Pick');
end;

{ RM --------------------------------------------------------------------------]
[ Sets the different mining modes ]
[------------------------------------------------------------------------------}
procedure SetMode(myMode: integer);
begin
case myMode of
FRENZY:
begin
with UseMode do
begin
WaitUpText := UT_WAIT_FRENZY;
WaitInvCount := IC_WAIT_FRENZY;
WaitRandom := R_WAIT_FRENZY;
end;

end;
FAST:
with UseMode do
begin
WaitUpText := UT_WAIT_FAST;
WaitInvCount := IC_WAIT_FAST;
WaitRandom := R_WAIT_FAST;
end;

end;
end;



{ RM --------------------------------------------------------------------------]
[ Results true if sentence matches one of the texts. Uses Pos. Returns the ]
[ Array index. ]
[------------------------------------------------------------------------------}
Function InStrArrExPosReverse(S: String; StrArr: TStringArray; Var Where: Integer): Boolean;
Var
I, H: Integer;
Begin
H := High(StrArr);
For I := 0 To H Do
If (Pos(LowerCase(StrArr[i]), LowerCase(S)) > 0) Then
Begin
Where := i;
Result := True;
Break;
End;
End;

{ RM --------------------------------------------------------------------------]
[ Finds symbol Which through TPA Analysis ]
[------------------------------------------------------------------------------}
Function FindSymbolWithTPA(Which: integer; var Where: TPoint): boolean;
var
TPA : TPointArray;
ATPA: T2DPointArray;
TBArr : TBoxArray;
i, h, t, waste, CTS: integer;
Hue, Sat: extended;
TIA: TIntegerArray;
Symb: TSymbol;
begin
RMRandoms(true);
if not FindColors(TPA, SYMBOL_OUTLINE, MMX1, MMY1, MMX2, MMY2) then
begin
srl_warn('FindSymbolThroughTPA', 'Could not find symbol', warn_AllVersions);
exit;
end;

ATPA := SplitTPA(TPA, 2);

t := 0;
h := High(ATPA);
SetLength(TIA, h + 1);
SetLength(TBArr, h + 1);

for i:= 0 to h do
begin
TBArr[i] := GetTPABounds(ATPA[i]);
if FindColor(waste, waste, SYMBOL_FILL, TBArr[i].x1, TBArr[i].y1, TBArr[i].x2, TBArr[i].y2) then
begin
TIA[t] := i;
Inc(t);
end;
end;

if (t = 0) then
begin
RMDebug('Impossible walk');
Result := false;
exit;
end;

SetLength(TIA, t);

case which of

SYMBOL_BANK :
with Symb do
begin
Color := 6542813; {2216175, 4694448, 9697013}
Tol := 15;
Hue := 0.10;
Sat := 1.49;
end;

SYMBOL_DUNGEON:
with Symb do
begin
Color := 6645236; {10526972, 2763504, 5263604}
Tol := 13;
Hue := 0.0;
Sat := 0.29;
end;


SYMBOL_MINING:
with Symb do
begin
Color := 8092796;
Tol := 14;
Hue := 2.39;
Sat := 0.03;

end;
end;

GetCTS(CTS, Hue, Sat);
SetCTS(2, Symb.Hue, Symb.sat);

for i:= 0 to t-1 do
begin
h := TIA[i];
if FindColorsToleranceBox(TPA, Symb.Color, Symb.Tol, TBArr[h]) then
begin
Where := MiddleTPA(TPA);
Result := true;
break;
end;
end;

SetCTS(CTS, Hue, Sat);

if i = t then
RMDebug('could not find symbol fill');

end;

{ RM --------------------------------------------------------------------------]
[ Clicks the Rocks/Ladder Zone ]
[------------------------------------------------------------------------------}
function FindMMLadder(var TP: TPoint): boolean;
var
TB: TBox;
ATPA: T2DPointArray;
TPA: TPointArray;
CTS, i: integer;
H, S: extended;
begin
result := false;

GetCTS(CTS, H, S);
SetCTS(2, 0.45, 4.10);

{143195, 403800, 404566}
if not FindColorsTolerance(TPA, 996441, MMX1, MMY1, MMX2, MMY2, 6) then
begin
SetCTS(CTS, H, S);
exit;
end else begin
SetCTS(CTS, H, S);

//avoiding confusion with mining symbol
ATPA := TPAtoATPAEx(TPA, 10, 20);

for i := 0 to High(ATPA) do
begin
TB := GetTPABounds(ATPA[i]);
RMDebug('x axis: ' + IntToStr(TB.x2 - TB.x1));
RMDebug('y axis: ' + IntToStr(TB.y2 - TB.y1));
if ((TB.x2 - TB.x1) > 5) then
if ((TB.y2 - TB.y1) > 11) then
Result := true
else
Result := false
else
Result := false;

if Result then
begin
TPA := ATPA[i];
TP := MiddleTPA(TPA);

if not InCircle(TP.x, TP.y, MMCX, MMCY, ((MMX2 - MMX1) / 2) - 5) then
begin
Result := false;
continue;
end;

break;
end;

end;

end;
end;

{ RM --------------------------------------------------------------------------]
[ Finds NPCs on MM ]
[------------------------------------------------------------------------------}
function FindNPCMM(var TP: TPoint): boolean;
var
TPA: TPointArray;
ATPA: T2DPointArray;
CTS: integer;
H, S: extended;
begin
GetCTS(CTS, H, S);
SetCTS(2, 0.00, 0.17);

Result := FindColorsTolerance(TPA, MM_NPC, MMX1, MMY1, MMX2, MMCY, 5);

if Result then
begin
ATPA := TPAToATPAEx(TPA, 4, 4); // 4*4 = NPC size
SortATPAFromFirstPoint(ATPA, Point(MMCX, MMCY));

TP := MiddleTPA(ATPA[0]);
end;

SetCTS(CTS, H, S);
end;

{ RM --------------------------------------------------------------------------]
[ Finds the door to noobie guild on Minimap ]
[------------------------------------------------------------------------------}
Function FindMMDoor(var TP: TPoint): boolean;
var
TPA: TPointArray;
ATPA: T2DPointArray;
i, CTS: integer;
H, S: extended;
begin
{Can also look for NPCs, they only exist on the other side!}
GetCTS(CTS, H, S);
SetCTS(2, 24.97, 0.80);

Result := FindColorsTolerance(TPA, MM_DOOR, MMX1, MMY1, MMX2, MMCY, 2);

if Result then
begin
Result := False;
ATPA := SplitTPA(TPA, 2);
SortATPAFromFirstPoint(ATPA, Point(MMCX, MMCY));
for i:= High(ATPA) DownTo 0 do
if (Length(ATPA[i]) <= 5) then
begin
Result := true;
TP := MiddleTPA(ATPA[i]);
end;

end;

if not Result then
Result := FindNPCMM(TP);

SetCTS(CTS, H, S);

end;

{ RM --------------------------------------------------------------------------]
[ Finds text <> MSG_SWING_PICK and returns its line ]
[------------------------------------------------------------------------------}
Function FindNeutralText(var text: string): integer;
var
i: integer;
begin
for i := 8 DownTo 1 do
begin
text := lowercase(GetChatBoxText(i, clMessage));
if not (Pos(MSG_SWING_PICK, text) > 0 ) then
break;
end;

Result := i;
end;

{ RM --------------------------------------------------------------------------]
[ Returns true if successfully started mining a rock. False otherwise ]
[------------------------------------------------------------------------------}
function CheckChat(PreviousMessage: string; CheckPlace, Stage, Time: integer): boolean;
var
ChatMessage: string;
NewMsg, MyTime: integer;
begin
RMDebug('in check chat');
MyTime := GetSystemTime + Time;



ChatMessage := lowercase(GetChatBoxText(CheckPlace, clMessage));
while MyTime > GetSystemTime do
begin

if IsFKeyDown(11) then
begin
Result := false;
writeln('Chat wait aborted by user');
exit;
end;

if PreviousMessage = ChatMessage then
begin
wait(50);
ChatMessage := lowercase(GetChatBoxText(CheckPlace, clMessage));
end else
break;
wait(100);
end;

ChatMessage := lowercase(GetChatBoxText(8, clMessage)); // 8 = last line of chat box

if ChatMessage = PreviousMessage then
begin
RMDebug('No Chat change');
exit;
end;

if not InStrArrExPosReverse(ChatMessage, [MSG_SWING_PICK, MSG_MANAGE_MINE, MSG_NO_ORE], NewMsg) then
begin
RMDebug('New: unidentified chat; ' + ChatMessage);
// relocating
if Pos('reach that', ChatMessage) > 0 then
Mouse(MMCX, MMCY + 60, 5, 5, true);
wait(4000+random(2000));
exit;
end;

case Stage of
STAGE_TO_ROCK:
begin
case NewMsg of

SWING_PICK:
begin
Result := true;
exit;
end;

else
begin
Result := false;
exit;
end;

end;
end;

STAGE_WAIT_ROCK:
Result := not (ChatMessage = MSG_SWING_PICK);

end;

end;

{ RM --------------------------------------------------------------------------]
[ Returns true if in guild = Wanted ]
[------------------------------------------------------------------------------}
function InGuild(time: integer; Wanted: boolean): boolean;
var
t, CTS: integer;
TPA: TPointArray;
H, S: extended;
begin
RMDebug('entering func InGuild');
RMRandoms(true);
if not LoggedIn then exit;

GetCTS(CTS, H, S);
SetCTS(1, 0.20, 0.20);

t := GetSystemTime + time;
while t >= GetSystemTime do
begin
FindColorsTolerance(TPA, MM_BLACK, MMX1, MMY1, MMX2, MMY2, 10);
Result := (Length(TPA) > 2000);

RMDebug('In Guild? '+ BoolToStr(Result));
RMDebug('Black Points: ' + IntToStr(Length(TPA)));

if Result = Wanted then
break
else
wait(250);
end;

ColorToleranceSpeed(CTS);
SetColorspeed2Modifiers(H, S);
end;

{ RM --------------------------------------------------------------------------]
[ Returns Which Part of the Guild we are in ]
[------------------------------------------------------------------------------}
function AtGuildLoc : integer;
var
TP: TPoint;
begin
{
//Inside Guild Locs
GUILD_ENTRANCE = 3;
GUILD_LEFT = 4;
GUILD_CENTER = 5;
GUILD_TOP = 6;
}
if FindMMLadder(TP) then
if Distance(TP.x, TP.y, MMCX, MMCY) < 7 then
Result := GUILD_TOP
else

end;


{ RM --------------------------------------------------------------------------]
[ Walks to Where ]
[------------------------------------------------------------------------------}
function WalkSymbol(Where: integer): boolean;
var
TP, TP2: TPoint;
begin
RMDebug('walking to ' + IntToStr(where));

// SetRun(true);

if Where = SYMBOL_BANK then
TP := Point(MMCX - 10, MMCY - 35)
else
TP := Point(MMCX + 10, MMCY + 35);

if not FindSymbolWithTPA(Where, TP2) then
begin
RMDebug('couldn''t find symbol. Blind Click');
MouseMM(TP.x, TP.y, 3, 3);
Result := false;

while IsMoving do
FFlag(5);

end else begin
Mouse(TP2.x, TP2.y, 2, 2, true);
Result := true;
end;

if not Result then
if FindSymbolWithTPA(Where, TP) then
begin
Mouse(TP.x, TP.y, 2, 2, true);
Result := true;
end else begin
RMDebug('Unable to Symbol Walk');
Result := false;
exit;
end;

if Result then
begin
FFlag(5);
while IsMoving do
FFlag(5);
end;

RMDebug('Walked: ' + BoolToStr(Result));

end;




{ RM --------------------------------------------------------------------------]
[ Clicks the Rocks/Ladder Zone ]
[------------------------------------------------------------------------------}
function ClickMMLadder: boolean;
var
TP: TPoint;
begin
RMDebug('Clicking MM Ladder');
Result := FindMMLadder(TP);

if Result then
begin
Mouse(TP.x, TP.y, 3, 3, true);
RMDebug('Clicked MM Ladder');
end else
RMDebug('Couldn''t Click Ladder');

end;

{ RM --------------------------------------------------------------------------]
[ Moves around in the Guild ]
[------------------------------------------------------------------------------}
function RelocateGuild: boolean;
var
TP: TPoint;
begin
RMDebug('Relocating in Guild');

RMRandoms(true);

if FindSymbolWithTPA(SYMBOL_MINING, TP) then
begin
Mouse(TP.x, TP.y, 10, 10, true);
Result := true;
end;
end;

{ RM --------------------------------------------------------------------------]
[ Clicks away from MM door if close to it. ]
[------------------------------------------------------------------------------}
function GetAwayFromDoor: boolean;
var
DoorTP: TPoint;
i, dist: integer;
begin
Result := FindMMDoor(DoorTP);

if not Result then
begin
RMDebug('No door on MM');
exit;
end else
RMDebug('Door on MM: ' + IntToStr(distance(DoorTP.x, DoorTP.y, MMCX, MMCY)));


dist := distance(DoorTP.x, DoorTP.y, MMCX, MMCY);
Result := (dist < MIN_DOOR_DIST);

if Result then
begin
Mouse(MMCX, MMCY + MIN_DOOR_DIST - dist + 10, 3, 5, true)

for i := 0 to 9 do
begin
wait(100)
if IsMoving then
break;
end;

while (IsMoving)or(FFlag(0)) do
wait(100);
end;

end;

{ RM --------------------------------------------------------------------------]
[ Gets out of the guild ]
[------------------------------------------------------------------------------}
Procedure WalkOutGuild;
var
i: integer;
ClickedLadder: Boolean;
begin
if not LoggedIn then exit;
RMDebug('WalkOutGuild');
SetRun(false);

if not InvFull then exit;

repeat
RMRandoms(true);
if not LoggedIn then exit;


//just in case we lagged and are outside of guild
if not InGuild(500, false) then
break;

RMDebug('getting out of guild');

RMDebug('walking to guild entrance');
for i:= 0 to 2 do
begin

if not LoggedIn then break;

if not InGuild(500, false) then
break;

if ClickMMLadder then
ClickedLadder := True
else begin
Mouse(MMCX - 50, MMCY + 15, 5, 5, true);
RMDebug('Blind Click');
ClickedLadder := False;
end;

FFlag(10);
while IsMoving do
while FFlag(0) do
wait(500);

if ClickedLadder then
begin
RMDebug('Clicked MM ladder');
break;
end;
end;

if not ClickedLadder then
begin
DeActivatePlayer('Failed WalkOutGuild');
RMDebug('Didn''t manage to get out of guild');
exit;
end;

wait(random(500));

RMDebug('looking for ladder');
if not SmartColorsEx(LADDER_INSIDE) then
continue
else begin
while IsMoving do
while FFlag(0) do
wait(500);
wait(2000+Random(1000));
end;

until(not InGuild(10000, false))

RMDebug('out of guild');
wait(1000+Random(1000));
end;

{ RM --------------------------------------------------------------------------]
[ Keeps track of rock while player moves around ]
------------------------------------------------------------------------------}
Function FollowRock(Rock: integer; var ThePoint: TPoint): boolean;
var
ATPA: T2DPointArray;
TPA: TPointArray;
time: integer;
TB: TBox;
OldPoint : TPoint;
BreakNext: boolean;
begin
time := 0;

repeat
wait(20);
OldPoint := ThePoint;

TB := MakeMSBox(ThePoint, 50);

if not FindOreBox(TPA, Rock, TB) then
begin
SetLength(TPA, 1);
TPA[0] := Point(0, 0);
DrawDots(TPA);
exit;
end;

ATPA := TPAToATPAEx(TPA, 20, 20);

if (Length(ATPA) > 1) then
SortATPAFromFirstPoint(ATPA, Point(MSCX, MSCY));

try
ThePoint := MiddleTPA(ATPA[0]);
except
ThePoint := MiddleTPA(TPA);
end;




if GetSystemTime > time then
begin
DrawDots(TPA);
time := GetSystemTime + 1000;
end;

if BreakNext then
break;

if not (FlagDistance > 0) then
if not IsMoving then
BreakNext := true;

until(false)

if Distance(ThePoint.x, ThePoint.y, MSCX, MSCY) > 50 then
begin
Result := false;
{ I wish to keep it there for now, to be able to better trim.
TPA[0] := Point(0, 0);
DrawDots(TPA);
}
end else begin
Result := true;
DrawDots(TPA);
DrawBox(TPA, clLime);
end;

ThePoint := MiddleTPA(TPA);

end;

{ RM --------------------------------------------------------------------------]
[ Checks if the Rock we are mining still has ore ]
[------------------------------------------------------------------------------}
Function IsRockHere(Rock, SCount: integer; Where: TPoint): boolean;
var
timer: integer;
Box: TBox;
TPA: TPointArray;
begin
//Avoids errors if it wrongly located the rock
if Distance(Where.x, Where.y, MSCX, MSCY) > 50 then
begin
Result := true;
exit;
end;

Box := MakeMSBox(Where, 20);

timer := GetSystemTime + DETECT_ROCK_TIME;
Result := false;

while Timer > GetSystemTime do
begin

if InvCount > SCount then
begin
Result := false;
break;
end;

if FindOreBox(TPA, Rock, Box) then
begin
DrawBox(TPA, clBlue);
Result := true;
exit;
end;

wait(100);
end;

if not Result then
begin
SetLength(TPA, 1);
TPA[0] := Where;
DrawBox(TPA, clRed);
end;

end;

{ RM --------------------------------------------------------------------------]
[ Mines Ore ]
[------------------------------------------------------------------------------}
Function MineOre(var which: integer): boolean;
var
TP: TPoint;
begin
if Random(100) <= Players[CurrentPlayer].Integers[P_MITHP] then
if FindSymbolWithTPA(SYMBOL_MINING, TP) then
if (TP.x - 5) < MMCX then
if (TP.y - 5) < MMCY then
begin
RMDebug('Searching for Mith');
Result := SmartColorsEx(ROCK_MITH);
which := ROCK_MITH;
end;


if not Result then
begin
RMDebug('Searching for Coal');
Result := SmartColorsEx(ROCK_COAL);
which := ROCK_COAL;
end;

end;


{ RM --------------------------------------------------------------------------]
[ Mining Loop ]
[------------------------------------------------------------------------------}
Procedure MineLoop;
var
Timer, ThePlace, TheRock, TTime, SCount, SwitchTimes: integer;
str: string;
Switch, Followed: boolean;
RockPoint: TPoint;
begin
RMDebug('MineLoop');

if not InGuild(500, true) then
exit;

RMDebug('MineLoop - In guild.');

TTime := GetSystemTime + 15*60*1000;

repeat
RMRandoms(true);
RunEnergy(70);
if not LoggedIn then exit;

//will only be useful when there is multiplayer or world switching.
{
if TTime < GetSystemTime then
begin
RMDebug('Load took too long');
LogOut;
Players[CurrentPlayer].Active := false;
Players[CurrentPlayer].Loc := 'Load took too long';
exit;
end;
}

GameTab(TAB_INV);
if InvFull then
begin
RMDebug('Full Load');
Inc(Loads);
Inc(Stats_CustomVars[STATS_LOADS]);
Inc(Players[CurrentPlayer].Banked);
ProgressReport;
break;
end;

RMDebug('Loads: '+ IntToStr(Loads));

SetMode(Random(2));


while IsMoving do
while FFlag(0) do
wait(250);

GameTab(TAB_INV);
SCount := InvCount;
Timer := GetSystemTime;

if GetAwayFromDoor then
RMDebug('Moved away from MM door.');

if MineOre(TheRock) then
begin

RMRandoms(true);

if ((GetSystemTime - Timer) > 5000) then
Switch := true; //avoiding bad / empty locations of guild

ThePlace := FindNeutralText(str);

GetMousePos(RockPoint.x, RockPoint.y);

if not FollowRock(TheRock, RockPoint) then
begin
RMDebug('FollowRock failed - unable to follow rock');
//continue;
end else begin
Followed := true;
SwitchTimes := 0;
Switch := False;
{
RMDebug('Moving Mouse to rock');
RMDebug('RockPoint X: ' + IntToStr(RockPoint.x));
RMDebug('RockPoint Y: ' + IntToStr(RockPoint.y));
//RMMMouse(RockPoint.x, RockPoint.y, 3, 3, Move); - 7th May 2010
//wait(5000);
}
end;

if CheckChat(str, ThePlace, STAGE_TO_ROCK, 5000) then
begin
Switch := False;

Timer := GetSystemTime + UseMode.WaitInvCount;
RMDebug('Max wait time for rock: '+IntToStr(UseMode.WaitInvCount));

Gametab(TAB_INV);

while (SCount = InvCount) do
begin

RMRandoms(false);

wait(100);

if IsFKeyDown(11) then
begin
RMDebug('Waiting for rock aborted by user');
break;
end;
if not (InvCount > SCount) then
if Followed then
if not IsRockHere(TheRock, SCount, RockPoint) then
begin
RMDebug('Rock not here');
break;
end;

if GetSystemTime > Timer then
begin
RMDebug('Rock took too long');

if Followed then
if IsRockHere(TheRock, SCount, RockPoint) then
if CheckAndClick(RockPoint, SCObjectsArray[ROCK_COAL]) then
Timer := GetSystemTime + UseMode.WaitInvCount
else
break
else
break
else
break;

end;

end;
wait(Random(UseMode.WaitRandom));
end;

end else
Switch := True;

if Switch then
begin
Inc(SwitchTimes);

if SwitchTimes > 3 then
begin
Players[CurrentPlayer].Active:= False;
Players[CurrentPlayer].Loc := 'lost';
LogOut;
exit;
end;

RelocateGuild;
Switch := False;
end;

while IsMoving do
wait(500);
until(false)
end;

function Bank: boolean; forward;

{ RM --------------------------------------------------------------------------]
[ Walks from bank to mining guild ]
[------------------------------------------------------------------------------}
function ToGuild: boolean;
var
i: integer;
begin
if not LoggedIn then exit;
Result := false;

RMDebug('ToGuild');

SetRun(true);

RMRandoms(true);

if not LoggedIn then exit;

for i := 0 to 2 do
begin

if InvFull then
exit;

//just in case we lagged and are INSIDE the guild
if InGuild(500, true) then
begin
Result := true;
exit;
end;

RMDebug('getting to guild');

if not WalkSymbol(SYMBOL_DUNGEON) then
continue;

wait(100+random(1000));

While IsMoving do
while FFlag(0) do
wait(500);

break;

end;

if i > 2 then
begin
Players[CurrentPlayer].Active := false;
LogOut;
Players[CurrentPlayer].Loc := 'Lost - ToGuild';
RMDebug('Player got lost on way to guild');
end else
Result := SmartColorsEx(LADDER_OUTSIDE);



end;

{ RM --------------------------------------------------------------------------]
[ Walks from mining guild to bank ]
[------------------------------------------------------------------------------}
function ToBank: boolean;
var
i, bx, by: integer;
WhichAngle: extended;
begin
if not LoggedIn then exit;

Result := false;
RMDebug('ToBank');
RMRandoms(true);

if not LoggedIn then exit;
if not InvFull then exit;


for i:= 0 to 2 do
begin
if InGuild(500, false) then
break;

RMDebug('getting to bank');

if not WalkSymbol(SYMBOL_BANK) then
if not FindDtmRotated(BankDTM, bx, by, MMX1, MMY1, MMX2, MMY2, Radians(-30), Radians(30), 0.05, WhichAngle) then
continue
else
RMMMouse(bx, by, 0, 0, LeftC);

RMDebug('waiting while moving');
While IsMoving do
while FFlag(0) do
wait(500);

RMDebug('done waiting');
break;

end;

if i <= 2 then
Result := Bank;

if Result then exit;

Players[CurrentPlayer].Active := false;
LogOut;
Players[CurrentPlayer].Loc := 'lost - ToBank';
RMDebug('Unable to bank, going false');

end;

{ RM --------------------------------------------------------------------------]
[ Deposits Items ]
[------------------------------------------------------------------------------}
Procedure DepositItems(All: boolean);
begin
if not BorPScreen then exit;

if All then
DepositAll
else
Deposit(2, 28, True);
{
for i := 1 to 28 do
if ExistsItem(I) then
begin
writeln('Checking Item: '+IntToStr(i));
IBox := InvBox(I);
if not FindDTM(PickDTM, x, y, IBox.x1, IBox.y1, IBox.x2, IBox.y2) then
Deposit(i, i, True)
else
writeln('Found Pick at: '+IntToStr(i));
end;
}
end;

{ RM --------------------------------------------------------------------------]
[ Banks ]
[------------------------------------------------------------------------------}
function Bank: boolean;
var i: integer;
begin
if not LoggedIn then exit;

RMDebug('Entering Bank function');
RMRandoms(true);
if not LoggedIn then exit;

if InvCount = Integer(not Players[CurrentPlayer].Booleans[P_WIELDED]) then
exit;

if InGuild(500, true) then
exit;

RMDebug('banking');

repeat
for i := 0 to 1 do
begin
if BorPScreen then break;

if i = 0 then
if SmartColorsEx(BANK_BOOTH) then
break;

if i = 1 then
if FindBank(BANK_FE) then
break;

RMRandoms(true);
end;

if i > 1 then
begin
RMDebug('Unable to find bank.');
Result := false;

Inc(Players[CurrentPlayer].Integers[P_BANK_TRIES]);

if Players[CurrentPlayer].Integers[P_BANK_TRIES] <= MAX_BANK_TRIES then
begin
RMDebug('trying again');
ToBank;
end;

exit;
end;

Players[CurrentPlayer].Integers[P_BANK_TRIES] := 0;

wait(2000+random(1000));
while IsMoving do
while FFlag(0) do
wait(100);

if WaitFunc(@BorPScreen, 100, 5000) then
begin
RMDebug('in here');
wait(1000+random(500));

i := 0;
repeat
RMDebug('leaving ' + BoolToStr(not Players[CurrentPlayer].Booleans[P_WIELDED]) + ' items in inv');
DepositItems(Players[CurrentPlayer].Booleans[P_WIELDED]);
WaitInvMaxCount(Integer(not Players[CurrentPlayer].Booleans[P_WIELDED]), 5000);

inc(i);
if i > 2 then
begin
RMDebug('banking failed.... lag?');
CloseBank;
exit;
end;

until(InvCount = Integer(not Players[CurrentPlayer].Booleans[P_WIELDED]))

i := 0;
repeat
CloseBank;
wait(500+random(500));

inc(i);
if i > 2 then
begin
RMDebug('lagging at closing bank..');
wait(3000 + random(1000));
i := 0;
end;

until(not BankScreen)

RMDebug('Banked..');
Result := true;
exit;
end;
until(BorPScreen)
end;

{ RM --------------------------------------------------------------------------]
[ Rests the player if it has been running for more than 20+rand(10) minutes ]
[------------------------------------------------------------------------------}
Procedure SetupPlayer; forward;
Procedure Rest;
begin

if AllPlayersInactive then
exit;

if (GetSystemTime > TimeGoing) then
begin
if PlayersActive > 1 then
NextPlayer(Players[CurrentPlayer].Active)
else begin
RMDebug('sleeping');
LogOut;
wait(3*60*1000 + Random(3*60*1000));
LoginPlayer;
end;

SetupPlayer;
TimeGoing := (GetSystemTime + FIXED_TIME*60*1000 + Random(RAND_TIME*60*1000));
RMDebug('restarted');
end;
end;

{ RM --------------------------------------------------------------------------]
[ Sets up SmartColors ]
[------------------------------------------------------------------------------}
Procedure SetupColors;
begin
{
SetupSmartColorsDetailsEx(
Index, ColorMin, ColorMax,
MaxColors, BoxSize, Tol,
Dist, ClickStyle, R_RL_Chance
: integer);
}

//coal
MakeObjEx( ROCK_COAL,
RMColors[_Coal].Color,
RMColors[_Coal].Tol,
RMColors[_Coal].h,
RMColors[_Coal].s,
['ine', 'ock'], ['ine'] );

SetupSmartColorsDetailsEx(ROCK_COAL, 3, 100, 7, 30, 5, 15, 3, 15);

//mith
MakeObjEx( ROCK_MITH,
RMColors[_Mith].Color,
RMColors[_Mith].Tol,
RMColors[_Mith].h,
RMColors[_Mith].s,
['ine', 'ock'], ['ine'] );

SetupSmartColorsDetailsEx(ROCK_MITH, 3, 100, 7, 30, 10, 15, 3, 15);

//bank booth
MakeObjEx( BANK_BOOTH,
RMColors[_Bank].Color,
RMColors[_Bank].Tol,
RMColors[_Bank].h,
RMColors[_Bank].s,
['ank', 'ooth'],
['qui', 'ick', 'kly'] );

SetupSmartColorsDetailsEx(BANK_BOOTH, 3, 300, 7, 50, 10, 15, 2, 100);

//Outside Ladder
MakeObjEx( LADDER_OUTSIDE,
RMColors[_LadderOutside].Color,
RMColors[_LadderOutside].Tol,
RMColors[_LadderOutside].h,
RMColors[_LadderOutside].s,
['limb', 'own', 'adder'],
['down'] );

SetupSmartColorsDetailsEx(LADDER_OUTSIDE, 2, 100, 7, 150, 20, 20, 2, 15);

//Inside Ladder
MakeObjEx( LADDER_INSIDE,
RMColors[_LadderInside].Color,
RMColors[_LadderInside].Tol,
RMColors[_LadderInside].h,
RMColors[_LadderInside].s,
['limb', 'up', 'adder'],
['limb'] );

SetupSmartColorsDetailsEx(LADDER_INSIDE, 2, 200, 7, 50, 20, 20, 2, 15);

end;

{ RM --------------------------------------------------------------------------]
[ Prepares the Player for Mining ]
[------------------------------------------------------------------------------}
Procedure SetupPlayer;
begin
TimeGoing := (GetSystemTime + FIXED_TIME*60*1000 + Random(RAND_TIME*60*1000));

if not LoggedIn then
LoginPlayer;

SetAngle(true);
Players[CurrentPlayer].Integers[P_BANK_TRIES] := 0;

PTime.StartTime := GetSystemTime;
PTime.PreviousTime := Players[CurrentPlayer].Worked;
PTime.CurrTime := GetSystemTime - PTime.StartTime;

Players[CurrentPlayer].Level[Skill_Mining] := GetSkillLevel(Skill_Mining);
CheckPickAxe;
end;

{ RM --------------------------------------------------------------------------]
[ Sets up All necessities ]
[------------------------------------------------------------------------------}
Procedure SetupScript;
begin
Smart_Server := RM_SERVER;
Smart_Signed := RM_SIGNED;
AllowPVP := false;

DeclarePlayers;

RMLoadColors;
SetupColors;
SetupSRL;

ActivateClient;

BankDTM := DTMFromString('78DA630C67666098C580028E1CD90367FF070' +
'2467FA09A45103E2354FCCF1F260626243E6310116AC2A8A4268A' +
'08357184D500001B001913');

PickDTM := DTMFromString('78DA639CC0CCC0F088910104202404B023F11' +
'9416A1EA3AAE929F44255D30F54F31EDD1C4654353D4035BF08A8' +
'E902AAF947404D3B50CD33026A1A816A9E1250331BA8E62501351' +
'309AB0100CDF50F0F');

//SRL Stats
Stats_ScriptID := SCRIPT_ID;
Stats_UserID := USER_ID;
Stats_Password := USER_PW;

{$ifndef Simba}
ClearReport;
{$else}
AddOnTerminate('ProgressReport');
{$endif}
AddToReport(IntToStr(RMColors[_Coal].Color));
{$ifdef SmartDebug}
SmartSetDebug(True);
{$endif}

end;




begin

SetupScript;

repeat

SetupPlayer;

repeat
if not LoggedIn then break;

if not ToGuild then
begin
Inc(Players[CurrentPlayer].Integers[W_GUILD]);
if Players[CurrentPlayer].Integers[W_GUILD] > WALK_ATTEMPTS then
begin
DeActivatePlayer('Failed ToGuild');
continue;
end;
end;


if not InvFull then
begin
if not InGuild(5000, true) then
continue; //waits to be inside guild

RMDebug('getting to rocks');

wait(random(1000));
RMMMouse(MMCX + 50, MMCY, 5, 5, LeftC);
wait(500);
while IsMoving do
while FFLag(0) do
wait(200);
end;

MineLoop;
WalkOutGuild;

if not ToBank then
begin
Inc(Players[CurrentPlayer].Integers[W_BANK]);
if Players[CurrentPlayer].Integers[W_BANK] > WALK_ATTEMPTS then
begin
DeActivatePlayer('Failed ToBank');
continue;
end;
end;

Rest;


until(IsFKeyDown(12))

until(AllPlayersInactive)
FreeDTM(BankDTM);
writeln('Finishing loop... :( ');
end.

I think that now that we got to talk about it it should be released, no?

~RM

mastaraymond

2011-02-10 10:29:03

Should be merged into MSI, imo.

Further more it needs to be updated, like deprecated stats, and my name needs to be removed as I did not code, I merely made it compiling in Simba.

Sir R. M8gic1an

2011-02-10 10:43:10

Okay, removed you as author, kept you as converter? Dunno, kinda hard to name what ur contribution was, but yeh pretty much u made it work for Simba too right? And a couple features u added there I saw :)

Anyway, yeh I won't be merging my own script into MSI. MSI is child to me and they already have a GM.

I'll keep it SSRM Guild Miner as a praise to you, because 'R' could be for Rasta or for Ray, but RM is definitely for Rasta Magician :)

S & S does stand for Simba & Scar tho ;)

but SRGM actually stands for Simba RM Guild Miner

~RM

Sir R. M8gic1an

2011-02-10 10:46:26

This script really needs cleanup.

I think I'll probably include MSI as a Library for the next release.

~RM

YoHoJo

2011-02-10 15:03:49

Single Player?
found declare players all the way down on line 283.

Ladder colors are off? Mined a load, walk to ladders, mouse was hovering over the walls/everything besides the ladders. Need a failsafe there too.

It's really fun watching it draw all of the debug stuff onto SMART though!

Sir R. M8gic1an

2011-02-11 08:24:57

Yeh, colors might be off, haven't got around to updating them again :)

Just find the right constant and change it :D

~RM