SRL Archive - MSI Suggestions

MSI_SetupPlayer


Gu3st...

2010-10-02 16:24:07

Currently, MSI_SetupPlayer is based on that it needs a tool to mine/chop/fish something and withdraws that tool from the bank, and after that MSI_MainLoop will walk to a specified location to perform a task.
The issue with this is that with cooking, you don't use any tools, but you still want to withdraw items from the bank. This applies to other skills that needs to withdraw items from the bank that's not tools (Runecrating, Fletching, Firemaking, Crafting, Smithing…..)

How should we solve this problem?

Sir R. M8gic1an

2010-10-03 08:38:17

New Array. Ingredients.

Ores for smithing, Raw food for cooking, ores for crafting + tool. Etc.

Also, I've noticed that at least for mining it checks the stats twice before starting to auto. If we can reduce this to once by grabbing all the stats the first time around, that'd be great.

~RM

Coh3n

2010-10-03 20:10:44

From: Sir R. Magician
Also, I've noticed that at least for mining it checks the stats twice before starting to auto. If we can reduce this to once by grabbing all the stats the first time around, that'd be great.

~RM

I've noticed that also, but haven't had the time to properly look through it.

Honestly, I feel SetupPlayer isn't horribly unorganized and needs a rewrite. I actually think the procedure could be reduced to grabbing skill levels then calling a setup function placed in each skill file. How would this work? Simple, another pointer in TScript. We could also get rid of the Tools attribute. Just a few things:
  • MSI_BestTool/WorstTool can be placed in Skills.simba, along with a function that gets and sets the player's skill level information.
  • A new function (MSI_WithdrawTools, or something similar to work will all skills) can be added to Banking.simba.
  • The new MSI_SetupPlayer would look something like this:

  • function MSI_SetupPlayer: Boolean;
    begin
    MSI_AddHeader('MSI_SetupPlayer');

    if (not LoggedIn) then
    begin
    MSI_Debug('Player is not logged in');
    if (not (WaitFunc(@LoginPlayer, 100, 5000))) then
    begin
    MSI_CloseHeader('MSI_SetupPlayer: ' + BoolToStr(Result));
    Exit;
    end;
    end;

    // Add logins to stats
    Inc(Stats_CustomVars[STATS_LOGINS]);
    MSI_SendStats;

    // Standard setup procedures
    MSI_FindRandoms;
    SetAngle(True);
    RunEnergy(20);

    // Setup the player
    MSI_SetSkillLevels();
    with MSI_Players[CurrentPlayer] do
    Result := MSI_Scripts[Scripts[CurrentScript]].SetupPlayer();

    MSI_CloseHeader('MSI_SetupPlayer: ' + BoolToStr(Result));
    end;
  • Each skill file would have a SetupSkill procedure, and if there are certain procedures common in 2+ skills, a separate function can be made and placed in Skills.simba (MSI_SetSkillLevels, MSI_BestTool/WorstTool, MSI_WithdrawTools, etc.).
  • All the required tools business can easily be done within the skill files. Fishing.simba is a good example.
Thoughts?

NCDS

2010-10-03 20:32:11

From: Coh3n
I've noticed that also, but haven't had the time to properly look through it.

Honestly, I feel SetupPlayer isn't horribly unorganized and needs a rewrite. I actually think the procedure could be reduced to grabbing skill levels then calling a setup function placed in each skill file. How would this work? Simple, another pointer in TScript. We could also get rid of the Tools attribute. Just a few things:
  • MSI_BestTool/WorstTool can be placed in Skills.simba, along with a function that gets and sets the player's skill level information.
  • A new function (MSI_WithdrawTools, or something similar to work will all skills) can be added to Banking.simba.
  • The new MSI_SetupPlayer would look something like this:

  • function MSI_SetupPlayer: Boolean;
    begin
    MSI_AddHeader('MSI_SetupPlayer');

    if (not LoggedIn) then
    begin
    MSI_Debug('Player is not logged in');
    if (not (WaitFunc(@LoginPlayer, 100, 5000))) then
    begin
    MSI_CloseHeader('MSI_SetupPlayer: ' + BoolToStr(Result));
    Exit;
    end;
    end;

    // Add logins to stats
    Inc(Stats_CustomVars[STATS_LOGINS]);
    MSI_SendStats;

    // Standard setup procedures
    MSI_FindRandoms;
    SetAngle(True);
    RunEnergy(20);

    // Setup the player
    MSI_SetSkillLevels();
    with MSI_Players[CurrentPlayer] do
    Result := MSI_Scripts[Scripts[CurrentScript]].SetupPlayer();

    MSI_CloseHeader('MSI_SetupPlayer: ' + BoolToStr(Result));
    end;
  • Each skill file would have a SetupSkill procedure, and if there are certain procedures common in 2+ skills, a separate function can be made and placed in Skills.simba (MSI_SetSkillLevels, MSI_BestTool/WorstTool, MSI_WithdrawTools, etc.).
  • All the required tools business can easily be done within the skill files. Fishing.simba is a good example.
