ID:148360
 
My mob seems to get placed on the same Z level everytime I restart. This is my code:
mob
icon = 'icons.dmi'
var
ishost = 0
Login()
..()
if (usr.ishost == 1)
usr.loc = locate(1,1,rand(1,world.maxz))
else
var/mob/M
for (M as mob in world)
if (M.ishost)
usr.loc = locate(1,1,M.z)
world
New()
var/mob/M
for (M as mob in world)
if(M.client)
M.ishost = 1
turf/Ground
z1
icon='icons.dmi'
icon_state="1"
z2
icon='icons.dmi'
icon_state="z2"
Your problem is that the <code>ishost</code> var is never being set, so the mob's Z level is being set to its current Z level (which is 1). You're attempting to set it in world/New(), but that won't work - the reason being, the mob doesn't exist yet when world/New() is called. The order of execution goes something like this, when a game is hosted in Dream Seeker (the host is not guaranteed to log in at all when the game is hosted via Dream Daemon):

- World is created, all objects in .dmp files are created and placed
- world/New() called
- Host logs in
- client/New() is called for the host
- A new mob is created for the host
- mob/Login() is called for that new mob

Also, that isn't the best way to go about setting up a host var. Besides the fact that you'll have to loop through all the mobs in the world just to find the host, you're actually finding non-NPCs rather than the host of the game. You want to check <code>client.address</code>.

I usually do this:

<code>var client/host //Var that can contain /clients; not often used, but best for this purpose</code>

Then, in client/New():

<code>client/New() .=..() //Always, always, ALWAYS call this if you override client/New() //If src has no address (or its address is the same as the world's) and there isn't a host already, set src as the host if ((!src.address || address==world.address) && !host) host=src</code>

Then you can just check for the host like this in mob/Login():

<code>mob/Login() ..() if (client==host) world << "[src] is the host! Yay for [src]!" else world << "[src] logs in. Whoever \he is."</code>