SRL Archive - MSI Suggestions

MSI_PlayerSetup


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.

Sir R. M8gic1an

2009-12-20 05:35:58

humm….



Players[0].Integers[P_SKILL] := SKILL_WOODCUTTING;

case Players[CurrentPlyaer].Integers[P_SKILL] of
SKILL_WOODCUTTING:
//...

Otherwise looking good :)

~RM

Nava2

2009-12-20 10:02:10

Love the standards of MSI, just a rather aside.

Anyways:
case currLevel of
REQ_BRONZE..(REQ_STEEL - 1):
toolArr := [ PICKAXE_IRON, PICKAXE_BRONZE ];

REQ_STEEL..(REQ_MITHRIL - 1):
toolArr := [ PICKAXE_STEEL, PICKAXE_IRON, PICKAXE_BRONZE ];

REQ_MITHRIL..(REQ_ADAMANT - 1):
toolArr := [ PICKAXE_MITHRIL, PICKAXE_STEEL, PICKAXE_IRON,
PICKAXE_BRONZE ];

REQ_ADAMANT..(REQ_RUNE - 1):
toolArr := [ PICKAXE_ADAMANT, PICKAXE_MITHRIL, PICKAXE_STEEL,
PICKAXE_IRON, PICKAXE_BRONZE ];

REQ_RUNE..REQ_MAX_LEVEL:
toolArr := [ PICKAXE_RUNE, PICKAXE_ADAMANT, PICKAXE_MITHRIL,
PICKAXE_STEEL, PICKAXE_IRON, PICKAXE_BRONZE ];
else
MSI_Debug('MSI_SetupPlayer', 'Invalid Skill Level.', debug_Functions);
end;

Could be:
var
i: Integer;
maxToolArr: Integer;
maxToolInd: Integer;

case (Players[i].Integers[P_SKILL]) of
SKILL_MINING:
maxToolArr := [PICKAXE_BRONZE, PICKAXE_IRON, PICKAXE_STEEL,
PICKAXE_MITHRIL, PICKAXE_ADAMANT, PICKAXE_RUNE];
//...
end;

for i := 0 to 6 do
if (curLevel <= levelArr[i]) then
begin
maxToolInd := i;
break;
end;
setLength(toolArr, maxToolInd + 1);
for i := 0 to maxToolInd do
toolArr[i] := maxToolArr[i];

// :D

Will make it shorter as you add more to it :)

Coh3n

2009-12-20 22:47:20

Thanks both of you, I've updated the first post. I hope I'm doing the Players array stuff right (P_SKILL, P_LOC).

EDIT: I edited the first post again.