Thoughts?


I don't see anything wrong with doing this at all.

It does seem like DeclarePlayers is getting a bit long.

Coh3n

2010-10-03 20:39:06

From: NCDS
It does seem like DeclarePlayers is getting a bit long.

Those changes wouldn't effect DeclarePlayers at all.

And we're going to have to accept the fact that it'll be long. It has to be if we plan to support so many skills.

NCDS

2010-10-03 20:49:46

From: Coh3n
We could also get rid of the Tools attribute.


You said yourself..?

Now that I read through it again I see what I got lost on though. I thought you were saying everything was going to be loaded skill specific. I must have over looked the part about putting Tools in Skills.Simba.

Coh3n

2010-10-03 20:52:59

From: NCDS
You said yourself..?

Now that I read through it again I see what I got lost on though. I thought you were saying everything was going to be loaded skill specific. I must have over looked the part about putting Tools in Skills.Simba.

Just the Setup functions. MSI_SetupWoodcutting, MSI_SetupMining, etc. Nothing about tools would go in Skills.simba. The tools would be used in MSI_SetupMining, etc.

NCDS

2010-10-03 21:58:25

From: Coh3n
Just the Setup functions. MSI_SetupWoodcutting, MSI_SetupMining, etc. Nothing about tools would go in Skills.simba. The tools would be used in MSI_SetupMining, etc.


Yeah, I know what your saying. Apparanetly it's just coming out wrong on my end :redface:

Coh3n

2010-10-04 01:17:19

From: NCDS
Yeah, I know what your saying. Apparanetly it's just coming out wrong on my end :redface:

Lol as long as you know what I mean.

There are a lot of things I've noticed throughout the include that could be greatly improved, but I'm trying not to stress about it now. This needs to be done so other skills can be added, so if you guys don't mind, I'd like to take care of this one. The rest can wait.

I think our greatest priority should be obstacle handling right now. I'm going to make a post on RM's thread for things I think we can do.

Gu3st...

2010-10-04 09:20:43

The progress of cooking.simba pretty much relies on that we get this done fast, but I agree. Obstacle handling is of a greater concern.

Coh3n

2010-10-04 13:13:25

From: Zyt3x
The progress of cooking.simba pretty much relies on that we get this done fast, but I agree. Obstacle handling is of a greater concern.

I'll do my best to get this done as soon as possible. :)

E: Just made these changes before school. What do you guys think so far?

