ID:141151
 
Code:
        Deathcheck()
if(attackable==1)
if(mob==1)
if(src.hp <= 0)
view() << "[src] dies!"
src.hp = maxhp
src.Move(locate(5,14,1))
usr.hp += 1
usr.str += 1
usr.def += 1
else
if(src.hp<=0)
view()<<"[src] dies!"
usr.hp+=1
usr.str+=1
usr.def+=1
usr<<"You gain 1 hp!"
usr<<"You gain 1 Strength!"
usr<<"You gain 1 Defence!"
del(src)
src.New(locate(5,14,1))
else
usr<<"You can't attack [src]!"
return


Problem description:</b

the problem is that when i kill the npc, after waiting, he doesnt respawn.. please help.
First problem: you should not be using usr in procs. Instead, pass a variable for who the killer is, like so:

mob
var/hp = 1
proc
deathcheck(mob/killer)
if(src.hp <= 0)
world << "[killer] killed [src]"
killer.highfive()

highfive()
src << "HIGH FIVE!"

verb
kill(var/mob/M)
M.hp = 0
M.deathcheck(src)


Searching the forum for "deathcheck" will probaby result in about five to ten thousand very good examples of the proc (and some bad ones, but you can tell those are bad because there will be responses saying "that is bad").

As for your respawning problem, your first issue is that New() is not a proc that you should be calling. To create a new object, you use the new() command, like so:

new /obj/thingy(loc)


If you wish to create something of the same type, then you can use:

new src.type(loc)


Second, the line before it: del(src) will always end the current proc (unless you've played silly buggers with the variable). The object is deleted and so all of its procs end as well (hence, you get no "src does not exist" errors when they attempt to continue). In order to circumvent this, the simplest thing to do is to move del(src) to the last line. Another alternative is to call an external proc like so:

proc/respawn(var/type, var/loc, var/time)
//use spawn() instead of sleep() so the proc calling us does not have to wait for us to finish
spawn(time)
new type(loc)

mob/zombie/proc/die()
respawn(src.type, loc, 100)
del(src)


This allows the respawn to not be instant.
Just to answer the question easily;

When deleting src (which is who the whole proc is about), the proc stops.

Easy fix;
...
usr<<"You gain 1 Defence!"
Respawnmob(src.type)
del(src)

proc/Respawnmob(mobtype)
spawn(/*respawn time*/)
new mobtype(locate(5,14,1))


In response to Mysame
That won't work. You can't use an instance as the type for creating something, and besides, M is null because it's been deleted. You'd need to pass its type to Respawnmob(), or grab its type in the first line of Respawnmob().
In response to Garthor
Editted. Wasn't aware it would pass through as null. You mean after or even before the spawn() ?
In response to Mysame
When an object is deleted, all references to it everywhere are automatically nulled out (which helps prevent problems) by DM internal behavior. This means while your initially-called proc would have a reference to the mob, after that proc ends that mob is deleted, and afterward your queued 'spawned' code runs, with null where the mob reference was, as it was cleared out when the mob was deleted just before.
Obviously, not that it matters whether you still have a dangling reference or not, the object is deleted anyway, and so you can't access data of it (so "backup"ing it beforehand is required). To illustrate, code like this-
mob/verb/Test()
var/obj/O = new
BGProc(O)
del O

proc/BGProc(o)
spawn(X) //X could be 0 or greater
if(o) world << "I've an object!"
else world << "I've null!"

Executes as follows:
*/mob/verb/Test() is executed. A new obj is created.
*Test() calls BGProc(), so execution moves to that proc.
*BGProc() is executed. It queues a new "thread" to run some statements after a (short) delay. The proc then ends, and returns.
*Since BGProc() returned, the point of execution shifts back to Test(). It runs and deletes the obj. Then it returns.
*Because there are no more immediate pending functions to run, a proc just finishes, and It's Time (the delay given passed),
the queued 'spawned' code runs. At this point the obj that used to be stored in 'o' has of course already been deleted, so 'o' is null.

EDIT: Linebreak, zomg!
In response to Kaioken
Cheerios.

So that's the final fixed version of the code, I guess. Bit messy but meh.

Ps; Didn't realize I had actually fixed the before code. Lol.
In response to Mysame
The one you already posted in your edited earlier post was a little better. >_> Also, I don't think it's messy at all.