ID:175323
 
I get a runtime error when throwing granades. The runtime error is this

runtime error: Cannot read null.player
proc name: Deathcheck (/mob/proc/Deathcheck)
usr: (/mob/PC)
src: (/mob/PC)
call stack:
(/mob/PC): Deathcheck(null)
Frag Granade (/obj/granade/Frag_Granade): Throw()


The DeathCheck works for all the other weapons such as guns and shotguns. When I compared the code the only thing that I would think causes the error would be this:

    for(var/mob/M in view(1))
M.health -= 40
M.Deathcheck()


Thank you for your time.
You've shown us the wrong proc. Your problem is in DeathCheck(), so show that.

I suspect however that you should change view(1) to view(1,src), but without seeing more of that proc I don't know for sure.

Lummox JR
In response to Lummox JR
Thats ok...I managed to fix the problem. You were right, the error was in the DeathCheck. Thank you
In response to SSChicken
ehh, well now I have yet another Deathcheack problem. It's another runtime error

runtime error: Cannot read 0.points
proc name: Deathcheck (/mob/proc/Deathcheck)
usr: 0
src: SSChicken (/mob/PC)
call stack:
SSChicken (/mob/PC): Deathcheck()
RBotBlast (/obj/shot/RBotBlast): Bump(SSChicken (/mob/PC))

I have no clue where the error might be. Well except that it might be in the DeathCheck proc....I hope.

Here is my deatcheck..


mob/proc/Deathcheck()  
if(!usr.client)//If the attacker is NOT a player
if(!src.client)//If the defender is NOT a player
del src//Simply Delete Him

else//If the defender is a player
if(src.health <= 0)
src<<"You were killed by [usr]"
src.deaths += 1
src.killsinrow = 0
src.loc = locate(1,1,1)
src.health = src.maxhealth
else//If the attack is a player
if(!src.client) //if the Defender isnt a player
if(src.health <= 0)
oview(6) << "[src] was killed by [usr]"
usr.points += 50
usr<<"You got 50 points for this kill"
usr.kills += 1
usr.killsinrow += 1
usr.maxhealth += 5
del src
else
return

else //If the Defender is a player
if(src.health <= 0)
src << "You were killed by [usr]"
oview(6) << "[src] was killed by [usr]"
var/pointstoget
src.points /=2
pointstoget += src.points
pointstoget += usr.kills
pointstoget += usr.killsinrow * 2
pointstoget += src.killsinrow / src.deaths
src.killsinrow = 0
pointstoget += src.kills / 2
usr.points += pointstoget
usr<<"You got [pointstoget] points for this kill"
src.deaths += 1
usr.kills += 1
usr.killsinrow += 1
usr.maxhealth += 10
src.killsinrow = 0
usr.loc = locate(1,1,1)
src.health = src.maxhealth
else
return
In response to SSChicken
No, don't use "usr" in procs. Even in a Death(), instead use arguments in place of usr. Such as:
mob
proc
Death(mob/M)
if(M.client)
if(M==src)
world<<"[M] has killed himself!"
else
world<<"[src] has killed [M]!"


Hope this helps.
In response to Goku72
Well the runtime proc has changed to this:

runtime error: Cannot read null.client
proc name: Deathcheck (/mob/proc/Deathcheck)
usr: 0
src: (/mob/PC)
call stack:
(/mob/PC): Deathcheck(null)
RBotBlast (/obj/shot/RBotBlast): Bump( (/mob/PC))

Now my coding looks like this:

mob/proc/Deathcheck(mob/M)  
if(!src.client)
if(!M.client)
del M

else
if(M.health <= 0)
M<<"You were killed by [src]"
M.deaths += 1
M.killsinrow = 0
M.loc = locate(1,1,1)
M.health = M.maxhealth
else
if(!M.client)
if(M.health <= 0)
oview(6) << "[M] was killed by [src]"
src.points += 50
src<<"You got 50 points for this kill"
src.kills += 1
src.killsinrow += 1
src.maxhealth += 5
del M
else
return

else
if(M.health <= 0)
M << "You were killed by [src]"
oview(6) << "[M] was killed by [src]"
var/pointstoget
M.points /=2
pointstoget += M.points
pointstoget += src.kills
pointstoget += src.killsinrow * 2
pointstoget += M.killsinrow / M.deaths
M.killsinrow = 0
pointstoget += M.kills / 2
src.points += pointstoget
src<<"You got [pointstoget] points for this kill"
M.deaths += 1
src.kills += 1
src.killsinrow += 1
src.maxhealth += 10
M.loc = locate(1,1,1)
M.health = M.maxhealth
else
return




Thank you for trying to help, now at least I know where the error might be.
In response to SSChicken
I can see where one of your problems may lay in, the run-time error is saying usr: 0 that means there is no usr. Which in turn means no client, so that's why client is returning as "null".
In response to SSChicken
SSChicken wrote:
Well the runtime proc has changed to this:

runtime error: Cannot read null.client
proc name: Deathcheck (/mob/proc/Deathcheck)
usr: 0
src: (/mob/PC)
call stack:
(/mob/PC): Deathcheck(null)
RBotBlast (/obj/shot/RBotBlast): Bump( (/mob/PC))


By the sounds of it you forgot too tell Deathcheck what M equals. You have to set M by calling Deathcheck(what_your_attacking)
In response to DarkView
Ok...I changed it around...now by bump looks like this:

    RBotBlast
icon_state = "RBot"
density = 1
Bump(mob/PC/Defender)
if(istype(Defender))
Defender<<"You're being shot at by the Red Bot!"
Defender.health -= 20
src.Deathcheck(Defender)


and the only difference in the deatchcheck() is that all the "M" are changed to mob/Defender..and the beginning looks like this...

mob/proc/Deathcheck(mob/Defender)


I get a compile error:

Weapons.dm:643:error:src.Deathcheck:undefined proc