// Skills.simba
{******************************************************************************}
{ procedure MSI_GetSkillLevels(); }
{ By: Coh3n }
{ Date: 04 October 2010 }
{ Description: Gets the player's skill levels for each script }
{******************************************************************************}
procedure MSI_GetSkillLevels();
var
i, curLev: Integer;
begin
if (not LoggedIn) then
Exit;

MSI_AddHeader('MSI_GetSkillLevels');

with MSI_Players[CurrentPlayer] do
for i := 0 to High(Scripts) do
begin
curLev := GetSkillLevel(MSI_Scripts[i].Skill);

// Only sets if the level has increased
if (curLev <= MSI_Scripts[Scripts[i]].PlayerSkillLevel) then
Continue;

// Set the TScript & ProgressReportArray attribute
MSI_Scripts[Scripts[i]].PlayerSkillLevel := curLev;
ProgressReportArray[CurrentPlayer].ScriptInfo[i].PlayerSkillLevel := curLev;

with MSI_Scripts[Scripts[i]] do
MSI_Debug(Skill + ' Level: ' + IntToStr(PlayerSkillLevel));
end;

MSI_CloseHeader('MSI_GetSkillLevels: Exit');
end;

// Debug.simba
{******************************************************************************}
{ procedure MSI_GetReportInfo; }
{ By: Coh3n & Shuttleu }
{ Date: 04 October 2010 }
{ Description: Gets the necessary proggy info that isn't automatically reset }
{ during runtime }
{******************************************************************************}
procedure MSI_GetReportInfo;
var
curLev, i: Integer;
script: TScript;
begin
for i := 0 to High(MSI_Players) do
with ProgressReportArray[i] do
begin
if (i = CurrentPlayer) then
MSI_GetSkillLevels();

PlayerLoc := MSI_Players[i].Location;
PlayerStatus := MSI_Players[i].Active;
end;
end;
Note that none of this will be committed until it's all finished.

Gu3st...

2010-10-04 15:03:01

That would get rid of the problem RM mentioned in this thread :)
Gj so far

Coh3n

2010-10-06 00:56:22

Here's some more. Yes, it's a clusterfuck. :o

// Skills.simba
{******************************************************************************}
{ procedure MSI_SetSkillLevels(); }
{ By: Coh3n }
{ Date: 04 October 2010 }
{ Description: Gets the player's skill levels for each script }
{******************************************************************************}
procedure MSI_SetSkillLevels();
var
i, curLev: Integer;
begin
if (not LoggedIn) then
Exit;

MSI_AddHeader('MSI_GetSkillLevels');

with MSI_Players[CurrentPlayer] do
for i := 0 to High(Scripts) do
begin
curLev := GetSkillLevel(MSI_Scripts[i].Skill);

// Only sets if the level has increased
if (curLev <= MSI_Scripts[Scripts[i]].PlayerSkillLevel) then
Continue;

// Set the TScript & ProgressReportArray attribute
MSI_Scripts[Scripts[i]].PlayerSkillLevel := curLev;
ProgressReportArray[CurrentPlayer].ScriptInfo[i].PlayerSkillLevel := curLev;

with MSI_Scripts[Scripts[i]] do
MSI_Debug(Skill + ' Level: ' + IntToStr(PlayerSkillLevel));
end;

MSI_CloseHeader('MSI_GetSkillLevels: Exit');
end;

{******************************************************************************}
{ function MSI_BestTool: Integer; }
{ By: Coh3n }
{ Date: 05 October 2010 }
{ Description: Determines the best tool for the chosen skill. Keep in mind }
{ this may not be used for every skill }
{******************************************************************************}
function MSI_BestTool: Integer;
begin
if (not LoggedIn) then
Exit;

with MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]] do
begin
case (SkillConstant) of
SKILL_WOODCUTTING:
case (PlayerSkillLevel) of
REQ_DRAGON..REQ_MAX_LEVEL: Result := HATCHET_DRAGON;
REQ_RUNE..REQ_DRAGON : Result := HATCHET_RUNE;
REQ_ADAMANT..REQ_RUNE : Result := HATCHET_ADAMANT;
REQ_MITHRIL..REQ_ADAMANT : Result := HATCHET_MITHRIL;
REQ_STEEL..REQ_MITHRIL : Result := HATCHET_STEEL;

else
Result := HATCHET_IRON;
end;

SKILL_MINING:
case (PlayerSkillLevel) of
REQ_DRAGON..REQ_MAX_LEVEL: Result := PICKAXE_DRAGON;
REQ_RUNE..REQ_DRAGON : Result := PICKAXE_RUNE;
REQ_ADAMANT..REQ_RUNE : Result := PICKAXE_ADAMANT;
REQ_MITHRIL..REQ_ADAMANT : Result := PICKAXE_MITHRIL;
REQ_STEEL..REQ_MITHRIL : Result := PICKAXE_STEEL;

else
Result := PICKAXE_IRON;
end;

else
MSI_SubDebug('MSI_BestTool: Invalid skill!');
end;

MSI_Debug('Best tool for ' + Skill + ' is '+ MSI_Items[Result].Name);
end;
end;

{******************************************************************************}
{ function MSI_WorstTool: Integer; }
{ By: Coh3n }
{ Date: 05 October 2010 }
{ Description: Determines the worst tool for the job at hand. }
{******************************************************************************}
function MSI_WorstTool: Integer;
begin
if (not LoggedIn) then
Exit;

with MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]] do
case skill of
SKILL_WOODCUTTING:
Result := HATCHET_BRONZE;

SKILL_MINING:
Result := PICKAXE_BRONZE;

else
MSI_SubDebug('MSI_WorstTool: Invalid skill!');
end;
end;

