ID:141687
 
Code:
            Bump(atom/M)
if(isturf(M)) // If whatever the head bumps is a turf..
owner.kame = 0 // Allow the owner to fire another beam
owner.icon_state = "" // Give them their default icon_state
owner.move = 1 // Allow them to move
for(var/obj/O in src.Beam) // Checks for objects in the Head's Beam list...
del(O) // Deletes any objects found
del(src) // Deletes the head
else if(ismob(M)) // If whatever the head bumps is a mob...
view(src.owner) << "[src.owner]'s beam hits [M]!" // For all in the owner's view, gives a message
M:powerlevel-= M:ki
usr.DeathCheck(owner,M)
owner.kame = 0 // Allows the owner to fire another beam
src.owner.icon_state = "" // Sets them to their default icon_state
owner.move = 1 // Allows them to move
for(var/obj/O in src.Beam) //For all objects in the Head's Beam list...
del(O) //Delete any objects found
del(src) // Delete the head
else
if(!ismob(M) && !isturf(M) && !isobj(M) && !isarea(M))
owner.kame = 0 // Allow the owner to fire another beam
owner.icon_state = "" // Give them their default icon_state
owner.move = 1 // Allow them to move
for(var/obj/O in src.Beam) // Checks for objects in the Head's Beam list...
del(O) // Deletes any objects found
del(src) // Deletes the head


mob
proc
DeathCheck(mob/M)
if(M.powerlevel<=0&&M.npc)// if the hp's 0 and its a NPC.
world<<"<font color=red>[src] has killed [M]</font>"/// say theyve killed M
src.exp+=M.exp
del(M)///delete the npc frm the world cuz its dead
src.Level()// call the lvl proc
return/// stop runtime errors =D
if(M.powerlevel<=0&&M.client) // if hp 0 and its a client.
world<<"<font color=red><B>Player Death:[src] has been killed by [M]</B></font>"// same as before
M.powerlevel=M.powerlevel_max//give them full hp back.
M.loc=locate(180,18,1)//take them to spawn point, dont DEL them.
src.exp+=src.powerlevel// give them exp!!
src.Level()/// call lvl proc


Problem description: My Death Check don't work. When I try to kill a npc on my game it says error and more errors:

runtime error: Cannot execute null.DeathCheck().
proc name: Bump (/obj/Beams/Head/Bump)
usr: 0
src: Head (/obj/Beams/Head)
call stack:
Head (/obj/Beams/Head): Bump(Vegeta (/mob/npc/Vegeta))
Head (/obj/Beams/Head): Move(Sand (183,22,1) (/turf/Sand/Sand), 8)

What is wrong with my code?


1. :(colon operator) abuse. 99.9% of the time, use typecasting, it's safer.
else if(ismob(M))
var/mob/hit=M //hit refers to M.
//This only works if M is a mob, which it is due to the conditional above.
//"hit" will have all mob variables, allowing you to access them.


2. usr abuse. usr doesn't exist in the context you're calling DeathCheck() with. usr is extremely unsafe, 98% of the time.


Bottom line: use owner.DeathCheck(M).


I'm not sure where all you new programmers learn about the : operator. Experimentation? Just DO NOT use it. :)
In response to Kaiochao
Oh thanks a lot, it worked.
In response to Kaiochao
99.9% of the time, use typecasting, it's safer.

If you want to, you can always use it. Tou could create a datum with the variables of built-in datums that aren't meant to be messed with (appearances, for example) and then type cast the whatever as that datum.

appearance
var
icon
icon_state
list/overlays
list/underlays
pixel_x
pixel_y
//there are probably more, I don't know all of them

mob/verb/Overlay_icons()
for(var/X in overlays)
var/appearance/A = X
src << A.icon
In response to Jeff8500
Indeed.

Jeff8500 programmed:
> appearance
> var
> list/overlays
> list/underlays
> pixel_x
> pixel_y
> //there are probably more, I don't know all of them


You can't actually use those. >_>
>        for(var/X in overlays)
> var/appearance/A = X
> src << A.icon
>

And for that I'd just use the 'as' keyword to override the type, you don't actually need a secondary variable.
for(var/appearance/A as anything in overlays)
In response to Kaioken
Ah, I don't use as much. And as for the overlays/underlays and pixel offsets thing, Lummox JR has said that they do have those vars.
In response to Jeff8500
Not in accessable form as far as we're concerned, though.