ID:262861
 
Code:
mob
var/XL
var/YL
var/ZL

mob
proc
Respawn()
for(var/mob/monster/M in world)
if(M.HP <= 0)
M.XL = M.x
M.YL = M.y
M.ZL = M.z
del(src)
spawn(20)
new src
M.loc = locate(M.XL,M.YL,M.ZL)
M.HP = M.HP


Problem description:

The code checks out, but doesn't work. How come?
What are you trying to do by deleting src? All of the mob's procs get stopped, so there is no use in trying to do that.

~~> Unknown Person
In response to Unknown Person
What you should do instead is delete and recreate M, because M is the monster you're respawning, yes?

Also, "new src" (or "new M") isn't what you want. That creates a new object with the typepath M. What you want is to create a new mob of the same type as before and assign it to M.

Also, you need to indent everything after spawn(20), or it will have no effect.

var/oldtype = M.type
del(M)
spawn(20)
M = new oldtype
// ...
In response to Crispy
ok, i changed it to what you had showed me, yet there is still no effect happening.
mob
proc
Respawn()
for(var/mob/monster/M in world)
if(M.HP <= 0)
M.XL = M.x
M.YL = M.y
M.ZL = M.z
var/oldtype = M.type
del(M)
spawn(20)
M = new oldtype
M.loc = locate(M.XL,M.YL,M.ZL)
M.HP = M.HP

any idea why?
In response to Pyro_dragons
Think about this line. What is it doing?

M.loc = locate(M.XL,M.YL,M.ZL)


More specifically, where is it getting its data from? What are the values of M.XL, M.YL, and M.ZL?

Hint: You just deleted and recreated M. =) That means XL, YL, and ZL are at their default values; not what you set them to a few lines up. Their default values are probably null, and locate(null, null, null) returns - guess what? - null! So your new monsters are getting created at null. Darn.

What you need to do is scrap the XL, YL, and ZL mob vars. Instead, create them as local vars:

var/savedx = M.x
var/savedy = M.y
var/savedz = M.z

M.loc = locate(savedx,savedy,savedz)


The same goes for the HP var. But why are you setting HP to the old monster's HP anyway? The old monster was dead. If you set the new monster's HP to the old monster's, your new monster will be dead too. Kinda defeats the purpose of respawning. =)
In response to Crispy
Nope, still nothing. I think I might be calling it wrong, but I don't know. Here's the modded Respawn code and deathcheck where it is called.

mob
proc
Respawn()
if(src.HP <= 0)
var/savedx = src.x
var/savedy = src.y
var/savedz = src.z
var/oldtype = src.type
del(src)
spawn(20)
src = new oldtype
src.loc = locate(savedx,savedy,savedz)
src.HP = src.maxHP


Deathcheck
mob
proc
DeathCheck(mob/M)
if(src.HP <= 0)
if(src.client)
src << "<font color = red>You have been killed by [usr]!</font>"
usr << "<font color = red>You killed [src]!</font>"
world << "<font color = red>[src] has been killed by [usr]</font>!"
src.loc = locate(48,48,2)
src.HP = src.maxHP
src.MP = maxMP
usr.EXP += src.EXPGive
else
Respawn(src)
In response to Pyro_dragons
Simplest respawn would be;
mob/var/origloc
mob/Monsters
New()//When a new monster is created
src.origloc=src.loc//Save its origloc

mob/proc/Deathcheck(mob/M)
if(src.hp<=0)
if(!src.client)
//do your stuff here
sleep(600)//Change this to whatever
src.loc=src.origloc
In response to Mysame
Thanks, but I want to know what is wrong with mine and why nothing is happening, even when it all checks out.
In response to Pyro_dragons
Because you're deleting src, thus the proc ends. Just do M.loc=null, and then bring it back :/