// Debug.simba
{******************************************************************************}
{ procedure MSI_GetReportInfo; }
{ By: Coh3n & Shuttleu }
{ Date: 04 October 2010 }
{ Description: Gets the necessary proggy info that isn't automatically reset }
{ during runtime }
{******************************************************************************}
procedure MSI_GetReportInfo;
var
curLev, i: Integer;
script: TScript;
begin
for i := 0 to High(MSI_Players) do
with ProgressReportArray[i] do
begin
if (i = CurrentPlayer) then
MSI_SetSkillLevels();

PlayerLoc := MSI_Players[i].Location;
PlayerStatus := MSI_Players[i].Active;
end;
end;

// Mainloop.simba
{******************************************************************************}
{ function MSI_SetupPlayer: Boolean; }
{ By: Coh3n }
{ Date: 05 October 2010 }
{ Description: Sets up the player for autoing }
{******************************************************************************}
function MSI_SetupPlayer: Boolean;
begin
MSI_AddHeader('MSI_SetupPlayer');

if (not LoggedIn) then
begin
MSI_Debug('Player is not logged in');
if (not (WaitFunc(@LoginPlayer, 100, 5000))) then
begin
MSI_CloseHeader('MSI_SetupPlayer: ' + BoolToStr(Result));
Exit;
end;
end;

// Add logins to stats
Inc(Stats_CustomVars[STATS_LOGINS]);
MSI_SendStats;

// Standard setup procedures
MSI_FindRandoms;
SetAngle(True);
RunEnergy(20);

// Setup the player
MSI_SetSkillLevels();
with MSI_Players[CurrentPlayer] do
Result := MSI_Scripts[Scripts[CurrentScript]].SetupPlayer();

MSI_CloseHeader('MSI_SetupPlayer: ' + BoolToStr(Result));
end;

{
var
bestTool, worstTool, x, y, i, j , k: Integer;
gameTabs, tools: TIntegerArray;
script: TScript;
begin
MSI_AddHeader('MSI_SetupPlayer');

if (not LoggedIn) then
begin
MSI_Debug('Player is not logged in');
if (not (WaitFunc(@LoginPlayer, 100, 5000))) then
begin
MSI_CloseHeader('MSI_SetupPlayer: ' + BoolToStr(Result));
Exit;
end;
end;

script := MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]];
Inc(Stats_CustomVars[STATS_LOGINS]);
MSI_SendStats;

SetAngle(True);
MSI_FindRandoms;
RunEnergy(20);

for i := 0 to High(script.Tools) do
case script.Tools[i] of
//first looks for the best tool depending on the player's skill level
TOOL_HATCHET, TOOL_PICKAXE:
begin
bestTool := MSI_BestTool;
worstTool := MSI_WorstTool;
gameTabs := [TAB_EQUIP, TAB_INV];

for j := 0 to High(gameTabs) do
for k := bestTool downto worstTool do
if (MSI_FindTool(k, gameTabs[j], x, y)) then
begin
Result := True;
MSI_CloseHeader('MSI_SetupPlayer: ' + BoolToStr(Result));
Exit;
end;

//if tool isn't found, will attempt to withdraw from bank

end;

TOOL_FISH:
begin
tools := MSI_FishingTools;

if (Length(tools) <= 0) then
Exit;

for i := 0 to High(tools) do
begin
if (not MSI_FindTool(tools[i], TAB_INV, x, y)) then
begin
MSI_Debug('Failed to find tool: ' + MSI_Items[tools[i]].Name);
if (i = High(tools)) then
Break;
Continue;
end;

Result := True;
end;

if (not Result) then
begin
if (script.BankType = NoBank) then
begin
MSI_CloseHeader('MSI_SetupPlayer: ' + BoolToStr(Result));
Exit;
end;

if (MSI_OpenBank(Script.WhichBank, MSI_Players[CurrentPlayer].Pin)) then
for j := 0 to High(tools) do
if MSI_Withdraw([tools[j]], [1]) then
begin
Result := True;
Break;
end else begin
CloseBank;
MSI_Debug('Couldn''t Withdraw Tool');
end
else
MSI_Debug('Unable to Open Bank');
end;
end;

else
MSI_Debug('Invalid tool option in script: ' + script.Name);
end;

MSI_CloseHeader('MSI_SetupPlayer: ' + BoolToStr(Result));
end;
}

// Woodcutting.simba
function MSI_SetupWoodcutting(): Boolean;
var
i: Integer;
tabs: TIntegerArray;
begin
for i := MSI_BestTool downto MSI_WorstTool do
begin
end;

