mob
Login()
..();
if(!usr.client.loggedIn)
{
usr.client.loggedIn = TRUE;
LoadMob(usr);
usr.UpdateVerbs();
usr.ReloadCommunicationObjs()
usr.UpdateInventory()
}
proc
SaveMob(var/mob/m)
{
if(m)
{
var/savefile/Player = new("Savefiles/[m.ckey].sav");
m.Write(Player);
}
}
LoadMob(var/mob/m)
{
if(fexists("Savefiles/[m.ckey].sav"))
{
var/savefile/Player = new("Savefiles/[m.ckey].sav");
m.Read(Player);
m.AddToPlayersList();
m.LinkToPoster();
AdminLogin(m);
}
else
{
m << "File for [m.ckey] not found.";
NewMob(m);
AdminLogin(m);
}
}
Write(var/savefile/Player)
{
if(fexists(Player))
{
fdel(Player);
}
Player["x"] << src.x;
Player["y"] << src.y;
Player["z"] << src.z;
..();
}
Read(var/savefile/Player)
{
var/x2,y2,z2;
Player["x"] >> x2;
Player["y"] >> y2;
Player["z"] >> z2;
src.Move(locate(x2, y2, z2));
..();
}
Problem description: Something is happening on the second load of a character. I can make one fine, and I can log out on it. When I log back in, all of its data is there. If I log out again, that's when the problem happens. Once I log back in, the character is at 1,1,1 (characters won't spawn at this location normally) with no overlays added with its name set to my key name. This problem only occurs for me when I am hosting the game in Dream Daemon.
Any suggestions?
Furthermore, you shouldn't be calling Read() and Write() directly, this can get goofy in some situations. Instead you should do something like this:
These methods call Read() and Write() respectively, but tend to be more reliable, especially by giving the data a save key ("player") to look at instead of just stuffing a mob inside of a file with no reference point.
Your problem with loading could be that you're being loaded into a new mob without properly cleaning things up, when saving and loading a whole mob like this the following is the most ideal means of loading the player:
This makes it possible to split your mob definitions up a bit, making life a wholllle lot easier, for instance you can use a default mob type of /mob/loading which will handle your player before they load their data, and /mob/player which will handle it after they've loaded. Making things like:
Possible, so you can handle events differently before and after a player is loaded up without having to do a bunch of checking to see where they are in the process.