ID:145752
 
Code:
client/proc/Load(char_name)
var/mob/new_mob
var/savefile/F = base_PlayerSavefile()
_base_player_savefile = null
var/char_ckey = ckey(char_name)
F.cd = "/players/[ckey]/mobs/"
var/list/characters = F.dir
if(!characters.Find(char_ckey))
mob << "Savefile was not found."
return null

F["[char_ckey]/mob"] >> new_mob
if (new_mob)
mob = new_mob
new_mob.base_InitFromSavefile()

// If we're doing verbs, set them now.
if (base_save_verbs && new_mob.base_saved_verbs)
for (var/item in new_mob.base_saved_verbs)
new_mob.verbs += item
return new_mob
return null
client/proc/SaveMob()
if (!mob || !mob.base_save_allowed)
return

// If we're saving verbs, move them over now.
if (base_save_verbs)
mob.base_saved_verbs = mob.verbs

var/savefile/F = base_PlayerSavefile()

var/mob_ckey = ckey(mob.name)

var/directory = "/players/[ckey]/mobs/[mob_ckey]"
F.cd = directory
F["name"] << mob.name
F["mob"] << mob
_base_player_savefile = null


Problem description:

I set the game to save whenever a verb is pressed or when the person logs out, and the Load() proc is called whenever someone clicks a load game button.

Problem is, the game cannot find the savefile, and before I changed the coding to this, the game did load, but only if the saved mob's name was the same as your key...

Please help.

Code:
> client/proc/Load()
> var/mob/new_mob
> var/savefile/F = base_PlayerSavefile()
> _base_player_savefile = null
> var/char_ckey = ckey(char_name)
> F.cd = "/players/[ckey]/mobs/"
> var/list/characters = F.dir
>
> F["[char_ckey]/mob"] >> new_mob
> if (new_mob)
> mob = new_mob
> new_mob.base_InitFromSavefile()
>
> // If we're doing verbs, set them now.
> if (base_save_verbs && new_mob.base_saved_verbs)
> for (var/item in new_mob.base_saved_verbs)
> new_mob.verbs += item
> return new_mob
> return null
> client/proc/SaveMob()
> if (!mob || !mob.base_save_allowed)
> return
>
> // If we're saving verbs, move them over now.
> if (base_save_verbs)
> mob.base_saved_verbs = mob.verbs
>
> var/savefile/F = base_PlayerSavefile()
>
> var/mob_ckey = ckey(mob.name)
>
> var/directory = "/players/[ckey]/mobs/[mob_ckey]"
> F.cd = directory
> F["name"] << mob.name
> F["mob"] << mob
> _base_player_savefile = null
>
>

Problem description:
This is how the code was before the changes, and it loads only characters with names as same as the key.
In response to FlameMarth
Wow, that's overly long and invovled. Since you savefile is a proc, under every verb you have, just put savefile() to call the save file proc and save their char. The same goes for logging out. Just put savefile(). Here, try this savefile proc. It's tested and works just fine. It saves the players name, stats, and whatever else they have(inventory, equipped items, etc.)

mob/proc/savefile(mob/M)
var/savefile/F = new(key)//creates a new savefile with their key, but still saves all that current stats.
Write(F)



Now, you're going to want to save the location of the user, so put this.

mob
var
saved_x
saved_y
saved_z
Write(savefile/F)
saved_x = usr.x//saves the users x loc
saved_y = usr.y//saves the users y loc
saved_z = usr.z//saves the users z loc
..()//calls the parent
Read(savefile/F)//this is for when the game is loaded
..()//call the parent
Move(locate(saved_x,saved_y,saved_z))//move them to their save location


As for loading the file, try this.

mob/proc/loadfile(mob/M)
var/savefile/F = new(key)
Read(F)


That should get you the desired effect. If you have any problems with it just post.



In response to Pyro_dragons
yeah, it loads and all, but one problem: once I do load I lose all the mob's verbs...
In response to FlameMarth
What do you mean " I lose all mob verbs"? Do you mean that every verbs you had is just not there any more? If so, then it has to do with something in your code and not with the savefile because that is my savefile and it works just fine.
Do you mean GM/Admin verbs?
In response to Pyro_dragons
I don't think it's because of the save code, I think it is because my coding creates a different type of mob for logging in (so that they don't have verbs while on title screen) and then a different one (/mob/player) for a character (usually one newly created), when it loads, the character type seems to stay as "/mob/selectingcharacter", the type that nullifies all verbs...
In response to FlameMarth
I'd have to see how that works, but I'm not sure if I can help you all that much. I've no EXP with doing titlescreens, I just can't get it to work right.
In response to Pyro_dragons
i'll worry about the rest, can you update the code so that it saves into a folder.. like players/(keynamehere).sav?
In response to FlameMarth
I don't have mine saved in a folder and I don't know how to do it. To be honest, so long as you keep your folder organized, you'll be fine. Well, that's what I do.