if (script.BankType = NoBank) then
begin
MSI_CloseHeader('MSI_SetupPlayer: ' + BoolToStr(Result));
Exit;
end;
end;

// Banking.simba
function MSI_WithdrawBestTool(): Boolean;
begin
with MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]] do
if (MSI_OpenBank(WhichBank, MSI_Players[CurrentPlayer].Pin)) then
begin
for i := MSI_BestTool downto MSI_WorstTool do
if (MSI_Withdraw([i], [1])) then
begin
Result := True;
Break;
end;

if (not Result) then
begin
CloseBank;
MSI_Debug('Couldn''t Withdraw Tool');
end;

end else
MSI_Debug('Unable to Open Bank');
end;






Gu3st...

2010-10-06 03:40:17

Maybe a TOOLS_NONE in Globals.simba, so in MSI_BestTool and MSI_WorstTool won't result in false with scripts that uses none :)
Else great :D

Coh3n

2010-10-06 12:43:31

From: Zyt3x
Maybe a TOOLS_NONE in Globals.simba, so in MSI_BestTool and MSI_WorstTool won't result in false with scripts that uses none :)
Else great :D

Those functions will only be called in skills that require a best/worst tool (i.e. Woodcutting and Mining), so it won't ever return false. :)

Coh3n

2010-10-06 13:35:04


// Mining.simba
{******************************************************************************}
{ function MSI_SetupMining(): Boolean; }
{ By: Coh3n }
{ Date: 06 October 2010 }
{ Description: Sets up the player for mining }
{******************************************************************************}
function MSI_SetupMining(): Boolean;
begin
Result := MSI_SetupWoodcutting(); // To avoid unnecessary repeated code
end;

// Woodcutting.simba
{******************************************************************************}
{ function MSI_SetupWoodcutting(): Boolean; }
{ By: Coh3n }
{ Date: 06 October 2010 }
{ Description: Sets up the player for woodcutting }
{******************************************************************************}
function MSI_SetupWoodcutting(): Boolean;
var
i, j, x, y: Integer;
tabs: TIntegerArray;
begin
// If it's already on the inventory, it will search there first
if (GetCurrentTab = TAB_INV) then
tabs := [TAB_INV, TAB_EQUIP]
else
tabs := [TAB_EQUIP, TAB_INV];

for i := 0 to 1 do
for j := MSI_BestTool downto MSI_WorstTool do // First search for the best tool
if (MSI_FindTool(j, tabs[i], x, y)) then
begin
if (tabs[i] = TAB_INV) then
MSI_Items[j].InvSlot := CoordsToItem(x, y); // Set tool's inventory slot

Result := True;
Break;
end;

with MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]] do // CurrentScript
if (not Result) then
if (not (BankType = NoBank)) then // If CurrentScript is a banking one
if (MSI_Locations[MSI_Players[CurrentPlayer].Location].AtBank) then // If player is at a bank
Result := MSI_WithdrawBestTool();

MSI_CloseHeader('MSI_SetupPlayer: ' + BoolToStr(Result));
end;
Not sure how I feel about the SetupMining function yet. I don't think I mind it, but what do you guys think?

Gu3st...

2010-10-06 13:41:07

I have no problems doing it that way, but I wouldn't mind having repeated code there either

Sir R. M8gic1an

2010-10-06 14:05:05

In practical terms I see nothing wrong with it as long as WC is included before mining. But it seems like bad practice? Especially as it's in two different files..

~RM

NCDS

2010-10-06 14:45:35

Mining and Woodcutting would be the only too wrapped like that, that I can think of off the top of my head, right?

If so, I don't see too much of a problem with it.

Coh3n

2010-10-06 20:30:13

From: Sir R. Magician
In practical terms I see nothing wrong with it as long as WC is included before mining. But it seems like bad practice? Especially as it's in two different files..

~RM

Yeah, I know that's what I don't like about it. I like it better than repeating code because then only one needs to be updated.

The function itself could be moved to Skills.simba and renamed, but it is only used for those two skills and I can't think of a decent name.

Gu3st...

2010-10-07 06:21:16

MSI_SetupWoodcuttingMining()?
People would use MSI_SetupWoodcutting or MSI_SetupMining if they wanted to setup woodcutting or mining, so it doesn't really matter what you call it imo

Coh3n

2010-10-07 17:43:16

From: Zyt3x
MSI_SetupWoodcuttingMining()?
People would use MSI_SetupWoodcutting or MSI_SetupMining if they wanted to setup woodcutting or mining, so it doesn't really matter what you call it imo

