attack(mob/M as mob in oview(1)) //attack a mob within 1 tile of you
oview() << "[usr] attacks [M]!" //send this message to everybody else
var/damage = rand(1, 10) * (usr.atk - M.def)
if(damage <= 0)
usr << "[M] easily dodges your attack!"
M << "You easily dodge [usr]'s attack."
else
M.HP -= damage
usr << "You attack [M] for [damage] HP!"
M << "[usr] attacks you for [damage] HP!"
M:DeathCheck()
if (M.HP >> 0)
oview() << "[M] counterattacks [usr]!" //send this message to everybody else
var/cdamage = rand(1, 10) * (M.atk - usr.def)
if(cdamage <= 0)
usr << "You easily dodge [M]'d attack!"
M << "[usr] easily dodge your attack."
else
usr.HP -= cdamage
usr << "[M] attacks you for [cdamage] HP!"
M << "You attack [usr] for [cdamage] HP!"
Problem description:
I can't figure out what's wrong with this code... it works fine without the second bit (If M.HP >> 0 and afterwards), but when I put it back in I get a runtime error that displays right before the enemy dies.
(
eg. bug with 15 HP
You attack the bug for 9 HP!
The bug attacks you for 8 HP!
runtime error: Cannot read null.HP
proc name: attack (/mob/verb/attack)
You attack the bug for 9 HP!
The bug was killed by Cinnamonspider
)
Sorry, I realize there are already threads on null runtime errors, I just can't seem to make much sense of any of them. :P
-Use
Attack(mob/M in get_step(usr, usr.dir)
instead of oview(1). This will attack only the monster that the player is facing.
-In this case it's better to use M.deathcheck(usr). Use a '.' instead of ':', and pass (usr) as an argument to the deathcheck, thus;
-Also do you seem to use
if(M.hp>>0)
The '>>' does nothing good. One '>' is enough. Thus;