ID:156968
 
How can I assign a mob to the client based on a choice during runtime? My attempts were unsuccessful. Thanks.
Usually, you should post your attempts. Anyways, I am pretty sure that this is how you do it.

mob/player
icon = 'player.dmi'

mob/verb/set_up()
mob = new/mob/player
In response to Darkjohn66
That is what I did with my attempt, which does not work because it makes me relog or so it seems.
In response to DisturbedSixx
mob var (client)

mob
verb
Do_It()
var/mob/M=client.mob //remember the old mob
var/mob/Thingy/T=new(loc) //create a new mob in the same location
client.mob=T //set the client's mob var to the new mob
del M //del the old one
Thingy
icon='icon.dmi'
In response to Cody123100
What would I do if I do not have an old one. I'm trying to create the mob after choosing it in the character creation.
In response to DisturbedSixx
As soon as any client enters into the game, they are assigned a mob based upon world.mob. By default this is simply the /mob type.So unless you set world.mob to 0, every player will have a mob created upon joining. However, if you do set world.mob to 0, simply skip the steps on remembering and deleting the old mob and go straight to creating the new mob. Then relocate the player to a position on the map as needed.
In response to Cody123100
Say I assign this through an object. Say:
obj/thing
DblClick()
//go to proc to assign mob

And then the proc looks something like:
mob/proc/MobAssign(TYPE)
switch(TYPE)
if("Bulbasaur")
var/mob/M=client.mob
var/mob/Pokemon/Bulbasaur/B=new(loc)
client.mob=B
del M

The only way I can see to link to the proc would be to do usr.MobAssign(Bulbasaur) but then it tells me usr in null through a runtime. I'm getting a bit confused and cannot solve it no matter what I do.
In response to DisturbedSixx
Take note that this code is just an example, if you actually use it in your pokemon game I imagine players will get frustrated always playing with default level pokemon. You should really write a design document with planned steps on the checks you need to initiate to make sure things go as planned. There's a lot more work than simply making a pokemon appear on the screen when you click a pokeball, for a few examples: What if the pokeball isn't in the user's contents? What if the pokemon in the pokeball doesn't have default stats? What if the pokemon in the pokeball is holding an item or has a status condition? What if the pokemon in the pokeball is injured/fainted?
obj
Pokeball
DblClick()
MobAssign(usr.client,"Bulbasaur")

proc //notice that we don't file this proc under a type like a mob/obj/turf
MobAssign(client/source,TYPE) //source is the client that initiates it, type is the type
if("Bulbasaur") //if it's a bulbasaur
var/mob/M=source.mob //temporarily remember the old mob
var/mob/Pokemon/Bulbasaur/B=new(loc) //create a new bulbasaur (NOTE: This will create a bulbasaur with default stats, it's your job to figure out how to get it to use the bulbasaur already in the pokeball)
client.mob=B //make the client's mob a bulbasaur
del M //delete the old mob (NOTE: In a pokemon game you might not want to do this, as it will delete your trainer, as well as everything in his contents and all of his stats etc.)
In response to Cody123100
I have managed to get it working (thanks for the big help) but why do I relog before I get into the game?
In response to DisturbedSixx
If you mean that it's calling Login() again, then it's probably because you have overwritten Login() for the default mob type (/mob). The unoverwritten proc simply checks if the mob has a location and if it doesn't it places it at (1,1,1). Since it is called whenever you try to connect to a mob (whether automatically at client.New() or manually called by changing the player's mob) if you have overwritten it for the default mob it will call your overwritten version everytime you connect to a new mob. For simplicity sake I would suggest that you create a tmp variable that tracks if the player is logged in (0 for false, 1 for true). If true then return, otherwise proceed into login and set the tmp variable to 1.
In response to Cody123100
It actually calls both the Logout() and Login(). Also, it changes the mob from being my key, DisturbedSixx, to the name of the mob path I'm assigning. Can I avoid that?
In response to DisturbedSixx
You can overwrite the name variable. And yes, it would call mob.Logout() too, I forgot that part heheh. You'll need to take that into account too possibly with a tmp variable that detects if you are switching mobs or actually logging out. For example,set the tmp variable to 1 before switching and back to 0 after switching is complete. Make it so that whenever Logout is called while switching is 1 it will not process. Beware however, you also need to consider what will happen if someone logs out while in a pokemon mob; or worse, they logout while switching is set to 1.
In response to Cody123100
Well I will try that out and edit this post and let you know how that works. Also, this isn't to send out pokemon. This will be you choosing the starter and then staying that mob for the remainder of the game.

{EDIT}
Yeah doing that tmp var worked for the Logout() but it still calls the Login() and if I apply the same method for Login(), it gives me a black screen. Geez this is harder then I expected it to be...
In response to DisturbedSixx
Here's an example.

mob
var/tmp
loggedin=0
switching=0
Login()
..() //do the default action
if(!loggedin) //if loggedin var=0
//do the custom login stuff
else
return //do nothing

Logout()
..() //do the default action
if(!switching) //if switching var=0
//do the custom logout stuff
else
return //do nothing

proc
Switch(client/source,TYPE) //modeled after your original switching proc
source.mob.switching=1
//do the switching stuff
source.mob.switching=0 //reset the switching tmp var after the switching is completed
In response to Cody123100
Alright I fixed everything up and it seems to be working. For some reason it feels to me like I'm just masking up some kind of problem but I'll deal with it until it comes up. Thanks.
In response to DisturbedSixx
DisturbedSixx wrote:
Alright I fixed everything up and it seems to be working. For some reason it feels to me like I'm just masking up some kind of problem but I'll deal with it until it comes up. Thanks.

The problem is that you are conflating "Login()" with "A player has connected to the game". If you want to do something WHEN A PLAYER CONNECTS, that goes in client/New(). If you want to do something when a player DISCONNECTS, that goes in client/Del().

Again, Login() is called whenever a client is assigned a mob, and Logout() is called whenever a client stops controlling a mob.
In response to Cody123100
Cody123100 wrote:
As soon as any client enters into the game, they are assigned a mob based upon world.mob.

This is not accurate. This is part of the default action of client/New(). Look it up in the Reference.