Coh3n
2009-12-20 00:45:24
function MSI_PlayerSetup: Boolean;
Since I haven't really done much to help out MSI in a while, I thought I'd try to get things rolling again. After taking a look at the MainLoopDraft RM committed, I thought it may be a good idea to come up with a function like this.
I haven't been able to test it, and I'm sure it can be improved/modified. The only thing I don't like is the IntToStr conventions. I'm not even sure if the function will work with them included. Like I said, I haven't been able to test, and I won't be able to work on it again until Monday, so criticism/feedback is appreciated.
program MSI_PlayerSetup_Test;
{.Include SRL/SRL/msi/Setup.scar}
const
SKILL_COUNT = 24;
{ 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;
{ const Players.
Constants representing the different Players array integers. }
const
P_SKILL = 0;
P_LOC = 1;
procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
with Players[0] do
begin
Name := '';
Pass := '';
Nick := '';
Pin := '';
Active := True;
Integers[P_SKILL] := SKILL_WOODCUTTING;
end;
end;
{******************************************************************************}
{ function function MSI_SetupPlayer: Boolean; }
{ By: The MSI Team }
{ Rev: 53 }
{ Date: 19 Dec 09 }
{ Description: Sets up the player for autoing. }
{******************************************************************************}
function MSI_SetupPlayer: Boolean;
var
toolArr, maxToolArr, reqArr: TIntegerArray;
currLevel, currSkill, maxToolInd: Integer;
x, y, h, hi, i, ii, j, k: Integer;
skillsArr: Array[0..SKILL_COUNT] of String;
bankCheck: Boolean;
begin
if (not LoggedIn) then
LoginPlayer;
SetAngle(True);
SetRun(True);
{ 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];
currLevel := GetSkillLevel(skillsArr[currSkill]);
case (Players[CurrentPlayer].Integers[P_SKILL]) of
SKILL_WOODCUTTING, SKILL_MINING:
begin
reqArr := [ REQ_BRONZE, REQ_IRON, REQ_STEEL, REQ_MITHRIL, REQ_ADAMANT,
REQ_RUNE, REQ_MAX_LEVEL ];
case (Players[CurrentPlayer].Integers[P_SKILL]) of
SKILL_WOODCUTTING:
maxToolArr := [ HATCHET_RUNE, HATCHET_ADAMANT, HATCHET_MITHRIL,
HATCHET_STEEL, HATCHET_IRON, HATCHET_BRONZE ];
SKILL_MINING:
maxToolArr := [ PICKAXE_RUNE, PICKAXE_ADAMANT, PICKAXE_MITHRIL,
PICKAXE_STEEL, PICKAXE_IRON, PICKAXE_BRONZE ];
end;
end;
else
MSI_Debug('MSI_SetupPlayer', 'Invalid Skill Name.', debug_Functions);
end; // of Players.Skill case.
h := High(maxToolArr);
for i := 0 to h do
if (currLevel <= reqArr[i]) then
begin
maxToolInd := i;
Break;
end;
setLength(toolArr, maxToolInd + 1);
for k := 0 to maxToolInd do
toolArr[k] := maxToolArr[k];
hi := High(toolArr);
for j := 0 to hi do
begin
Result := MSI_FindTool(toolArr[j], 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 ii := 0 to h do
begin
Result := MSI_Withdraw([toolArr[ii]], [1]);
if (Result) then
Break;
end
else
MSI_Debug('MSI_SetupPlayer', 'Unable to Open Bank.', debug_Functions);
end;
end;
begin
SetupSRL;
ActivateClient;
DeclarePlayers;
Players[CurrentPlayer].Integers[P_LOC] := LOC_VEBANK;
if MSI_SetupPlayer then
Writeln('Successfully Setup Player!')
else
Writeln('Couldn''t Setup Player.');
end.