I use file objects, I like to share it because when it loads the file it parses all the variables and all the values to the client.
GameConnection::RPG_SaveProfile(%this) - First field is the variable, no spaces or special ascii chars. Second field is the value.
GameConnection::RPG_LoadProfile(%this) - Parses the file.
Ignore the party stuff, lol
function GameConnection::RPG_SaveProfile(%this)
{
if(!isRPG(%this))
return;
%path = $RPG::FilePaths::Profiles @ %this.getBLID() @ ".RPGBLP"; //Funny save file name
if(!isFile(%path))
return -1;
if(!strLen(%this.RPGData["RPGPN"]))
%this.RPGData["RPGPN"] = %this.getBLID() @ getRandom(1000,10000);
%file = new FileObject();
%file.openForWrite(%path);
%file.writeLine("RPGPN" TAB %this.RPGData["RPGPN"]);
%file.writeLine("health" TAB %this.RPGData["health"]);
%file.writeLine("maxHealth" TAB %this.RPGData["maxHealth"]);
%file.writeLine("mana" TAB %this.RPGData["mana"]);
%file.writeLine("maxMana" TAB %this.RPGData["maxMana"]);
%file.writeLine("gold" TAB %this.RPGData["gold"]);
%file.writeLine("exp" TAB %this.RPGData["exp"]);
%file.writeLine("maxExp" TAB %this.RPGData["maxExp"]);
%file.writeLine("level" TAB %this.RPGData["level"]);
%file.writeLine("money" TAB %this.RPGData["money"]);
%file.writeLine("DoNotShow" TAB %this.RPGData["DoNotShow"]);
%file.writeLine("canSeeHP" TAB %this.RPGData["canSeeHP"]);
%file.writeLine("BGColor" TAB %this.RPGData["BGColor"]);
%file.writeLine("maxGold" TAB %this.RPGData["maxGold"]);
%file.writeLine("RPG_SpeedFactor" TAB %this.RPGData["RPG_SpeedFactor"]);
%file.writeLine("Skill_StrengthMultiplier" TAB %this.RPGData["Skill_StrengthMultiplier"]);
if(%this.RPGData["party"] != 0 || %this.RPGData["party"] !$= "") //If the party exists, let's convert it to it's bl_id
{
%oldParty = %this.RPGData["party"];
%this.RPGData["party"] = %this.getParty().bl_id;
}
%file.writeLine("party" TAB %this.RPGData["party"]);
if(%oldParty !$= "")
%this.RPGData["party"] = %oldParty;
echo("\'" @ %this.name @ "\' profile has been saved.");
%file.close();
%file.delete();
}
function GameConnection::RPG_LoadProfile(%this)
{
if(!isRPG(%this))
return;
%path = $RPG::FilePaths::Profiles @ %this.getBLID() @ ".RPGBLP";
if(!isFile(%path))
{
%this.RPG_NewProfile();
return;
}
%file = new FileObject();
%file.openForRead(%path);
echo("\'" @ %this.name @ "\' profile has been loaded.");
while(!%file.isEOF())
{
%line = %file.readLine();
%fLine = strReplace(getField(%line,0)," ","_");
%this.RPGData[getWord(getField(%fLine,0),0)] = getField(%line,1);
RPG_Debug("GameConnection::RPG_LoadProfile","Loaded variable string > \c4" @ getField(%line,0) SPC getField(%line,1));
if(%fLine $= "party")
{
if(isObject(%party = ("RPGParty_") @ getField(%line,1)))
%party.setOnline(%this); //Aye look they are online :D
RPG_Debug("GameConnection::RPG_LoadProfile","Loaded party string > \c4" @ getField(%line,0) SPC getField(%line,1));
}
}
%file.close();
%file.delete();
}[/tt]