Finding a bot's spawn brick || Variable Saving System

Author Topic: Finding a bot's spawn brick || Variable Saving System  (Read 1066 times)

Hey guys, I'm making an RPG and I want certain bots to reward players more then others. I figured a way to do this was to refer to the bot's spawn brick's name, and if it is set to certain values it rewards more then normal. Although, I don't know how to refer to the spawn brick through %bot. Can you help me?
« Last Edit: April 25, 2015, 09:00:59 PM by Johnny Blockhead »

Using dump() on the bot shows that it is stored in .spawnBrick, which is the brick's ID. Use dump(). It's nice.

Thanks, it worked! I'll be sure to take a dump() next time.
I have this variable saving script, and it works dandy. If you leave and rejoin, your stuff is there. But it won't save if I reboot the server. I also can't find the .cs files that it appears to be saving. Any Ideas?
package SaveData
{
    function gameConnection::onClientLeaveGame(%client)
    {
        %saveObj = new ScriptObject(%this.getBLID() @ "_saveObj");
        %saveObj.name = %client.name;
        %saveObj.BLID = %client.BLID;
        %saveObj.class = %client.class;
        %saveObj.spell = %client.spell;
        %saveObj.lvl = %client.lvl;
        %saveObj.upg = %client.upg;
        %saveObj.EXP = %client.EXP;
        %saveObj.dmgMult = %client.dmgMult;
        %saveObj.spdMult = %client.spdMult;
        %saveObj.expMult = %client.expMult;
        parent::onClientLeaveGame(%client);
    }
    function gameConnection::onClientEnterGame(%client)
    {
        exec("config/players/" @ %client.BLID @ ".cs");
        %saveObj = (%this.BLID @ "_saveObj");
        %client.class = %saveObj.class; //Different variables needed for my mod.
        %client.spell = %saveObj.spell;
        %client.lvl = %saveObj.lvl;
        %client.EXP = %saveObj.EXP;
        %client.upg = %saveObj.upg;
        %client.dmgMult = %saveObj.dmgMult;
        %client.spdMult = %saveObj.spdMult;
        %client.expMult = %saveObj.expMult;
        %saveObj.delete();
        if(%client.spdMult == 0)
            correctValues(%client); //This is an actual function
        parent::onClientEnterGame(%client);
    }
};
activatePackage(SaveData);

But it won't save if I reboot the server. I also can't find the .cs files that it appears to be saving. Any Ideas?
That's because you're using a scriptObject and you're not creating any sort of files.
Script objects basically just store information and they die when the server dies.

I'd suggest either temporarily assigning the values you want to save to global variables and then using export("file/path.cs", %append); and then executing the file when they join and assigning the client's variables to the global variables.

Or you can use file objects and write the values in them manually and then parse the file manually when they join.

Also, you should check if the file exists before loading their data and don't use such a generic file path as config/players/BL_ID.cs. Use something more like config/server/myMod/BL_ID.cs.

Not to knock jes, but don't do that.

When the player disconnects, use this:
%saveObject.save("config/playerData/" @ %client.getBLID() @ ".cs");

When they connect use this:
exec("config/playerData/" @ %client.getBLID() @ ".cs");

That will load it from the file. You can even delete the object after saving / loading to save memory.

Or you can write your own database.

/shades

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

Code: (aScript_WorldRPG/server.cs) [Select]
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]