ID:144049
 
Code:


Problem description:
I've tried this many times, I've used many different things, I've even tried taking the character creation from the Graphical MUD Kit! And all I want to know is, HOW DO YOU CHANGE A PLAYERS MOB?!?! I use src.client.mob, but it ALWAYS gives me a runtime error: bad client. HOW CAN I DO IT?!?!

Explain what do you mean by change their mob?

1. Allow them to look different(Change icon?)
2. ALlow them to control someone else(temporarily/permanently)
2a. Allow them to be an EXACT copy

1. Just change their icon..
src.icon = 'blah.dmi'
src.icon_state = "blah2"


2. Click here

2a. Just manipulate stats:
src.hp = M.hp // of course you have to select who M or whatever is first



Also in the future for code problems, show your code..Otherwsie, it might be a better Developer How To..
Do you want to "stick" the client to another mob, or just change the one you alreay have?
for the former:
mob/verb/bodysnatch()
set src in oview(2)
if(!usr.client) return
if(!src.client)
usr.client.mob = src
else
usr << "Someone else already snatched that body."

client.mob can be used to do this - so if that's what you were going for, you're on the right track. The runtime error may stem from an attempt to "body snatch" with a mob that isn't controlled by a client.

For the latter possibility:
client/verb/alter_mob(var/setvar1, var/setvar2)
set src in oview(2)
src.mob.var1 = setvar1
src.mob.var2 = setvar2


Which were you going for, and were you looking for something a bit more complex? Maybe we could see some code...


--Vito
In response to Vito Stolidus
I was trying to change the usr's mob to another, pre-defined mob in the game. So the usr could have special verbs that nobody else could have.
When will I get an answer?! Changing the src.client.mob var works in the Graphical MUD Kit, so why doesn't it work here?
In response to Armiris
Why not post the code you're trying to use that isn't working?
Something as simple as this should do the trick:

mob
Login()
var/Race = input("Which race do you want to be?","Race selection") as null|anything in list("Human","Wolven","Alien") //Prompt for a race
if(!Race) del(src) //If they chose cancel, have them quit.
var/P = text2path("/mob/[Race]") //Construct a path based on the race they chose
client.mob=new P() //Connect their client to a new mob of that type

Human
icon='Blah.dmi'
Wolven
ALien


However, in the case of administration abilities, you might want to consider a different path. I would suggest just adding the verbs to their verbs list without actually switching their mobs.

Now, to do this, you create a fake class to put all the verbs under. Something like "mob/Admin" will work fine. Then, when you want to give the verbs to someone, just do "M.verbs+=typesof(/mob/Admin/verb)-/mob/Admin/verb," with M being the player to give the verbs to.

Here's an example:
mob
Login()
if(key=="SuperMrAdminGuy")
src.verbs+=typesof(/mob/Admin/verb)-/mob/Admin/verb
..()


Admin
verb
Super_Awesome_Smite_Attack()
world<<"Kapow!"
sleep(10)
world<<"Fatality!"
sleep(2)
del(world)


That's about the gist of it. There may be a few mistakes, since I just did this off the top of my head. If you need me to further explain any of it, I'd be happy to oblige.
In response to Armiris
Then modifying src.client.mob (for verbs defined under something other than the mob use usr.client.mob) should do nicely. Again, if I could see code, I could <s>shoot it full of holes</s> - err, show you what's going wrong to give you "error: bad client".

--Vito
In response to DarkCampainger
You should probably have the mob/Login() code in client/New(), or somewhere similar. mob/Login() isn't all that safe if you're moving people around between mobs.
In response to Jp
Jp wrote:
mob/Login() isn't all that safe if you're moving people around between mobs.

True. His code like there will make an infinite loop. Note however generally you should use client/New() instead I guess, but you CAN easily distinguish between connecting/disconnecting from the game and between mob-switching in both Login() and Logout(). Their reference entries tell about this.
In response to DarkCampainger
I understand all of it, but I used your code and it still gives me this error:
runtime error: bad client
proc name: Login (/mob/Login)
usr: Red Team (/mob/Red_Team)
src: Red Team (/mob/Red_Team)
call stack:
Red Team (/mob/Red_Team): Login()
I'llpost the code here:
mob
White_Team
icon = 'teammates.dmi'
icon_state = "white"
Red_Team
icon = 'teammates.dmi'
icon_state = "red"
Blue_Team
icon = 'teammates.dmi'
icon_state = "blue"
Login()
..()
src << "Welcome to TrapWar! Pick your team."
world << "[src.key] is picking \his character!"
var/Team = input("What team would you like?","Team Selection") as null|anything in list("Red_Team","Blue_Team") //Prompt for a team
if(!Team) del(src) //If they chose cancel, have them quit.
var/P = text2path("/mob/[Team]") //Construct a path based on the team they chose
client.mob=new P()
src.team = "[Team]"
src.name = input("What is your name?","Name") as text
usr << "Welcome to the [usr.team] base! Destroy or capture all of the other team to win!"
world << "[src.team] Teammate [src.name] has logged on!"
Logout()
..()
world << "[usr.team] Teammate [src.name] has logged out."
var
team = null
In response to Armiris
Kaioken wrote:
His code like there will make an infinite loop.

Whoops. Sorry, I was tired last night. Nice catch.


Armiris wrote:
I understand all of it, but I used your code and it still gives me this error:
runtime error: bad client
proc name: Login (/mob/Login)
usr: Red Team (/mob/Red_Team)
src: Red Team (/mob/Red_Team)
call stack:
Red Team (/mob/Red_Team): Login()

Well, there are a few problems with your code (most of them my fault, sorry), but none of them that would lead to a bad client (which makes me think you're manually calling login on something)

First, let's take their suggestion and use client/New() instead for choosing a team:
client
New()
src << "Welcome to TrapWar! Pick your team."
world << "[src.key] is picking \his character!"
var/Team = input(src,"What team would you like?","Team Selection") as null|anything in list("Red_Team","Blue_Team") //Prompt for a team
if(!Team) del(src) //If they chose cancel, have them quit.
var/P = text2path("/mob/[Team]") //Construct a path based on the team they chose
mob=new P()


Now, we'll re-setup the teams to match this: (Oh god, Firefox just crashed, curse you QuickTime update!)
mob
var/team=null
Login() //Now we can use this for joining a team
src.name = input("What is your name?","Name") as text
src<< "Welcome to the [team] base! Destroy or capture all of the other team to win!"
world << "[src.team] Teammate [src.name] has logged on!"
..()
Logout()
world << "[usr.team] Teammate [src.name] has logged out."
del(src) //Remove their mob from the field
..()
White_Team
icon = 'teammates.dmi'
icon_state = "white"
team="White_Team"
Red_Team
icon = 'teammates.dmi'
icon_state = "red"
team="Red_Team"
Blue_Team
icon = 'teammates.dmi'
icon_state = "blue"
team="Blue_Team"


You'll also notice that I defined team under the actual team mobs. This way, you could even change the teams to something more simple, like just "White", "Red", and "Blue".
In response to DarkCampainger
DarkCampainger wrote:
Kaioken wrote:
His code like there will make an infinite loop.

Whoops. Sorry, I was tired last night. Nice catch.

Sure, no problem. Stuff like that happens. A lot.

Well, there are a few problems with your code (most of them my fault, sorry)

Really, screw him, he shouldn't be copying your code in the first place...