Ok I have this code
/***
This is a simple little example of a combat system.
The cops are computer characters who go after and attack things.
The demo shows you how to have computer characters act on their own,
and how you can handle attack and defense variables and killing mobs.
It uses my EventLoop library to control how often NPCs do something.
[email protected]
***/
world
mob = /mob/blue_guy
turf
icon = 'floorgreen.dmi'
atom/movable
var
hit_points = 10
armor_class = 1
defense = 1
mob
hit_points = 20
var
strength = 5
next_action_time
action_delay = 10 // How long between actions for an NPC?
movement_probability = 50 // How likely to move in a lifecycle?
verb/attack(mob/victim as mob in oview(1))
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 0
// 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)
hit_points -= potential_damage
view(src) << "[attacker] hit [src] for [potential_damage] points damage!"
if (isDead())
view(src) << "[attacker] killed [src]!"
Die()
return
else
view(src) << "[attacker]'s attack bounces harmlessly off [src]."
proc/Die()
icon = 'skull.dmi'
proc/isDead()
if (hit_points <= 0)
return 1
return 0
mob/cop
icon = 'keystone.dmi'
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/cop) || 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/cop) || other_mob.isDead())
continue
view(src) << "[src] is going after [other_mob]!"
step_towards(src, other_mob)
action_taken = 1
if (action_taken)
return
// No one around, so do the default behavior.
..()
mob/blue_guy
icon = 'Lwen.dmi'
strength = 10
GOto the Death Porc how do I make it show that icon and then warp back to start and retrave my orgigional icon and stats!!
ID:266673
May 17 2002, 2:04 pm
|
|
if (src.hit_points <= 0)
src.loc = locate(1, 1, 1) //Change this to where you want dead people to respawn
src.hit_points = src.maxhit_points
Try That If I Doesn't Work Reply Me.
Shun Di