Bobzilla69
2011-01-14 15:48:01
i made a Character Skill Level grabber for MSI.
i PMed Coh3n about it and he said its good and to post it here so that him or someone else when they get time can add it into MSI Extras.
So basically what i have done is made it so that after a character finished there Loads/Time or the player is unset it will call my include and save all of the current players skill levels to a file.
The file will be stored in MSI\MSI\Extras\Accounts and will have the character name as the file name. i.e. MSI\MSI\Extras\Accounts\Bobzilla.txt
Here is the Main Script to be added into the Extras Folder.
CharacterStats.Simba
{==============================================================================\
| MSI Group Scripting Include |
| CharacterStats.Simba |
|==============================================================================|
| For Storing Player Skill levels after Time/Loads are reached |
| |
| * procedure CheckFile; * by Bobzilla69 |
| * procedure WriteFile(); * by Bobzilla69 |
| * procedure GetData; * by Bobzilla69 |
| * procedure WriteData; * by Bobzilla69 |
| * procedure StoreCharacterLevels; * by Bobzilla69 |
\_____________________________________________________________________________}
var
Accounts:Integer;
oldInfo:String;
Skills:TStringArray;
Const
Path = IncludePath + 'MSI\MSI\Extras\Accounts\';
StartNew = True; //keeps adding to end of file, True to overwrite anythign in file
{******************************************************************************}
{ procedure CheckFile; }
{ By: Bobzilla69 }
{ Date: 13 January 2011 }
{ Description: Check if File exists if it doent creates file. }
{ Also handles if file will be added to or rewritten }
{******************************************************************************}
Procedure Bobzilla_CheckFile;
begin
if FileExists(Path + Players[CurrentPlayer].Name +'.txt') then
begin
//Writeln('File all ready created');
Accounts:= OpenFile(Path + Players[CurrentPlayer].Name +'.txt' , False);
if (not StartNew) then ReadFileString(Accounts, oldInfo, FileSize(Accounts));
CloseFile(Accounts);
end else
begin
//WriteLn('File not Found, Creating new file')
Accounts := CreateFile(Path + Players[CurrentPlayer].Name +'.txt');
CloseFile(Accounts);
end;
end;
{******************************************************************************}
{ procedure WriteFile(New, Old:string); }
{ By: Bobzilla69 }
{ Date: 13 January 2011 }
{ Description: Writes Character data to the file. }
{ New is new data to be added to file. }
{ Old is data that was in file to be re writen }
{******************************************************************************}
Procedure Bobzilla_WriteFile(New, Old:string);
begin
Accounts := RewriteFile(Path + Players[CurrentPlayer].Name +'.txt', False);
WriteFileString(Accounts, Old + #13 + #10 + New);
CloseFile(Accounts);
end;
{******************************************************************************}
{ procedure GetData; }
{ By: Bobzilla69 }
{ Date: 13 January 2011 }
{ Description: Using reflection gets all character skill levels }
{ and stores it to a Array for that character }
{******************************************************************************}
Procedure Bobzilla_GetData;
begin
Players[CurrentPlayer].Arrays[1]:= [
R_GetSkillLevel(SKILL_ATTACK), R_GetSkillLevel(SKILL_DEFENCE), R_GetSkillLevel(SKILL_STRENGTH),
R_GetSkillLevel(SKILL_HITPOINTS), R_GetSkillLevel(SKILL_RANGE), R_GetSkillLevel(SKILL_PRAYER),
R_GetSkillLevel(SKILL_MAGIC), R_GetSkillLevel(SKILL_COOKING), R_GetSkillLevel(SKILL_WOODCUTTING),
R_GetSkillLevel(SKILL_FLETCHING), R_GetSkillLevel(SKILL_FISHING), R_GetSkillLevel(SKILL_FIREMAKING),
R_GetSkillLevel(SKILL_CRAFTING), R_GetSkillLevel(SKILL_SMITHING), R_GetSkillLevel(SKILL_MINING),
R_GetSkillLevel(SKILL_HERBLORE), R_GetSkillLevel(SKILL_AGILITY), R_GetSkillLevel(SKILL_THIEVING),
R_GetSkillLevel(SKILL_SLAYER), R_GetSkillLevel(SKILL_FARMING), R_GetSkillLevel(SKILL_RUNECRAFTING),
R_GetSkillLevel(SKILL_HUNTER), R_GetSkillLevel(SKILL_CONSTRUCTION), R_GetSkillLevel(SKILL_SUMMONING),
R_GetSkillLevel(SKILL_DUNGEONEERING)]
end;
{******************************************************************************}
{ procedure WriteData; }
{ By: Bobzilla69 }
{ Date: 13 January 2011 }
{ Description: Handles extracting data from array and sending to WriteFile; }
{******************************************************************************}
Procedure Bobzilla_WriteData;
var
B:integer;
newInfo:String;
begin
Skills:= ['Attack Skill :', 'Defence Skill :', 'Strength Skill :', 'Hitpoints Skill :', 'Range Skill :', 'Prayer Skill :', 'Magic Skill :', 'Cooking Skill :', 'Woodcutting Skill :', 'Fletching Skill :', 'Fishing Skill :', 'Firemaking Skill :', 'Crafting Skill :', 'Smithing Skill :', 'Mining Skill :', 'Hreblore Skill :', 'Agility Skill :', 'Thieving Skill :', 'Slayer Skill :', 'Farming Skill :', 'Runercrafting Skill :', 'Hunter Skill :', 'Conctruction Skill :', 'Summining Skill :', 'Dungeoneering Skill :'];
newInfo:= newInfo + Players[CurrentPlayer].Name + ' Skill Levels are :'+#13+#10;
for B:=0 to high(Players[CurrentPlayer].Arrays[1]) do
begin
newInfo := newInfo + ' '+Skills[B] + IntToStr(Players[CurrentPlayer].Arrays[1][B])+#13+#10;
end;
newInfo := newInfo + #13 + #10;
WriteFile(newInfo, oldInfo);
end;
{******************************************************************************}
{ procedure StoreCharacterLevels; }
{ By: Bobzilla69 }
{ Date: 13 January 2011 }
{ Description: Simply calles all procedures in order }
{ means only one lines is called in MSI }
{******************************************************************************}
Procedure Bobzilla_StoreCharacterLevels;
begin
CheckFile;
GetData;
WriteData;
end;Changes to Setup.Simba
//Extras
{$include_once MSI/MSI/Core/Extras.simba}
{$include_once MSI/MSI/Extras/WorldWalker_cstrike.simba}
{$include_once MSI/MSI/Extras/CharacterStats.simba} Changed to MainLoop.simba
{******************************************************************************}
{ procedure MSI_UnsetPlayer(func, reason: String; setReason: Boolean); }
{ By: RM and Coh3n }
{ Date: 03 July 2010 }
{ Description: Sets the player to false if something fails }
{******************************************************************************}
procedure MSI_UnsetPlayer(reason: String; setReason: Boolean);
begin
MSI_AddHeader('MSI_UnsetPlayer');
if (BankScreen) then
CloseBank;
MSI_Debug(reason);
MSI_Players[CurrentPlayer].Active := False;
Players[CurrentPlayer].Active := False;
if (setReason) then
MSI_Players[CurrentPlayer].ReportInfo.FalseReason := reason;
if (Players[CurrentPlayer].Rand <> '') then
MSI_Players[CurrentPlayer].ReportInfo.FalseReason := 'In random: '+Players[CurrentPlayer].Rand;
Bobzilla_StoreCharacterLevels;
MSI_ProgressReport;
NextPlayer(False);
stats_IncVariable('Total Logins', 1);
MSI_CloseHeader('MSI_ReflectionWalk: Finished');
end;
{******************************************************************************}
{ function MSI_CheckLoads(...): Boolean; }
{ By: Coh3n }
{ Date: 03 December 2010 }
{ Description: Returns true if it's time to break or set player inactive }
{******************************************************************************}
function MSI_CheckLoads(TempLoads: Integer; var Reason: string; var TakeBreak: Boolean): Boolean;
var
_avg: Integer;
begin
with MSI_Players[CurrentPlayer] do
begin
// Handle finishing total loads
if (TotalLoads > 0) then
begin
MSI_SubDebug('Total loads done: '+IntToStr(ReportInfo.LoadsDone));
_avg := Round(TotalLoads * RANDOM_TIME_PERCENT);
if (ReportInfo.LoadsDone >= (TotalLoads + RandomRange(-_avg, _avg))) then
begin
MSI_SubDebug('Finished total loads');
Reason := 'Finished total loads!';
Result := True;
Exit;
Bobzilla_StoreCharacterLevels;
end;
end;
// Breaking via loads
if (BreakLoads > 0) then
begin
MSI_SubDebug('Temp loads done: '+IntToStr(TempLoads));
_avg := Round(BreakLoads * RANDOM_TIME_PERCENT);
if (TempLoads >= (BreakLoads + RandomRange(-_avg, _avg))) then
begin
MSI_SubDebug('Finished loads before breaking');
TakeBreak := True;
Result := True;
Exit;
end;
end;
end;
end;
{******************************************************************************}
{ function MSI_CheckLoads(...): Boolean; }
{ By: Coh3n }
{ Date: 03 December 2010 }
{ Description: Returns true if it's time to break or set player inactive }
{******************************************************************************}
function MSI_CheckTime(TempTime: Integer; var Reason: string; var TakeBreak: Boolean): Boolean;
var
_avg: Integer;
begin
with MSI_Players[CurrentPlayer] do
begin
// Completed total time (common for all skills)
if (TotalTime > 0) then
begin
MSI_SubDebug('Total playing time: '+IntToStr(Round(ReportInfo.PlayerTime / 60000)));
MSI_SubDebug('Max playing time: '+IntToStr(TotalTime));
Bobzilla_StoreCharacterLevels;
_avg := Round(TotalTime * RANDOM_TIME_PERCENT);
if (Round(ReportInfo.PlayerTime / 60000) >= (TotalTime + RandomRange(-_avg, _avg))) then
begin
MSI_SubDebug('Finished total time');
Reason := 'Finished total time!';
Result := True;
Exit;
end;
end;
// Handle breaking via time (common for all skills)
if (BreakTime > 0) then
begin
MSI_SubDebug('Temp playing time: '+IntToStr(TempTime));
_avg := Round(BreakTime * RANDOM_TIME_PERCENT);
if (Round(TempTime / 60000) >= (BreakTime + RandomRange(-_avg, _avg))) then
begin
MSI_SubDebug('Finished total time before breaking');
TakeBreak := True;
Result := True;
Exit;
end;
end;
end;
end;