ID:145917
 
Code:

    
die(mob/M)
if(src.hp<=0)
if(src.key) //checks if it's a player
src.loc=locate(1,1,1) // locates the player back to the respawn point
src.hp = src.maxhp
src<<"You've died"
M.exp += src.maxexp/2
M.gold += src.gold / 2
else
M.gold += src.gold
M.exp += src.maxexp
del(src)
spawn(src.respawn) //Waits respawn amount
src.loc = origloc // Moves the monsters back to his original location


Problem description: Runtime, cannot read null.gold, though the src's (monsters) has 1 gold

i havnt coded in a long time but i believe the M.gold that M is not properly asociated with a character... if your character witch is if M is You then go to the world proc and add mob = /mob/Character then make a mob/character for a mob and it should work just make sure gold doesnt = 0 or bellow that could also be a problem!
In response to Cyanide
world
mob=/mob/create_char

So that's no prob.

PS/ M is the dying mob
If M is the dying mob, then why is the person dying getting money and exp? And why is it telling the attacker that they have died? You got something mixed up.


Edit:
Try this:
mob
proc
Die(mob/M)
if(src.hp<=0)
if(src.key) //checks if it's a player
src.loc = locate(1,1,1) // locates the player back to the respawn point
src.hp = src.maxhp
src << "You've died"
M.exp += (src.maxexp / 2)
M.gold += (src.gold / 2)
return 1
else
var/mob/NPC = new src.type
M.gold += src.gold
M.exp += src.maxexp
del(src)
spawn(NPC.respawn) //Waits respawn amount
NPC.loc = origloc // Moves the monsters back to his original location
return 1
In response to Y2kEric
Euuuhhhh, my bad, src is the one dying!!! Sorry T.T

(I still remember how (I think it was O-Matic) always told me using M as dying person was wrong, so I made it src o.o... Though the errors)
In response to Mysame
So, does the proc work?
In response to Y2kEric
nope... Dunno what's wrong though, my bet is that the mob/M has something faulthy in it
In your current code, I see src is the dying mob and M is the killer. This is correct; you should never write a death check any other way.

The reason you're getting a runtime error is that you're calling the proc incorrectly; you're calling it as victim.die() instead of victim.die(killer). M is null when the proc runs, hence the error.

Note you'll also need to use round() when adding things like gold/2 and maxexp/2. In fact you should also be sure to remove that half gold that was taken from the victim, or else you'll end up with a bit of an inflation problem.

Also in the monster death section, you've got some problems: del(src) is called before some other stuff, so that part of the proc will never run. And spawn() has nothing indented under it. Bear in mind also that anything you do with spawn() will not run once del(src) is called anyway, so I believe you'd want to replace del(src) with loc=null, and indent the last line.

Lummox JR
In response to Mysame
Mysame wrote:

(I still remember how (I think it was O-Matic) always told me using M as dying person was wrong, so I made it src o.o... Though the errors)

Really? I don't really remember saying that to you, I hardly know you!

I think you mean Lummox JR. As far as I know, he's the only one who's making people aware that they're not using Deathcheck() procs correctly.

O-matic
In response to O-matic
Sorry O-Matic, I tend to switch you 2 up.. :/

Anyways, this is what I've got now..
    die(mob/M)
if(src.hp<=0)
if(src.key)//checks if it's a player
src.loc=locate(1,1,1) // locates the player back to the respawn point
src.hp = src.maxhp
src<<"You were killed by [M]"
M.exp += round(src.maxexp/2)
M.gold += round(src.gold / 2)
src.gold = round(src.gold / 2)
src.exp = round(src.exp / 3)
else
M.gold += round(src.gold)
M.exp += round(src.maxexp)
src.loc = null
spawn(src.respawn) //Waits respawn amount
src.loc = origloc // Moves the monsters back to his original location


obj/var
dam

obj // ARCHER
Arrow
icon = 'IT.dmi'
icon_state = "IT"
density = 1
dam = 5
Bump(mob/M)
if(istype(M,/mob/))
if(!M.npc && M.pvp)
usr<<"You hit [M]!"
var/arrowdam = src.dam
M.hp -= arrowdam
M.die()
del(src)
if(!M.key)
usr<<"You hit [M]!"
var/arrowdam = src.dam
M.hp -= arrowdam
M.die()
del(src)
if(!M.pvp || M.npc)
del(src)
else
del(src)
-------------------------------------------------

mob/archer
verb
Shoot()
set name = "Shoot"
set category = "Skills"
if(usr.fire) return 0
//if(usr.bow)
if(usr.client)
fire = 1
var/obj/Arrow/A = new /obj/Arrow(usr.loc)
walk(A,usr.dir)
walk_to(usr,1,10)
sleep(15)
fire = 0


Since my attack verb is bugged, I've been using arrows to kill the monster. Now the error seems OBVIOUS because the arrows does not have a usr! Anyone know how to assign one to it?