ID:149738
 
i have this code here
atom/movable
var
armor_class = 1
defense = 3


mob


var
next_action_time
action_delay = 10 // How long between actions for an NPC?
movement_probability = 30 // How likely to move in a lifecycle?

verb/attack(mob/victim as mob in oview(1))
if(!victim.isnpc)
src.Attack(victim)
else
src<<"You cannot attack [victim]!"



New()
// Start my action cycle at a random point, to keep cycles spread out.
next_action_time = world.time + rand(10)
return ..()


base_EventCycle(world_time)
/*
This function is called by the EventLoop library once per tick (1/10th a second)
to give me a chance to do something if I want.

I only want to do something if we've reached my next_action_time.
*/
if (next_action_time <= world_time)
if (isDead())
return

// Time to do whatever.
TakeAction()

// Set the next walk time.
next_action_time = world_time + action_delay


Move()
if (isDead())
// Can't move if I'm dead.
return 1

// I'm alive, so do the default movement proc.
return ..()


proc/TakeAction()
// If this is a player, do nothing.
if (client)
return

// By default just have them walk around.
if (prob(movement_probability))
step_rand(src)
return

proc/Attack(mob/victim)
var/potential_damage = strength
victim.TakeDamage(src, potential_damage)



proc/TakeDamage(mob/attacker, potential_damage)
// Can't kill me if I'm already dead.
if (isDead())
view(src) << "[attacker] hits [src]'s dead body!"
return

// Damage is reduced based on my armor class and defense.
var/defense_modifier = armor_class + defense
potential_damage -= defense_modifier

if (potential_damage > 0)
hp -= potential_damage
view(src) << "[attacker] hit [src] for [potential_damage] points damage!"
s_damage(usr ,potential_damage ,"red")
if (isDead())
view(src) << "[attacker] killed [src]!"
Die()
return
else
view(src) << "[attacker]'s attack bounces harmlessly off [src]."

proc/Die()
if(src.compute == 1)//its a monster
src.loc.contents += src.contents
src.icon = 'deadcop.dmi'
del(usr)
else
src.Move(locate(38,25,1))//here is DA PROBLEM
src.Health=usr.MaxHealth



proc/isDead()
if (hp <= 0)
return 1
return 0


mob/wolf
icon = 'wolf.dmi'
strength = 17
contents = newlist(/obj/Short_Sword,)
TakeAction()
var/action_taken

// Before moving, NPC cops see if there is someone to attack within 1 space.
for (var/mob/other_mob in oview(1, src))
// But don't attack if it's another cop or they are dead...
if (istype(other_mob, /mob/wolf) || other_mob.isDead())
continue

Attack(other_mob)
action_taken = 1

// No one to attack, so see if a non-cop is within 3 spaces to move toward.
for (var/mob/other_mob in oview(3, src))
if (istype(other_mob, /mob/wolf) || other_mob.isDead() || istype(other_mob, /mob/NPCS/Aracon))

continue

step_towards(src, other_mob)
action_taken = 1

if (action_taken)
return

// No one around, so do the default behavior.
..()

but whenever it does a death check it deletes the enemie even if they won and leaves the player there.
i can figure out why?
That's what happens when you have this line:

del(usr)
Mrhat99au wrote:
proc/Die()
if(src.compute == 1)//its a monster
src.loc.contents += src.contents
src.icon = 'deadcop.dmi'
del(usr)
else
src.Move(locate(38,25,1))//here is DA PROBLEM
src.Health=usr.MaxHealth

Skysaw has it right: The del(usr) line is wrong. The reason is that usr is the player who last used a verb or clicked something, while src is a monster in that case. If you successfully kill a monster, it will hit the del(usr) line and kill you instead.

However, you can't use del(src) right away either if you want to leave a corpse behind, so I suggest you do this:
src.loc.contents+=src.contents
new /obj/corpse(loc) // spawn a corpse here
del(src)

Lummox JR
In response to Lummox JR
yeah i know but is there a way to check whos dead not who used like if player kills other player it moves the dead player back to start and gives em full hp.
and if they are a monster it deletes them and drops contents