Yeah, I don't know. Lol, I'll keep working on the rest and worry about it later.

Coh3n

2010-10-07 19:28:18

Okay I've got all of the functions done and I've commited them as comments as I don't have the time right now to make the necessary core changes and test everything. I will within the next couple days though.

Few things to note:
  • The bug where player setup would click the stats tab multiple times will be fixed.
  • I've implemented the InvSlot attribute from TItem, so there will be no mistakes between items and tools when the time comes to drop and bank the materials (I still need to edit MSI_DropAll and MSI_Deposit so this will work).
  • MSI_SetupFishing is completely rewritten and is much, much better. It will now search for the tools for each object in the player array. If a tool isn't found, it's stored in a separate array so after looking for every tool for EACH object the script can withdraw all the tools at the same time.
  • Then, if all tools are found for their respective object, that object will be added to a temporary object array. The same is done for all objects. MSI_Players[CurrentPlayer].Objects[CurrentScript] is then reset with only the objects that have had their tools found. Probably sounds confusing, but it is A LOT better then what we currently have.
  • TScript.Tools will be gone, and TScript.PlayerSetup will be added.
I'm not sure if there's anything else. I'll update the post if there is. Here's the code. It hasn't been tested so of course there will be flaws; some may not even compile.

// Skills.simba
{******************************************************************************}
{ procedure MSI_SetSkillLevels(); }
{ By: Coh3n }
{ Date: 04 October 2010 }
{ Description: Gets the player's skill levels for each script }
{******************************************************************************}
procedure MSI_SetSkillLevels();
var
i, curLev: Integer;
begin
if (not LoggedIn) then
Exit;

MSI_AddHeader('MSI_GetSkillLevels');

with MSI_Players[CurrentPlayer] do
for i := 0 to High(Scripts) do
begin
curLev := GetSkillLevel(MSI_Scripts[i].Skill);

// Only sets if the level has increased
if (curLev <= MSI_Scripts[Scripts[i]].PlayerSkillLevel) then
Continue;

// Set the TScript & ProgressReportArray attribute
MSI_Scripts[Scripts[i]].PlayerSkillLevel := curLev;
ProgressReportArray[CurrentPlayer].ScriptInfo[i].PlayerSkillLevel := curLev;

with MSI_Scripts[Scripts[i]] do
MSI_Debug(Skill + ' Level: ' + IntToStr(PlayerSkillLevel));
end;

MSI_CloseHeader('MSI_GetSkillLevels: Exit');
end;

{******************************************************************************}
{ function MSI_BestTool: Integer; }
{ By: Coh3n }
{ Date: 05 October 2010 }
{ Description: Determines the best tool for the chosen skill. Keep in mind }
{ this may not be used for every skill }
{******************************************************************************}
function MSI_BestTool: Integer;
begin
if (not LoggedIn) then
Exit;

with MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]] do
begin
case (SkillConstant) of
SKILL_WOODCUTTING:
case (PlayerSkillLevel) of
REQ_DRAGON..REQ_MAX_LEVEL: Result := HATCHET_DRAGON;
REQ_RUNE..REQ_DRAGON : Result := HATCHET_RUNE;
REQ_ADAMANT..REQ_RUNE : Result := HATCHET_ADAMANT;
REQ_MITHRIL..REQ_ADAMANT : Result := HATCHET_MITHRIL;
REQ_STEEL..REQ_MITHRIL : Result := HATCHET_STEEL;

else
Result := HATCHET_IRON;
end;

SKILL_MINING:
case (PlayerSkillLevel) of
REQ_DRAGON..REQ_MAX_LEVEL: Result := PICKAXE_DRAGON;
REQ_RUNE..REQ_DRAGON : Result := PICKAXE_RUNE;
REQ_ADAMANT..REQ_RUNE : Result := PICKAXE_ADAMANT;
REQ_MITHRIL..REQ_ADAMANT : Result := PICKAXE_MITHRIL;
REQ_STEEL..REQ_MITHRIL : Result := PICKAXE_STEEL;

else
Result := PICKAXE_IRON;
end;

else
MSI_SubDebug('MSI_BestTool: Invalid skill!');
end;

MSI_Debug('Best tool for ' + Skill + ' is '+ MSI_Items[Result].Name);
end;
end;

