ID:2134510
 
Code:

mob
var
OldEye = null
mob
Login() if(src.InGame == 0)
src.invisibility = 1
src.loc = locate(2,2,2)

src.OldEye = src.client.eye
for(var/obj/Action/Camera/A in world)
src.client.perspective=EYE_PERSPECTIVE
src.client.eye=A

var/obj/O = new
O.screen_loc = "CENTER,CENTER+3"

O.name = "In"
O.layer = 201
O.maptext_x = -256
O.maptext_width = 512
O.maptext_height = 128
O.maptext = "<font size = 5><font face = Gigi><font color = #8B0000><center>D<font color = #B22222>anger <font color = #8B0000>Z<font color = #B22222>one"

var/obj/Hud/Login/NewGame/O2 = new
O2.screen_loc = "CENTER-3,CENTER"
O2.name = "In"
O2.layer = 201
O2.maptext_x = -256
O2.maptext_width = 512
O2.maptext_height = 128
O2.overlays += icon('Misc.dmi',"C")
O2.maptext = "<big><font face = Gigi><font color = #8B0000><center> New Game"

var/obj/Hud/Login/LoadGame/O3 = new
O3.screen_loc = "CENTER+3,CENTER"
O3.name = "In"
O3.layer = 201
O3.maptext_x = -256
O3.maptext_width = 512
O3.maptext_height = 128
O3.overlays += icon('Misc.dmi',"C")
O3.maptext = "<big><font face = Gigi><font color = #8B0000><center> Load Game"

src.client.screen.Add(O,O2,O3)

if(src.key == "OttavioVaz")
src.verbs += typesof(/mob/Admin/verb/)

src<<browse(MsgLogin,"window=MsgLogin;size=500x500")
world << "<H4><font color = #C7F464>(System) <font color = #FA6900>[src.key] entered on the game.<br>"


mob/var/tmp/InGame = 0 

mob
proc
Save_Character() if(InGame == 1) // Check if player is in game
var/savefile/F=new("Player/[src.ckey].sav") // Create a new savefile

// Store the cords
F["X"] << src.x
F["Y"] << src.y
F["Z"] << src.z

Write(F) // Save all the vars
mob
proc
Load_Character() if(InGame == 0) // Check if player is in login screen
if(fexists("Player/[src.key].sav")) // Check if exist a savefile
var/savefile/F=new("Player/[src.ckey].sav") // Load the savefile

// Transfer the cords to the vars
var/X
var/Y
var/Z
F["X"] >> X
F["Y"] >> Y
F["Z"] >> Z

Read(F) // Load all the stored vars

src.loc = locate(X,Y,Z) // Use the vars to teleport the character to the logout location


Problem description:
The problems is in the Load_Character() proc, by some reason the game logout and login back to the initial screen every time i call the Load_Character() proc, i just want to load the savefiles and then normally go to the game but i am really bad using files... yep i am newbie, can someone help me ?

Sorry for my bad English
This is how I handle it
world
mob = /mob/logging
Del()
for(var/mob/player/p in world)
del p
mob
var
Youricon = 'youricon.dmi'
mob
logging
Login()
if(fexists("saves/[copytext(src.ckey,1,2)]/[src.ckey].sav")) // if we have savefile


var/savefile/F = new/savefile("saves/[copytext(usr.ckey,1,2)]/[usr.ckey].sav") // load it and login as mob/player
var/mob/player/p = null
F >> p
p.key = src.client.key

del src
else // else create new character
var/mob/new_mob
new_mob = new /mob/player()
new_mob.loc=locate(1,1,2)
new_mob.icon=src.Youricon
src.client.mob = new_mob


return 1
Move()

player

Login()


spawn(10)
src.save()


//set up your icons, icon_state, screen objects, screen locs, underlays, and overlays here.
src.icon = 'youricon.dmi'
src.icon_state= "youriconstate"
return ..()
Del()
src.save()
return ..()
proc
save()
var/savefile/F = new/savefile("saves/[copytext(src.ckey,1,2)]/[src.ckey].sav")
F << src
mob
Write(savefile/F) // Write proc
..()
F["last_x"] << x // saves your x location on the map
F["last_y"] << y // saves your y location on the map
F["last_z"] << z // saves your z location on the map
Read(savefile/F)
..()
var/last_x // var defined
var/last_y
var/last_z
F["last_x"] >> last_x // reads your x location on the map
F["last_y"] >> last_y // reads your y location on the map
F["last_z"] >> last_z // reads your z position on the map
src.loc = locate(last_x, last_y, last_z) // locates you to your last map location<dm>
T-Thanks Senpai, i look your example and then made a new template to my character creation system, a basically resumed my code in this:

