I made this script saving weather the client is muted, the pos of the player and all of the tools the player has. It saves and loads properly. My problem is giving the items to the player. This is the code.
$Gamemode::PlayerMaxTools=5;
function loadstuff(%client)
{
%file = new FileObject();
%filename = "config/server/MedievalRPG/stats/" @ %client.bl_id @ ".txt";
%file.openForRead(%filename);
%client.player.position = %file.readLine();
$RPG::Variables[%client.bl_id @ "_Mute"] = %file.readLine();
$RPG::Variables[%client.bl_id @ "_MuteReason"] = %file.readLine();
%client.player.cleartools();
addItem(%client.player,%file.readLine());
addItem(%client.player,%file.readLine());
addItem(%client.player,%file.readLine());
addItem(%client.player,%file.readLine());
addItem(%client.player,%file.readLine());
}
function addItem(%player,%image)
{
for(%i = 0; %i < $Gamemode::PlayerMaxTools; %i++)
{
%tool = %player.tool[%i];
if(%tool == 0)
{
%player.tool[%i] = %image;
%player.weaponCount++;
messageClient(%client,'MsgItemPickup','',%i,%image);
break;
}
}
}
package loadOnPlayerSpawn
{
function GameConnection::onPlayerSpawn(%client)
{
Parent::onPlayerSpawn(%client);
if(isFile("config/server/MedievalRPG/stats/" @ %client.bl_id @ ".txt"))
{
loadstuff(%client);
} else { warn("Failed to find stats for " @ %client.Name); }
}
};
activatePackage(loadOnPlayerSpawn);
package onplayerenter {
function GameConnection::onClientEnterGame(%client)
{
Parent::onClientEnterGame(%client);
if(isFile("config/server/MedievalRPG/stats/" @ %client.bl_id @ ".txt"))
{
loadstuff(%client);
} else { warn("Failed to find stats for " @ %client.Name); }
}
};
activatePackage(onplayerenter);
function saveStats(%client) {
%file = new FileObject();
%filename = "config/server/MedievalRPG/stats/" @ %client.bl_id @ ".txt";
%file.openForWrite(%filename);
%file.writeLine(%client.player.position);
%file.writeLine($RPG::Variables[%client.bl_id @ "_Mute"]);
%file.writeLine($RPG::Variables[%client.bl_id @ "_MuteReason"]);
%file.writeLine(%client.player.tool[0]);
%file.writeLine(%client.player.tool[1]);
%file.writeLine(%client.player.tool[2]);
%file.writeLine(%client.player.tool[3]);
%file.writeLine(%client.player.tool[4]);
%file.close();
%file.delete();
}
function saveAllClientStats()
{
%count = clientGroup.getCount();
for(%i = 0; %i < %count; %i++)
{
%cl = clientGroup.getObject(%i);
saveStats(%cl);
}
}
The tools clear and I hear the tool-pickup sound but the tool list won't show up and
talk(fcbn("Pie Crust").player.tool[0]);
returns 0.