ID:264694
 
Code:
mob
player
verb
Save()
var/savefile/P=new("players/[src.ckey].sav")
src.Write(P)
P["lastx"] << usr.x
P["lasty"] << usr.y
P["lastz"] << usr.z
P["direction"] << usr.dir
usr << output ("<font color=green>Your file has been saved!</font>", "OOC")
..()

mob
Nplayer
verb
Load()
if(fexists("players/[src.ckey].sav"))
var/savefile/P=new("players/[src.ckey].sav")
src.Read(P)
var/newX
var/newY
var/newZ
var/newD
P["lastx"] >> newX
P["lasty"] >> newY
P["lastz"] >> newZ
P["direction"] >> newD
src.Move(locate(newX,newY,newZ))
src.Move(locate(newD))
usr.verbs+=typesof (/mob/player/verb/)
..()
else
usr << output ("<font color=red>You do not have a saved character!</font>", "OOC")
return


Problem description: I don't know how to save the verbs for the player. When they load, they don't have their player verbs unless I give them to them via the usr.verbs+=typesof (/mob/player/verb/), that and I cannot get rid of the load verb.

Also, I can't get the player's direction to save and load, no matter when, when you load the player, they always face west.


You are doing saving wrong. This is how to do it properly:

client
proc
Save()
var/savefile/F = new("[ckey].sav")
F["mob"] << mob
Load()
if(fexists("[ckey].sav"))
var/savefile/F = new("[ckey].sav")
F["mob"] >> mob

New()
Load()
..()

Del()
Save()
..()

mob
Write(var/savefile/F)
..()
F["x"] << x
F["y"] << y
F["z"] << z
Read(var/savefile/F)
..()
loc = locate(F["x"], F["y"], F["z"])
In response to Garthor
I managed to cook this up from what I was given. But it says that mob under the parameter is an undefined variable on both verbs

mob
player
verb
Save()
var/savefile/P = new("players/[ckey].sav")
P["mob"] << mob
Write()
P["x"] << x
P["y"] << y
P["z"] << z
usr << output ("<font color=green>Your file has been saved!</font>", "OOC")
..()

mob
Nplayer
verb
Load()
if(fexists("players/[src.ckey].sav"))
var/savefile/P = new("players/[ckey].sav")
P["mob"] >> mob
Read()
loc = locate(P["x"], P["y"], P["z"])
else
usr << output ("<font color=red>You do not have a saved character!</font>", "OOC")
return
In response to Ryu-Kazuki
What I was telling you to do was a REPLACEMENT for what you had, not a supplement.

I've gone over how to save and load so many times because there's a whole lot of really, really bad code getting passed around. Just do a forum search for "save author:Garthor" and you'll find about a hundred posts.

Wait, no: three hundred.
In response to Garthor
Then help me understand the replacement better.

I want a save and load verb, no procs. I've tried the procs and it's just killing me. (Or, if you could, my IMs are

AIM: Fireninjanaruto
YIM: Fireninjanaruto
MSN: [email protected]

Please help me better understand this. Much appriciated.)

If you can IM me on one of those, we can discuss it and you can help impliment it.
In response to Ryu-Kazuki
And I want fifty bucks. Alas, I am not about to have my every wish granted to me across the forum.

