ID:165915
 
mob/proc/saveName()
var/savefile/R = new("save/[key].sav")
R["NameSave"]<<NameSave
..()
mob/proc/loadName()
if(fexists("save/[key].sav"))
var/savefile/R = new("save/[key].sav")
R["[usr.name]"]<<NameSave
usr.name="[usr.name].sav"
..()

This is what I have to save and load, not even sure if this works, but I need it so that it will ask the player to input their name only if they haven't inputed their name before
well the load will fail <_< (but not crash)
mob/proc/loadName()
if(fexists("save/[key].sav"))
var/savefile/R = new("save/[key].sav")
NameSave = R["[usr.name]"]
usr.name="[NameSave]"
..()
else
// no save file detected
NameSave = input(usr,"what would you like your name to be?","enter your name",usr.name) as text
if(alert(usr,"are you sure you want to be called [NameSave]?","Check your name","Yes","No") == "Yes")
usr.name = "[NameSave]"
usr.saveName()

notes
1: you will get yell'd at for having usr in a mob based proc
where src will work (this is because it can make issues later on)
2: I will get yell'd at for not fixing my post to use src
3: im not sure if the changed Load will work fully its only there as an example.
4: i use "[]" when setting the name even thou you could just have usr.name = NameSave (thats just something I do please change it)
If you want to make a character saving system, I propose that you use <code>Read()</code> and <code>Write()</code> to do this. They're really easy to use:

mob/Login()
.=..()
if(fexists("players/[ckey].sav")) //if we have a savefile
var/savefile/F=new("players/[ckey].sav")
Read(F)

mob/var/save=0
mob/Logout()
.=..()
if(save) //if we're allowed to be saved
var/savefile/F=new("players/[ckey].sav")
Write(F)
del src


This simple and robust code will make it so that your characters will save. It also allows you to specify wether you want the player to save. I will use this below. You can include a check if the character doesn't have a name like so:

proc
hasletters(t) //returns 1 if [t] has letters
if(!istext(t))return
for(var/i=1,i<=length(t),i++)
var/x=text2ascii(t,i)
if(x>=65&&x<=122)return 1
return 0
mob/Login()
name="" //set name to null, something which a player should not be allowed to name
.=..() //load the character and do other things if nessesary
if(!name) //the player hasn't setup their name
var/x=loc
loc=null //temporarily move the player into The Void
if(client) //disable the verb panel and the map and the statpanel
client.show_verb_panel=0
client.show_map=0
client.statobj=null

name=input("Please input your characters' name.","Character Creation",key)as null|text //allow the player to input their name, provide a "Cancel" button and make the default their BYOND key.
name=html_encode(name)
if(!hasletters(name)) //the player didn't input any letters in their name, which is usually a good sign that\
the player is trying to get a null name

del src //cause the player to logout
save=1 //allow the player to be saved
loc=x
if(client) //enable the verb panel and the map and the statpanel
client.show_verb_panel=1
client.show_map=1
client.statobj=src


This will ask for the player to name their character if they joined for the first time. If they specify a name which has no letters, it's a good sign the player is trying to abuse the system (possibly by having a name like " "). HTML is disabled in the name. (Warning: The \n tag can still be used for some annoyance!)

During the naming process, the player gets no map, no verb panels and no statpanels. This is only an illusion, however: you should make your own means of preventing verbs and such from being used.


This is a demo. You should learn from this rather than just copy/paste this.
Warning: Untested code.