ID:261753
 
When I use this piece of coding:

mob
Monster
icon = 'Monsters.dmi'
battle = 1
var/respawning = 0
var/oldx
var/oldy
var/oldz
var/mob/P //set a new var, the path is /mob/PC, and we will name it for easier typing P.
New() //This is called when the atom enters the world
. = ..()
if(src.respawning)
src.oldx = src.x
src.oldy = src.y
src.oldz = src.z

spawn() //Spawn here to prevent crashing. If you want it to wait a set amount of time before calling Wander(), then put a number in the middle of the spawn arguments.
Wander()
Del()
if(src.respawning)
spawn(100)
var/mob/Monster/M = new src.type ()
M.loc = locate(src.oldx,src.oldy,src.oldz)
..()


It doesnt wait for 100 ticks and respawn. In fact it doesnt do anything. Can anybody help me?
if(src.respawning)
spawn(100) {
var/mob/Monster/M = new src.type ()
M.loc = locate(src.oldx,src.oldy,src.oldz) }


Try this... spawn usually calls the procedure on the same line after 100 ticks, but instantly continues the rest of the code until then. The way I've given should make it wait.

splatty
Sorry, splatter, wrong answer. His use of spawn() is correct, he has a different problem. =)

The problem is that the spawn()ed code is never being executed. Why? Simple; the ..() in Del() is deleting the object (deleting is the default action for Del()), which halts all running procs belonging to the object. You still want the object to be deleted, so taking out the ..() isn't the answer. Instead, you have to make a new proc for the mob, pass the type and location of the monster to it, and in that proc set src to null. As src is null, the proc won't be halted when the object is deleted.

<code>mob/Monster/proc/ respawn(delay,typepath,newx,newy,newz) spawn(delay) new typepath(locate(newx,newy,newz)) //This combines the new and M.loc lines; the first argument to new is the location of the newly created object. mob/Monster/Del() if (src.respawning) respawn(100, src.type, src.oldx, src.oldy, src.oldz) ..()</code>