Here you'll find two processes to load and save players.
savePlayer()
Always creates a savefile or writes to the existing one
loadPlayer()
Returns 0 if the player couldn't be loaded
Returns 1 if the player was loaded
You'll also find that I've edited Read() and Write() to save the location of the player as this is not done automatically.
Worked Example
This will automatically save players when they log out and load them when they log in.
mob
// Attempts to load the player. If it can't, spawns them like normal. Replace ..() with what you
// would like to happen when there's no save file to load.
Login()
if(!loadPlayer())
..()
// Saves the player to a file such as "Savefiles/alexpeterson.sav"
Logout()
savePlayer()
del src
// The processes themselves you'll want to use
proc
loadPlayer()
if(fexists("Savefiles/[ckey].sav"))
var/savefile/F = new("Savefiles/[ckey].sav")
Read(F)
return 1
else
return 0
savePlayer()
var/savefile/F = new("Savefiles/[ckey].sav")
Write(F)
return 1
// Here's an edit to Read and Save allowing them to save the player's coordinate variables.
Read(var/savefile/F)
..()
Move(locate(F["x"],F["y"],F["z"]))
Write(var/savefile/F)
..()
F["x"] << x
F["y"] << y
F["z"] << z
Extra Note #1
If you have a mob variable you don't want this to save then define it in the format:
mob
var/tmp/dontSaveThis = 20
Extra Note #2
You may want to instead place loading and saving under: client/new() and client/Del() if the worked example isn't quite what you wanted.
:) :)