ID:142953
 
Code:
mob/var/KOed = 0
proc
KOcheck(mob/M)
if(M.health<=0)
M.canmove=0
M.KOed=1
view(6)<<"[M] has been knocked out."
sleep(60)
if(M.NPC==0)
M.canmove=1
M.KOed=0
var/half = M.maxhealth/2
M.health = half

mob/verb/Finish(mob/M in oview(1))
set category = "Combat"
if(M.KOed==1)
if(M.NPC==1)
del M
else
M.loc=locate(10,10,1)
M.deaths+=1
world<<"<b>[src] has killed [M].</b>"
Finaldeathcheck(M)


Problem description:

So I tested out the "Finish" on one of my NPCs, and it worked, but a few seconds later I got this runtime error:

runtime error: Cannot read null.NPC
proc name: KOcheck (/proc/KOcheck)
usr: Div (/mob)
src: null
call stack:
KOcheck(null)
Div (/mob): Attack(null)
i dont the npc code here, nor do i see the variable that uve defined for npc.

it might be something as simple as maybe youve defined npc under the npc class only, but you need to put it like this
mob
var
NPC = 0
NPC
NPC = 1
that will make all npc's have NPC = 1 and then all others have NPC = 0

i dont think this thing is the exact cause, but it maybe part of something too.

also, it is the npc, and not a player that was in range when u did this right?
In response to Superbike32
NPCs have an NPC variable of 1
Players have a variable of 0

And yes, I killed an NPC.
In response to GohanIdz
Make sure the mob isn't being deleted before you send the KOCheck. And you may want to think about changing view(6) to view(6,M).

The problem is in your attack verb, not either of those, but you should have a line in there making sure there is a mob before it attempts to do anything to it.
In response to Feenux
The attack verb?

mob/verb/attack(mob/M in get_step(usr,dir))
set category="Combat"
set name="Attack"
if(usr.stamina>=5)
if(usr.canattack==1&&M.KOed==0)
usr.stamina -= rand(0,4)
M.health-=usr.atk
KOcheck(M)


What's wrong with it?
In response to GohanIdz
Ha, fixed it ^_^.

I just put the sleep(60) in the finish verb after the if(M.NPC==0) instead of before it, and now there's no runtime error.
In response to GohanIdz
That would not fix the error (unless if you moved the sleep(60) to the very end of the proc, in which case you've removed the error but also broken your functionality). The error occurs because, during those 6 seconds, M is killed and deleted (by another attack). Thus, the variable M becomes null and you get an error why you try to access its variables. The best way to fix this problem would be to make the KOcheck() proc belong to a mob. When the mob is deleted, all of its procs will stop, including KOcheck. So, you'd change it to mob/proc/KOcheck(), replace M with src, and call it as M.KOCheck() instead of KOCheck(M).
In response to Garthor
The way I did it seemed to have worked though. I've tested it with NPCs and players, and it seems to work correctly.

mob/verb/attack(mob/M in get_step(usr,dir))
set category="Combat"
set name="Attack"
if(usr.stamina>=5)
if(usr.canattack==1&&M.KOed==0)
usr.stamina -= rand(0,4)
M.health-=usr.atk
view(6)<<"[usr] attacks [M] for [usr.atk]."
usr.exp+=rand(0,10)
KOcheck(M)
if(usr.exp>=usr.maxexp)
levelup(usr)



mob/var/KOed = 0
proc
KOcheck(mob/M)
if(M.health<=0)
M.canmove=0
M.KOed=1
view(6)<<"[M] has been knocked out."
if(M.NPC==0)
sleep(60)
M.canmove=1
M.KOed=0
var/half = M.maxhealth/2
M.health = half
In response to GohanIdz
That will not fix the error. The reason you haven't gotten any errors is because you did not properly reproduce the conditions. You need to delete the mob during the 6 seconds they are knocked out. In order to reproduce this error now, you're going to want to have the second player log out immediately after they are knocked out.

...which is actually likely to produce an altogether worse error, in fact.
In response to Garthor
Yeah, I tried fixing it and I jacked up all kinds of stuff now.

One problem is that after getting KOed, you can still move x_x

mob/verb/attack(mob/M in get_step(usr,dir))
set category="Combat"
set name="Attack"
if(usr.stamina>=5)
if(usr.canattack==1&&M.KOed==0)
usr.stamina -= rand(0,4)
M.health-=usr.atk
view(6)<<"[usr] attacks [M] for [usr.atk]."
usr.exp+=rand(0,10)
M.KOcheck()
if(usr.exp>=usr.maxexp)
usr.levelup()


mob/var/KOed = 0
mob/proc
KOcheck()
if(src.health<=0)
src.canmove=0
src.KOed=1
view(6)<<"[src] has been knocked out."
if(src.NPC==0)
sleep(60)
src.canmove=1
src.KOed=0
var/half = src.maxhealth/2
src.health = half


Please help me ;-;