If you want save/load verbs, then just make verbs that call the procs. Note that you'll also need to delete the old mob after a new one is loaded, which you can probably accomplish with just a del(src) after calling it in the verb, or modifying the proc to delete the old mob if there is one.
In response to Ryu-Kazuki
verbs are a list, you would save it and load it just like any other varibles. (Use the X, Y and Z in garthor's snip of code as an example.)
In response to Pirion
That's not the problem, my old system would save the x,y,z just fine. It wouldn't write / read the usr's direction or verbs. That was my original problem.

I now implemented Garthor's system as so. I get this afterward.

loading Bleach TRP.dme
loading main.dmf
verbs.dm:68:error: Save: undefined proc
verbs.dm:77:error: Load: undefined proc

Bleach TRP.dmb - 2 errors, 0 warnings (double-click on an error to jump to it)

//verbs.dm


mob
player
verb
save()
set name = "Save"
set desc = "Save your character"
Save()
..()

mob
Nplayer
verb
load()
set name = "Load"
set desc = "Load your saved character"
Load()
..()

//savesystem.dm

client
proc
Save()
var/savefile/P = new("players/[src.ckey].sav")
P["mob"] << mob
usr << output ("<font color=green>Your file has been saved!</font>", "OOC")
Load()
if(fexists("players/[src.ckey].sav"))
var/savefile/P = new("players/[src.ckey].sav")
P["mob"] >> mob
else
usr << output ("<font color=red>You do not have a saved character!</font>", "OOC")
return

mob
Write(var/savefile/P)
..()
P["x"] << x
P["y"] << y
P["z"] << z
Read(var/savefile/P)
..()
loc = locate(P["x"], P["y"], P["z"])
In response to Ryu-Kazuki
you need to call client.save and load as they are attached to the client.
In response to Pirion
Alright well, it still doesn't save the verbs. And now, when I load, it says that I logged out and logged in.
In response to Ryu-Kazuki
> mob
> Write(var/savefile/P)
> ..()
> P["x"] << x
> P["y"] << y
> P["z"] << z
> Read(var/savefile/P)
> ..()
> loc = locate(P["x"], P["y"], P["z"])


Just the the x y and z vars were saved, we would have to save these in the Write proc.
P["verbs"] << verbs

then on the read proc, we would load them into their correct places
verbs += P["verbs"]


With Read, it disconnects and reconnects your client mob, so that is why it is giving you 2 entrys.

You want to set the world.mob as your loading mob, then create a new mob without the "Has entered the game" on the login for your player type mob.


For direction you wouldnt move them, you would just set it.

dir = F["dir"]
In response to Pirion
I changed my logout to this, and it doesn't say I logged out when I load now. Was this is a good idea?

client
proc
Logout()
world<<output("<font color=red>[usr.name] has logged out!</font>", "OOC")
del(src)
..()
In response to Ryu-Kazuki
Yes that would be fine also. It will show the message when the client disconnects not the mob.

P.S. I edited the post above for your direction issue.
In response to Pirion
Despite your help and Garthor's. I still have problems. I had to change the logout back. It made it horribly bad, it's too hard to explain.

Now, since I reverted back. It still tells me when my mob logs in and out. I'd like it to do that only when a player first logs in or out.

That, and thank you, it restores my verbs. But the load verb won't go away now. I want the load verb to only appear on the login screen.

Here is my logout.

mob
Logout()
world<<output("<b><font color=red>[name] has logged out!</font>", "OOC")
del(src)
..()


Here is my login.

mob/Login()
usr.loc=locate(9,8,1)
usr.verbs+=typesof (/mob/Nplayer/verb/)
world << output ("<b><font color=green>[name] has logged in!</font>", "OOC")
if(usr in bans)
usr << output ("You are banned and cannot come in!", "OOC")
del(usr)


Here is my load verb.

mob
Nplayer
verb
load()
set name = "Load"
set desc = "Load your saved character"
client.Load()
..()
In response to Ryu-Kazuki
what is happening is it is running the mob/Login for mob when you first connect, then again for mob/Nplayer when you load.

lookup world.mob
In response to Pirion
Well, how do I get rid of the load verb? I can't use typesof -= (etc), it says there's an infinite cross-reference loop. Is there any other way besides the reading the verbs a character had to get rid of the load verb?
In response to Ryu-Kazuki
Ryu-Kazuki wrote:
Alright well, it still doesn't save the verbs. And now, when I load, it says that I logged out and logged in.

This is a result of putting the message in mob/Login() and mob/Logout(), which is not where it belongs. Move any "soandso has connected/disconnected" messages to client/New() and client/Del(), which are the actual procs that are called when a player joins or leaves your game.
In response to Ryu-Kazuki
once again, it should be assigned to your login mob, not your root mob, which will also be from world.mob
In response to Pirion
I found an alternative way to fix yet. Now I'm onto my other problems. Thank you and Garthor for your help.