ID:150484
 
After a week of trying various combinations for this code, it just isn't working at all. If anyone can give me any help as to make it work, please reply.
The problem with it is - When the monster is SUPPOSED to kill you, it dies instead.

mob
var
lifecycle_delay = 10
movement_probability = 50

mob
Click()
if (src.friendly == 1)
usr << "This is [src]."
else
if (usr.combatmode == 1)
FightStuff()
..()
else
usr << "You must enter combat mode before fighting [src]."

mob
proc
FightStuff()
if (src in oview(1))
var/damage = rand(usr.matk,usr.atk)
damage -= src.def
if (damage < 0)
damage = 0
usr << "You attack [src] for [damage] damage!"
oview() << "[usr] attacks [src] for [damage] damage!"
usr << "[src] has [src.HP] HP remaining."
src.HP -= damage
DeathCheck()
..()
else
usr << "This is [src]."
..()

mob
proc
DeathCheck()
if (src.HP <= 0)
usr << "You have slain [src]!"
usr.XP += src.XP
usr.totalXP += src.XP
usr << "You have gained [src.XP] experience!"
LevelCheck()
del (src)
..()

mob
proc
pdc()
if (s.HP <= 0)
world << "[usr] HAS BEEN SLAIN BY A MONSTER!"
if (usr.level <= 15)
usr << "You cannot lose experience if you are level 1-15! ;)"
usr.loc = locate(59,54,1)
usr.HP = usr.maxHP
else
usr << "You lose one quarter your experience."
usr.XP = (usr.XP / 4)
usr.loc = locate(59,54,1)
usr.HP = usr.maxHP

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
mob
proc
Attack(mob/victim)
var/potential_damage = rand(src.matk,src.atk)
victim.TakeDamage(src, potential_damage)

TakeDamage(mob/attacker, potential_damage)
var/defense_modifier = src.def
potential_damage -= defense_modifier

if (potential_damage > 0)
view(src) << "[attacker] hit [src] for [potential_damage] points damage!"
src.HP -= potential_damage
pdc()
else
view(src) << "[attacker] does no damage to [src]."

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

mob/monster
New()
..()

spawn(rand(10))
LifeCycle()
return

LifeCycle()
if (client)
return

var/action_taken

for (var/mob/other_mob in oview(1, src))
if (istype(other_mob, /mob/monster))
continue

Attack(other_mob)
action_taken = 1

for (var/mob/other_mob in oview(3, src))
if (istype(other_mob, /mob/monster))
continue

step_towards(src, other_mob)
action_taken = 1

if (action_taken)
spawn(lifecycle_delay)
LifeCycle()
return
behavior.
..()

mob
proc
LifeCycle()
if (client)
return
if (prob(movement_probability))
step_rand(src)

spawn(lifecycle_delay)
LifeCycle()</0>
Gynax wrote:
After a week of trying various combinations for this code, it just isn't working at all. If anyone can give me any help as to make it work, please reply.
The problem with it is - When the monster is SUPPOSED to kill you, it dies instead.

You are using usr all over the place when you shouldn't be. In so many places that it's hard to tell which all cause the problems. usr means "the last player to use a verb", and you are frequently using it to mean "this object". Instead, use src to mean "this object". And pass in the other mob/player as an argument to each function instead of using usr.

Rewrite this to remove every case of usr unless it's in a verb, then you'll have a fighting chance.
In response to Deadron
Ah... okay. ;) I'll try that.