Code:
mob/Tester
Login() ..()
client.Load()
src.Build_Icons() src.Build_Overlays()
if(world.SetMedal("Tester Medal", src)) src << "You've earned the \"Tester Medal\"!"
client/Del() world.ClearMedal("Tester Medal", src)
Save()
..()
var/list/Char_Icons = list("Tester" = 'Tester Mob.dmi')
mob var/char_icon = "Tester" var/hairSty = "bald" var/hairCol = "#000000"
proc/Build_Icons() var/icon/base = new(Char_Icons[char_icon]) icon = base
proc/Build_Overlays() overlays.Cut() var/obj/olay = new for(var/obj/O in equipment) if(O.has_overlay) olay.icon = O.icon olay.icon_state = "equipped" olay.layer = (O.equipment_layer || MOB_LAYER+1) overlays += olay
Read(savefile/F) ..()
Build_Icons() Build_Overlays()
var/turf/T = locate(F["x"], F["y"], F["z"]) if(T) loc = T
Write(savefile/F) ..()
F["x"] << x F["y"] << y F["z"] << z F["icon"] << null F["underlays"] << null F["overlays"] << null
client proc/Load() var/firstletter=copytext(ckey, 1, 2) if(fexists("Saves/[firstletter]/[ckey].sav")) var/savefile/F = new("Saves/[firstletter]/[ckey].sav") F["mob"] >> mob
proc/Save() var/firstletter=copytext(ckey, 1, 2) var/savefile/F = new("Saves/[firstletter]/[ckey].sav") F["mob"] << mob
|
Problem description:
When I login it doesn't load back where I was last standing when I logged out.
Read(savefile/F)
//Default Behavior
..()
//Build user icon and overlays
Build_Icons()
Build_Overlays()
//Relocate the user to his last saved position
var/turf/T = locate(F["x"], F["y"], F["z"])
if(T)
loc = T
Don't do this turf locating stuff here. Just have it load the saved x,y,z variables to the player.
If they are at an invalid location such as something outside of the world map's maxx, maxy, or maxz then their location is set to null.
You can create a check after this that can determine if they are at a null location, and move them accordingly, such as to locate(1,1,1)
Try this:
var/last_xvar/last_y
var/last_z
F["x"]>>last_x
F["y"]>>last_y
F["z"]>>last_z
loc=locate(last_x,last_y,last_z)