ID:155131
 
client
proc
SaveMob(var/nomessage=1)
if(src.mob && src.mob.SaveSlot && !(src.mob.status2 & SAVETIMER))
var/mob/player/Q = src.mob
Q.oldx = Q.x
Q.oldy = Q.y
Q.oldz = Q.z
var/savefile/F = new("Players/[Q.Username].sav")
F.cd = "/[src.mob.SaveSlot]/"
F["mob"] << mob
if(!nomessage)
src.mob << "<b><font color=red>You have saved!</b></font>"
src.mob.status2 |= SAVETIMER
spawn(50)
src.mob.status2 &= ~SAVETIMER
return
LoadMob(var/slot,var/mob/OldMob)
if(slot)
var/mob/player/Q = src.mob
if(!fexists("Players/[Q.Username].sav"))
return
var/savefile/F = new("Players/[Q.Username].sav")
F.cd = "/[slot]/"
var/mob/player/L = new
L = F["mob"]
if(!L)
src << "<b>ERROR: Unable to create mob from save file. Corrupted?"
return
L.SaveSlot = slot
world<<"<font size=1><font color=yellow><B>Info:<font color = silver> [L] has logged on the server."
L.loc = locate(L.oldx,L.oldy,L.oldz)
if(L.oLoc)
L.loc = L.oLoc
L.oLoc = 0
L.Logged = 1
spawn()
while(OldMob)
del(OldMob)


This is my current save / load system. I'm trying to implement an in-game username system and everything works fine. The only problem is that saving the variables from src.mob also saves key and ckey, which means you disconnect if you log in a character with a key other than the one you originally created it with... which completely undermines the purpose of having an independent login system to begin with. How would I go about reworking this system to not include key or ckey? Any comments or suggestions are appreciated.
Lige wrote:
Save the mob after the client disconnects, then delete it.

I don't see what you mean. SaveProc() already runs at client/Del(). The problem isn't the save system itself, just the fact that ckey and key are saving, meaning the saves are key-specific.

Edit: Nevermind, I think I see what you're saying. But if you saved the mob, wouldn't it still save key and ckey?

Double Edit:
    Del()
if(src.mob && src.mob.Logged)
for(var/obj/BattleObject/MovingDamager/A in world)
if(A.Owner == src.mob)
del(A)
src.mob.status2 &= ~SAVETIMER
world << "<b><font color = yellow>Info:<font color = silver> [src.mob]([src]) has logged off!"
src.mob.Logout()
src.SaveMob()
..()
del(src.mob)


This is for client/Del(). Since I'm triggering Logout(), shouldn't that get rid of the mob's key and ckey variables? I'm still having the same issue regardless.