mob/var/tmp/NoJogo = 0

world
mob = /mob/Logando
Del()
for(var/mob/Jogador/p in world)
del p
mob/Logando
proc
Carregar_Personagem() if(NoJogo == 0)
if(fexists("Player/[src.key].sav"))
var/savefile/F = new/savefile("Player/[src.ckey].sav")
var/mob/Jogador/p = null
F >> p
p.key = usr.client.key

del src

mob/Jogador
proc
Salvar_Personagem() if(NoJogo == 1)
var/savefile/F=new("Player/[src.ckey].sav")

F["X"] << src.x
F["Y"] << src.y
F["Z"] << src.z
Write(F)

mob
Logando
Login()
if(fexists("Player/[src.key].sav"))
src.Carregar_Personagem()
else
var/mob/new_mob
new_mob = new /mob/Jogador()
new_mob.loc=locate(15,15,1)
new_mob.icon=src.icon
src.client.mob = new_mob
return 1
..()
Jogador
Login()
return ..()
Del()
world << "<H4><font color = #C7F464>(Sistema) <font color = #FA6900>[src.key] saiu do jogo.<br>"
if(src.AgarradoPor != null) src.Agarrar()
src.overlays -= icon('Misc.dmi',"Z")
src.Salvar_Personagem()
..()


Problem solved =)
Phat T led you wrong in one thing: You should not be using usr in a proc. The correct value for his proc, and for yours, is src instead of usr.
I notice and then solved it... but now i got a new error:

runtime error: Cannot read null.key
proc name: Carregar Personagem (/mob/Logando/proc/Carregar_Personagem)
source file: Salvar.dm,95
usr: (src)
src: OttavioVaz (/mob/Logando)
src.loc: null
call stack:
OttavioVaz (/mob/Logando): Carregar Personagem()
OttavioVaz (/mob/Logando): Login()


mob/Logando
proc
Carregar_Personagem() if(NoJogo == 0)
if(fexists("Save/Player/[src.key].sav"))
var/savefile/F = new/savefile("Save/Player/[src.ckey].sav")

var/mob/Jogador/p = null
F >> p

p.key = src.client.key // >>>> src.client.key <<<< the error is here

world << "A:[p.x]-[p.y]"
world << "B:[p.XSalvo]-[p.YSalvo]"
del src


I dont know how to fix it...
src.client is null. It means this routine is being called when you don't have a client connected.
having the same problem for some reason players been logged out then logged back in on load
When a mob is saved, the mob's key is saved.

When the mob is loaded, the key is loaded.

Whenever a mob's key is set, it automatically connects to any online client with that key.

Whenever a mob connects to a client, Logout is called on the client's previous mob (if any), and Login is called on the new mob.

Although it's common to see people use Login for "when a player joins the world" behavior, that's not actually what Login is for. Instead, use client/New(). In client/New(), code before the ..() call occurs before the mob is initialized.

(I'd normally advise against so-called "side-effects in the constructor", but client.New() isn't actually a constructor)
mob/combatant/player
bounds = "10,3 to 22,19"

Login()
loc = null
src.LoadClientHUD()
client.CreateMainMenu()
..()
Logout()
Players --
OnlinePlayers-=src
for(var/atom/movable/a in move_with)
del a
world << "<font color=red>[src] has logged out!"
del src
..()

mob/combatant/player
var
tmp/cansave = FALSE
xco
yco
zco
Del()
Save_Character()
..()

mob/combatant/player/Write(var/savefile/F)
var/oldIcon = src.icon;var/oldcolor=src.color;var/list/oldOverlays=src.overlays.Copy()
src.overlays=null;src.icon=null
src.color = null
..()
src.overlays=oldOverlays;src.icon=oldIcon;src.color=oldcolor

mob/combatant/player/proc
Save_Character()
if(cansave)
var/savefile/F = new("Saves/[src.ckey].sav")
xco = x
yco = y
zco = z
F << src
// client.SendMessage("<font color=red>Game Saved.</font>")

Load_Character()
if(fexists("Saves/[src.ckey].sav"))
var/savefile/F = new("Saves/[src.ckey].sav")
F >> src
src.loc = locate(src.xco,src.yco,src.zco)
world << "<font color=green>[src] has logged on!"
world << client
PlayerFirstSpawn()



did i do anything wrong?
When you do "F >> src", you're actually replacing the value contained by the "src" variable with the mob in the savefile.

Since there are actually two mobs involved (the mob doing the loading, and the mob that is loaded), you shouldn't use the src variable to contain the mob being loaded.