{******************************************************************************}
{ function MSI_WorstTool: Integer; }
{ By: Coh3n }
{ Date: 05 October 2010 }
{ Description: Determines the worst tool for the job at hand. }
{******************************************************************************}
function MSI_WorstTool: Integer;
begin
if (not LoggedIn) then
Exit;

with MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]] do
case skill of
SKILL_WOODCUTTING:
Result := HATCHET_BRONZE;

SKILL_MINING:
Result := PICKAXE_BRONZE;

else
MSI_SubDebug('MSI_WorstTool: Invalid skill!');
end;
end;

// Debug.simba
{******************************************************************************}
{ procedure MSI_GetReportInfo; }
{ By: Coh3n & Shuttleu }
{ Date: 04 October 2010 }
{ Description: Gets the necessary proggy info that isn't automatically reset }
{ during runtime }
{******************************************************************************}
procedure MSI_GetReportInfo;
var
curLev, i: Integer;
script: TScript;
begin
for i := 0 to High(MSI_Players) do
with ProgressReportArray[i] do
begin
if (i = CurrentPlayer) then
MSI_SetSkillLevels();

MSI_Players[i].Active := Players[i].Active;
PlayerLoc := MSI_Players[i].Location;
PlayerStatus := MSI_Players[i].Active;
end;
end;

// Mainloop.simba
{******************************************************************************}
{ function MSI_SetupPlayer: Boolean; }
{ By: Coh3n }
{ Date: 05 October 2010 }
{ Description: Sets up the player for autoing }
{******************************************************************************}
function MSI_SetupPlayer: Boolean;
begin
MSI_AddHeader('MSI_SetupPlayer');

if (not LoggedIn) then
begin
MSI_Debug('Player is not logged in');
if (not (WaitFunc(@LoginPlayer, 100, 5000))) then
begin
MSI_CloseHeader('MSI_SetupPlayer: ' + BoolToStr(Result));
Exit;
end;
end;

// Add logins to stats
Inc(Stats_CustomVars[STATS_LOGINS]);
MSI_SendStats;

// Standard setup procedures
MSI_FindRandoms;
SetAngle(True);
RunEnergy(20);

// Setup the player
MSI_SetSkillLevels();
with MSI_Players[CurrentPlayer] do
Result := MSI_Scripts[Scripts[CurrentScript]].SetupPlayer();

MSI_CloseHeader('MSI_SetupPlayer: ' + BoolToStr(Result));
end;

// Fishing.simba
{******************************************************************************}
{ function MSI_SetupFishing(): Boolean; }
{ By: Coh3n }
{ Date: 06 October 2010 }
{ Description: Sets up the player for fishing }
{******************************************************************************}
function MSI_SetupFishing(): Boolean;
var
i, j, t, x, y: Integer;
tools, newObjs: TIntegerArray;
toWithdraw: array of TIntegerArray;
objReady: TBooleanArray;
curScript: TScript;
begin
MSI_AddHeader('MSI_SetupFishing');

with MSI_Players[CurrentPlayer] do
begin
SetLength(objReady, Length(Objects[CurrentScript]));
SetLength(toWithdraw, Length(Objects[CurrentScript]));
curScript := MSI_Scripts[Scripts[CurrentScript]];

// Loops through the player objects checking for the required tools for each
for i := 0 to High(Objects[CurrentScript]) do
begin
tools := MSI_FishingTools(Objects[CurrentScript][i]); // Gets the required fishing tools for the fishing spot
t := 0;

for j := 0 to High(tools) do
if (MSI_FindTool(tools[j], TAB_INV, x, y)) then
MSI_Items[j].InvSlot := CoordsToItem(x, y) // Set tool's inventory slot
else begin
SetLength(toWithdraw[i], t);
toWithdraw[i][t] := tools[j]; // Adds to the array if the tool isn't found
Inc(t);
end;
end;

// In a separate loop so it only opens the bank once
for i := 0 to High(Objects[CurrentScript]) do
if (Length(toWithdraw[i]) <= 0) then // If all tools are found
objReady := True
else // If 1+ tools aren't found
if (MSI_OpenBank(curScript.WhichBank, Pin)) then
objReady := MSI_Withdraw(toWithDraw[i], []);

t := 0;
for i := 0 to High(objReady) do
if (objReady[i]) then
begin
newObjs[t] := Objects[CurrentScript][i];
Inc(t);
end else
MSI_Debug(MSI_Objects[Objects[CurrentScript][i]].Name + ': Required tools not found');

// Resets the objects so if the tools aren't found it will still fish in the spots for which the tools were found
Objects[CurrentScript] := newObjs;
Result := (Length(Objects[CurrentScript]) > 0);
end;

MSI_CloseHeader('MSI_SetupFishing: ' + BoolToStr(Result));
end;

{******************************************************************************}
{ function MSI_FishingTools(Obj: Integer): TIntegerArray; }
{ By: 3Garrett3 }
{ Date: 07 Octovber 2010 }
{ Description: Figures out which tool the script needs to use }
{******************************************************************************}
function MSI_FishingTools(Obj: Integer): TIntegerArray;
begin
case (Obj) of
FISHSPOT_NET:
Result := [FISH_SMALLNET];

FISHSPOT_BAIT:
Result := [FISH_ROD_BAIT, FISH_BAIT];

FISHSPOT_LURE:
Result := [FISH_ROD_FLY, MISC_FEATHER];

FISHSPOT_CAGE:
Result := [FISH_CAGE];

FISHSPOT_HARPOON:
Result := [FISH_HARPOON];

else
MSI_Debug('Invalid Fishing Spot Argument');
end;
end;

// Mining.simba
{******************************************************************************}
{ function MSI_SetupMining(): Boolean; }
{ By: Coh3n }
{ Date: 06 October 2010 }
{ Description: Sets up the player for mining }
{******************************************************************************}
function MSI_SetupMining(): Boolean;
begin
Result := MSI_SetupWoodcutting(); // To avoid unnecessary repeated code
end;

// Woodcutting.simba
{******************************************************************************}
{ function MSI_SetupWoodcutting(): Boolean; }
{ By: Coh3n }
{ Date: 06 October 2010 }
{ Description: Sets up the player for woodcutting }
{******************************************************************************}
function MSI_SetupWoodcutting(): Boolean;
var
i, j, x, y: Integer;
tabs: TIntegerArray;
begin
// If it's already on the inventory, it will search there first
if (GetCurrentTab = TAB_INV) then
tabs := [TAB_INV, TAB_EQUIP]
else
tabs := [TAB_EQUIP, TAB_INV];

for i := 0 to 1 do
for j := MSI_BestTool downto MSI_WorstTool do // First search for the best tool
if (MSI_FindTool(j, tabs[i], x, y)) then
begin
if (tabs[i] = TAB_INV) then
MSI_Items[j].InvSlot := CoordsToItem(x, y); // Set tool's inventory slot

Result := True;
Break;
end;

with MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]] do // CurrentScript
if (not Result) then
if (not (BankType = NoBank)) then // If CurrentScript is a banking one
if (MSI_Locations[MSI_Players[CurrentPlayer].Location].AtBank) then // If player is at a bank
Result := MSI_WithdrawBestTool();

