ID:141646
 
Attack Code:
        Attack(mob/M)
set src in oview(1)
var/damage
damage = (M.attack - src.defence) * (M.level - src.level)
if(damage <= 0)
damage = 0
src << "[M.name] misses you!"
if(prob(10))
M << "You miss!"
src << "[M.name] misses you!"
else
M << "You attack [src.name] for [damage]!"
src << "[M.name] attacks you for [damage]!"
src.health -= damage
Dead()


Dead Code:
mob
proc
Dead(mob/M)
if(M.health <= 0)
oview() << "[M.name] died from [src.name]!"
if(client)
alert("Died")
if(!client)
del M


Problem description:

I get this Runtime error when I attack the mob:

runtime error: Cannot read null.health
proc name: Dead (/mob/proc/Dead)
usr: (/mob)
src: Demi Hollow (/mob/Demi_Hollow)
call stack:
Demi Hollow (/mob/Demi_Hollow): Dead(null)
Demi Hollow (/mob/Demi_Hollow): Attack(Demi Hollow (/mob/Demi_Hollow))
That's a very confusing (for me) and bad way to code an attack verb...

set src in oview(1) isn't used for that purpose. And that mob/M arg in the verb definition has no specifications so it can be ANY mob ANYWEHRE. I may be wrong about why it's bad, but it's bad nonetheless. If you want to attack anyone around the usr of the verb....

mob/verb/Attack(mob/M in oview(1,usr))
//... Take out the set src in oview() line


If you want to only attack a mob 1 step in FRONT of the usr...

mob/verb/Attack(mob/M in get_step(usr,usr.dir))
//... Again take out the set src in oview() line >_>
Frankly, this is a very basic, self-explanatory beginner error. Did you spend some time debugging and reading through the code trying to solve it? As long as you know the language (if you don't, I suggest going through the DM Guide), you should catch that immediately with a simple quick read through the code.
The variable (argument) M in your Death() proc is set to null, not an object, and therefore when the code tries to access M's health variable, it errors up since there is no object to access a variable of. This problem is rather clearly caused by you calling the proc without supplying any argument, so Death() starts up with M as null.

Other problems in the code include, as Ketsu said, a rather wrong and backwards management of the verb in regards to attacker and victim, and how you reference them. As far as I can see it, a player running the verb will not attack himself at all - rather, the verb will be available when the player is next to a mob (presumably), and when ran a popup box will ask him to choose another mob in the world, then that mob he is next to will be attacked by the mob he chose in the input box... quite messed up.
You also have 'hidden usr abuse' in your oview() call in Death(); you're not supplying any argument for the center, so it uses the default value which is usr. Very similar thing in the alert(). Also, checking a condition (client) twice like you have is pretty silly; rather, you check it once, then use the else statement to do something else in the case the condition was not true.
Try this code

mob/proc/Attack(mob/M in get_step(usr,usr.dir))
var/damage= (M.attack - src.defence) * (M.level - src.level)
if(damage <= 0)
damage = 0
src << "[M.name] misses you!"
if(prob(10))
M << "You miss!"
src << "[M.name] misses you!"
else
M << "You attack [src.name] for [damage]!"
src << "[M.name] attacks you for [damage]!"
src.health -= damage
Dead(M)// before it was Dead() which passed an empty argument to the Dead Proc





Dead(mob/M)
if(M.health <= 0)
oview() << "[M.name] died from [src.name]!"
if(client)
alert("Died")
if(!client)
del M
In response to Rapmaster
Rapmaster wrote:
Try this code

mob/proc/Attack(mob/M in get_step(usr,usr.dir))
> var/damage= (M.attack - src.defence) * (M.level - src.level)
> if(damage <= 0)
> damage = 0
> src << "[M.name] misses you!"
> if(prob(10))
> M << "You miss!"
> src << "[M.name] misses you!"
> else
> M << "You attack [src.name] for [damage]!"
> src << "[M.name] attacks you for [damage]!"
> src.health -= damage
> Dead(M)// before it was Dead() which passed an empty argument to the Dead Proc
>
>
>
>
>
> Dead(mob/M)
> if(M.health <= 0)
> oview() << "[M.name] died from [src.name]!"
> if(client)
> alert("Died")
> if(!client)
> del M
>
>


Wouldent it be:
     Dead(src)

Instead of (M)?
In response to Hi1
my bad typo and yes
In response to Rapmaster
Okay, thanks!
In response to Rapmaster
You shouldn't spoon feed people unless they're totally stuck.

"Give a man a fish and he'll eat for the day. Teach a man to fish and he'll eat for a lifetime."

Or until the fish run out ;p Whichever comes first ^-^
In response to Mizukouken Ketsu
I learnt how to code by being 'spoon fed' sooo im returning the favour to the community.

You dont have to teach them to reinvent the wheel you know.
In response to Rapmaster
You don't truly learn by being spoon fed. You learn how to do that specific code if not how to just copy and paste then modify slightly to fit the purpose rather than the whole concept.