ID:149996
 
Heres what im trying to do. I have it where if you login, and its your first time you have logged in with that char, then randomize where you start.. [The spacing is messed up, caused by the forum]

Login()
if(usr.first_login == 0)
usr.first_login = 1
var/island = rand(1,5)
switch(island)
if(1)
var/locx = rand(1,14)
var/locy = rand(1,27)
usr.Move(locate(locx,locy,1))
if(2)
var/locx = rand(1,21)
var/locy = rand(73,100)
usr.Move(locate(locx,locy,1))
if(3)
var/locx = rand(92,100)
var/locy = rand(43,63)
usr.Move(locate(locx,locy,1))
if(4)
var/locx = rand(87,100)
var/locy = rand(240,247)
usr.Move(locate(locx,locy,1))
if(5)
var/locx = rand(188,201)
var/locy = rand(151,162)
usr.Move(locate(locx,locy,1))


Ok, that works.. now i need it to make you start out where you last were, before you logged out.. Heres what i have.
else
usr.Move(locate(usr.lasty,usr.lastx,1))

Logout()
world << "<b>[usr] logs out."
usr.lastx = usr.x
usr.lasty = usr.y
del(usr)


And for some reason, when you login with an old character, you start at 1,1,1... Any ideas?

-Rcet
Rcet wrote:
Logout()
world << "<b>[usr] logs out."
usr.lastx = usr.x
usr.lasty = usr.y
del(usr)

And for some reason, when you login with an old character, you start at 1,1,1... Any ideas?

Well, aside from not closing the <B> tag, there's one big problem: You're deleting the mob instead of moving it to null. The changes you store in lastx and lasty aren't saved becaues you immediately delete the mob right afterward. You have to safe the mob right at that point, then delete it--or else move it to null.

[EDIT]
You should also consider using a list to store starting turfs. Much simpler than a switch() statement, you could run a proc in world.New() that stores those turfs in a list, and then in Login() you could set the loc like this:
if(island)
loc=startturf[island]
else
loc=locate(lastx,lasty,1)

Lummox JR
In response to Lummox JR
The changes you store in lastx and lasty aren't saved becaues you immediately delete the mob right afterward. You have to safe the mob right at that point, then delete it--or else move it to null.

What exactly do you mean by saving it right at that point?
Do you mean save, or did you purposely type 'safe'?

Thanks for the help.

-Rcet
In response to Rcet
Rcet wrote:
What exactly do you mean by saving it right at that point?

Unless you have some saving code somewhere, if the game is shutdown or restarted, player mobs aren't going to remember their last position no matter what. For that you need to save info in a savefile.

If you aren't already, you might want to use the CharacterHandling library for this. The simple demo:

byond://Deadron.SimpleSaving

The more in-depth demo:

byond://Deadron.CharacterSaving

And the nifty new web page version:

byond://Deadron.CharacterForm
In response to Rcet
Rcet wrote:
What exactly do you mean by saving it right at that point?
Do you mean save, or did you purposely type 'safe'?

Yep, I did mean save. Dran tpyos.
I mean that you need to store those changes somewhere, or else they'll be lost when the mob is deleted. It's kinda like spending all night typing a paper, then the power goes out and you lose it because you didn't save it.

Lummox JR
Ok.. i messed with it alot and i cant seem to get it to work. This is the cod ei have:
mob
proc
save()
var/savefile/F = new("[src.ckey].sav")

F["x"]<<lastx
F["y"]<<lasty
F["z"]<<lastz

mob
proc
load()
var/savefile/F = new("[src.ckey].sav")

F["x"]>>lastx
F["y"]>>lasty
F["z"]>>lastz
src.loc=locate(lastx,lasty,lastz)


Login()
if(usr.first_login == 0)
usr.first_login = 1
var/island = rand(1,5)
switch(island)
if(1)
var/locx = rand(1,14)
var/locy = rand(1,27)
usr.Move(locate(locx,locy,1))
if(2)
var/locx = rand(1,21)
var/locy = rand(73,100)
usr.Move(locate(locx,locy,1))
if(3)
var/locx = rand(92,100)
var/locy = rand(43,63)
usr.Move(locate(locx,locy,1))
if(4)
var/locx = rand(87,100)
var/locy = rand(240,247)
usr.Move(locate(locx,locy,1))
if(5)
var/locx = rand(188,201)
var/locy = rand(151,162)
usr.Move(locate(locx,locy,1))
else
..()
load()
usr.Move(locate(usr.lasty,usr.lastx,usr.lastz))

Logout()
world << "<b>[usr] logs out.</b>"
lastx = src.x
lasty = src.y
lastz = src.z
save()
del(src)


It STILL makes me start at 1,1,1.. also it makes my lastx,y and z null.. Please help :(

-Rcet