MSI_CloseHeader('MSI_SetupPlayer: ' + BoolToStr(Result));
end;

// Banking.simba
{******************************************************************************}
{ function MSI_WithdrawBestTool(): Boolean; }
{ By: Coh3n }
{ Date: 06 October 2010 }
{ Description: Withdraws the best tool for the current script }
{******************************************************************************}
function MSI_WithdrawBestTool(): Boolean;
begin
with MSI_Scripts[MSI_Players[CurrentPlayer].Scripts[CurrentScript]] do
if (MSI_OpenBank(WhichBank, MSI_Players[CurrentPlayer].Pin)) then
begin
for i := MSI_BestTool downto MSI_WorstTool do
if (MSI_Withdraw([i], [1])) then
begin
Result := True;
Break;
end;

// Equip tool if possible

if (not Result) then
begin
CloseBank;
MSI_Debug('Couldn''t withdraw best tool');
end;

end else
MSI_Debug('Unable to open ' + MSI_Objects[WhichBank].Name);
end;
What do you guys think? :)

Coh3n

2010-10-08 17:13:42

I've moved this to public to set everyone know. Lots of bugs have been fixed with this update plus a lot of improvements (not noticeable to the users) to how fishing is setup. Se the above post for part of the list.
  • Fixed a bug with the Dragon Pickaxe.
  • Fixed trout and salmon DTMs.
  • Fixed the issue with depositing feathers.
  • Added relocating to Barbarian Village fisher. It will now fish at both locations.
  • Some people had their progress reports say the players were true when they weren't. I've added something to hopefully fix this.
  • There have been A LOT of changes, including rewriting and changing location of some functions. I encourage (especially SLs) to look at the diff file after updating.
I think that's it. :)