ID:273418
 
Been ages since I've posted here.

Anyway, I'm trying to find an efficient approach to do a mob switch. Basically, I'm working on a game where players control a one mob, but once they enter battle, they change to a different mob that handles differently. After the battle is over, or if they log out, I want them to switch back to their previous mob. I've tried a few different ways, but all of them end up just saving the battle mob and the switch back never occurs. What's a good way to do this?
I'm not excaclty sure if this is what u need but may help you anyway. look up 'tmp' variables in the help (F1)
In response to Lusodante
No, tmp just prevent variables from being saved. I'm looking for a method of switching players back to their previous mob after a battle, either before log out, or during login.
In response to Pyro_dragons
If you mean before the Login() and Logout() procedures are called, that's not possible: they are by definition called when client.mob changes.

What you need to do is move all the "player is leaving the game so do stuff" code to client/Del(), which is ONLY called when a client disconnects (and, similarly, client/New() is ONLY called when a client connects).
In response to Garthor
Am I getting this right?
if i do something like:
...
var/mob/player/character/C = new()
src.client.mob = C
...


the Logout() proc of the current mob will be called, and then the Login() proc of the new mob?

Anyway, i tried it and it seems to do as i stated above.
I currently working on something that switches the client.mob too, there is one big traphole: "src" is in the proc (and all procs directly called by that proc)that changes the client.mob still a reference to the old mob. "src" is only updated if the proc terminates.

That also means with the method stated above, you have to set every value for the new player mob manually. (actually thats the reason, why I'd like to know if there is a better method)

EDIT:Well, after testing it SEEMS the Login()proc is directly executed after setting assigning a new mob...

EDIT2:
have a look at this, that may server as a example:
http://www.byond.com/developer/forum/?id=700351
In response to Amsel
Amsel wrote:
EDIT:Well, after testing it SEEMS the Login()proc is directly executed after setting assigning a new mob...

Yes, as Garthor said, Logout() and Login() are called any time you change mobs. Changing mobs will happen if you set client.mob directly or assign a logged-in user's key to another mob. This also means that loading a saved character from a savefile will automatically transfer you to that character, since the mob probably was saved with the key var intact. (This is one reason why savefiles that haven't been rollback-proofed, and accidentally saved with other mobs inside, can cause people to suddenly jump into older versions of their characters.)

Lummox JR
In response to Lummox JR
i am having a similar problem except i want the mob to change forever but keep old stats(and name)

for mob swapping how bout you just make another command to change the mob back to the user?

im pretty sure this is how pokemon games work xD