ID:140678
 
Code:
obj
bullet
icon = 'Bullet.dmi'
density = 1
New()
spawn(100)
del src
Bump(A)
if(ismob(A))
var/mob/M = A
if(M == src.owner)
del src
return
var/mob/O = src.owner
var/damage = O.Dex * rand(1.3,1.9) - M.def
if(damage < 1)
damage = 1
if(O.pvp == 1)
if(M.pvp == 0)
return
else
M.health -= damage
O << "<b><font size = -2><font color = blue>You hit <u>[M]</u>: with your bullet! Doing [round(damage)] damage."
M << "<b><font size = -2><font color = blue>You have been hit by <u>[usr]'s</u> bullet for [round(damage)] damage!"
if(O.hollow_protection == 1)
if(M.race == "Jedi" || M.race == "Sith" || M.race == "Merc")
O.Sith_protection = 0
if(O.Jedi_protection == 1)
if(M.race == "Jedi")
O.Jedi_protection = 0
M.Death()
del src
if(O.pvp == 0)
if(M.client)
return
else
M.health -= damage
O << "<b><font size = -2><font color = blue>You hit <u>[M]</u>: with your bullet! Doing [round(damage)] damage."
M << "<b><font size = -2><font color = blue>You have been hit by <u>[usr]'s</u> bullet for [round(damage)] damage!"
if(O.Sith_protection == 1)
if(M.race == "Jedi" || M.race == "Sith" || M.race == "Merc")
O.Sith_protection = 0
if(O.Jedi_protection == 1)
if(M.race == "Jedi")
O.Jedi_protection = 0
M.Death()
del src
if(istype(A,/turf/))
var/turf/T = A
if(T.density)
del src
if(istype(A,/obj/))
del src


Problem description:
Okay, my problem is this, I can kill a mob with attack or slashing fine, my death check runs and they die. When I happen to use a blaster or any powers, it deals the damage but won't kill them. Above is the bullet that is created when firing a blaster. Below is the error it runs in the game.


runtime error: Cannot read 0.Mercref
proc name: Death (/mob/proc/Death)
usr: 0
src: X a o c T r o o p (/mob/Xaoc_Trooper)
call stack:
X a o c T r o o p (/mob/Xaoc_Trooper): Death(null)
the bullet (/obj/bullet): Bump(X a o c T r o o p (/mob/Xaoc_Trooper))
You should be using the letter O instead of the number 0.
The error is thrown from within Death(), which we can't see and can only guess at.

I will make such a guess. You are not passing any arguments to Death(), so I assume it doesn't have anything to do with incorrect parameters inside Death(), and the only other thing I can think of at the moment (without seeing Death()) would normally be that you're using usr in a situation where usr!=src (Death() belongs to the M from Bump(), so M will be src and is the appropriate owner of local variables/functions from Death()'s point of view), but the error says 0.Mercref, not null.Mercref.

Either way, whatever line of code is causing the error, you have "somevariable.Mercref" and the somevariable is equal to 0, not to an object with a Mercref field.

(Edit)
On the part where I was talking about it possibly being a usr issue - on second look, that is indeed the problem. I didn't even notice at first that the runtime error output actually says that usr is 0. So you're using "usr.whatever" in there, and usr=0. Why usr is 0 I don't even want to guess, but, as I said, usr isn't the correct thing to use in Death() anyway.
You are using usr in procs, which you should not be doing. To fix this, search the forum for "usr deathcheck" to find five hundred million instances of the same solution.
In response to Garthor
:P I got it fix, I can't believe I made this mistake. Thanks a bunch to you helped, but now I am having a problem with something else inside this code. It kills them now, and what not, but now it spams me with an error in the game for running a Levelcheck(), is there some way to fix this or go around it?

Sorry for posting on my company name :P.
In response to Nenja Gaming
The first step would generally be to share the error and relevant code with us.
In response to Garthor
runtime error: Cannot read null.Exp
proc name: Levelcheck (/mob/proc/Levelcheck)
usr: 0
src: Krim (/mob)
call stack:
Krim (/mob): Levelcheck(null)
R a t (/mob/Creatures/Rat): Die(Krim (/mob))
the blue fire (/obj/blue_fire): Bump(R a t (/mob/Creatures/Rat))
runtime error: Cannot read null.Exp
proc name: levelcheck (/mob/proc/levelcheck)
usr: 0
src: Krim (/mob)
call stack:
Krim (/mob): levelcheck(null)
R a t (/mob/Creatures/Rat): Die(Krim (/mob))
the blue fire (/obj/blue_fire): Bump(R a t (/mob/Creatures/Rat))


This is the runtime error I get after killing a mob with a tech.

                if(src.race == "Rat")
M.Ratskilled += 1
src.loc = locate(0,0,0)
M.Exp += 4
M << "<b><font size = -2><font color = white>You gain 4 Experience from defeating a <u>Rat</u>!"
M.Levelcheck()
M.levelcheck()
sleep(165)
src.New()


This is part of the death code where is runs the two levelchecks I have emplemented in the code. What would anyone suggest here?
In response to Nenja Gaming
You need to pass the proc an argument.

http://www.byond.com/docs/guide/chap06.html