ID:141348
 
Code:
mob
var
life = 100
strength
defence
proc
DeathCheck()
if (life <= 0)
world << "[src] dies a horrible, bloody death!" //give the death messaging
del src


Problem description:
In testing, people never die, they just move right on to negative health
Um, is the procedure even called?


You should modularize your program. Have a procedure like TakeHP(dmg = 0) which calls Deathcheck() after dealing damage.
In response to GhostAnime
mob
var
life
maxlife
strength
defence
proc
DeathCheck()
if(life <= 0)
return 1
else
return 0
verb
Attack(mob/Monster as mob in oview(1))
var/damage = (src.strength - Monster.defence)
if(damage <= 0)
damage = 1
Monster.life -= damage
view() << "[src] hit [Monster] for [damage] life!"
if(Monster.DeathCheck())
del Monster
view() << "[Monster] died!"
else
Monster.Monster_Attack(src)
proc
Monster_Attack(mob/Player)
var/damage = (src.strength - Player.defence)
if(damage <= 0)
damage = 1
Player.life -= damage
view() << "[src] hit [Player] for [damage] life!"
if(Player.DeathCheck())
Player << "You are dead!"
Player.loc = locate(1,1,1)
Player.life = Player.maxlife


mob/Login()
usr.icon = 'test.dmi'
usr.loc = locate(1,1,1)
usr.life = 50
usr.maxlife = 50
usr.strength = 7
usr.defence = 5

mob/monster
icon = 'test.dmi'
strength = 10
defence = 3
life = 20
maxlife = 20


Just a little test I ran. Works fine for me.
In response to ArcaneDragonX
While it works; Don't ever implement it that way. Hell, If you insist on using such a small deathcheck, why not stuff it in a DEFINE; Saves another function call..

I stand by GhostAnime's suggestion on AddHP(value,[CheckDeath?]) functions.
In response to Xeronage
Xeronage wrote:
While it works; Don't ever implement it that way. Hell, If you insist on using such a small deathcheck, why not stuff it in a DEFINE; Saves another function call..

I'd advise using #defines for the rather more abstract (like mere calculations) or small-time operations that don't effect much in the world. Something like a DeathCheck() is better done with an object proc to be tidier and take advantage of OOP (not to mention these can easily be more complicated than a single if() statement). Here are some classic examples of utilizing OOP with DeathCheck() (also splitting the proc into an also-recommended Die() proc).
mob/person
var/HP
var/deaths,kills
var/player_kills /*,player_deaths */
...
proc/DeathCheck(mob/person/killer,attack_type,...)
if(src.HP <= 0)
src.Die(killer)
return 1
proc/Die(mob/person/killer,announce=1)
if(announce)
world << "[killer] has killed [src]!"
src.deaths++
killer.kills++
player
Die(mob/person/killer)
..() //do the above, original actions
//AND also some player specific behavior:
killer.player_kills++
//(not setting loc directly is recommended, but this proc isn't included :P)
src.Relocate_To(locate("respawn_area") || locate(1,1,1))
src.Heal() //restore HP,MP...
monster
var/loot_drop = /obj/item/gold
Die()
..()
/*monsters have special behavior upon death;
they are deleted, and they leave corpses and loot*/

new /obj/item/corpse(src.loc,src) //create a corpse of src...
new src.loot_drop(src.loc)
del src
vampire
DeathCheck(killer,atk_type)
if(atk_type == EXORCISM_ATTACK)
..()
//vampires can only be killed by a specific finishing attack!
immortal_dude
Die()
viewers(src) << "[src] falls down, then rises back up again."
//no calling ..() - this mob never dies!


I stand by GhostAnime's suggestion on AddHP(value,[CheckDeath?]) functions.

Same here, so consider it Thirded. ;D One proc that sets HP (up/down) and then makes sure it's within bounds (could be optional with an argument) is much more robust and flexible, and is also a useful hook.