ID:270581
 
Ok, this code works good and everything but I have tried like a thousand times to try to get rid of the "Wander" Part but still have the monster attack if it sees something in its view, and i have been unsuccessfull. I was hoping someone could help me?
mob/monster
Kangaroo
icon = 'Monster3.dmi'
icon_state = " "
gold = 150
HP = 200
MHP = 200
player = 0
Str = 106
Def = 106
Expg = 5462
level = 90
monster = 1
PK = 1
NPC = 0
Del()//When it's going to be deleted
if (prob(4)) //50% Chance of going onto to dropping the helmet.
var/obj/equipment/head/Knighthelmet/K = new //Make a new
K.Move(src.loc)//Move it to the Kangeroo his location
..() //Do the normal

New()
. = ..()
spawn()
Wander()
proc/Wander(var/mob/You/P)
while(src)
if(P in oview(5))
step_towards(src,P)
for(P in oview(1))
break
for(P in oview(2))
break
for(P in oview(3))
break
for(P in oview(4))
break
else
step_rand(src)
sleep(5)
for(P in oview(5))
break
sleep(5)
spawn(5)
Wander()
Bump(mob/M)
if(M.player == 1)
Fight(M)
else
return
proc/Fight()
for(var/mob/E in get_step(usr,usr.dir))
var/damage = src.Str
E.HP -= damage
E << "[src] attacks you for [damage] damage!!"
src<<"You attack [E] for [damage] damage!!"
UserDcheck(E)
Click()
if(usr.pet == 1)//if you have a pet
if(usr.target == src)//and this monster is already your target
usr.target = ""//make your target blank
usr << "[src] is no longer your target."//get rid of that target
else//or if you don't have a target
usr.target = src//make it your target
usr << "[src] is now your target.. get your pet ready, foo!"
I also forgot, if I didn;t include some codes you may need to figure out how to fix it, feel free to pos that and I will give it to you.
Instead of having the monster continually look for a player to attack (a loop you're currently starting in New) have the player alert the monster when she comes in range. There's a great many ways to do this, but the simplist might be to alert everyone in viewers(src) everytime the player moves:
monster
var
sleeping = TRUE
movement_delay = 10
mob/target
max_alone_time = 20
New()
.=..()
wake(null)
proc
wake(var/mob/waker)
sleeping = FALSE
if(!target)
target = waker
if(!target)
target = locate(/mob) in oview(src)
advance()
advance(var/alone_time = 0)
if(!target)
target = locate(/mob) in oview(src)
if(!target)
step_rand(src)
if(alone_time >= max_alone_time)
sleeping = TRUE
return
else
alone_time = 0
step_to(target)
spawn(movement_delay)
/* spawn is nessesary so we don't overload the
call stack and crash the proc, something
that probably happened with your sleeping loop.*/

advance(alone_time++)
player
Move()
.=..()
for(var/mob/sleeper in viewers(src))
if(sleeper.sleeping)
sleeper.wake(src)

There are several huge problems with the above code, one of them being that the woke monster will target any mob. Unless you have very tired monsters with exams in the morning, they generally shouldn't attack their own kind. You'll probably want to make a 'find_target' proc for your monsters.

---

Better systems could include waking up an entire z level (or maybe just an area or room) when the player enters, and puting that area back to sleep when the player exits. Because the waking/sleeping procs would only be called when the player entered or exited the area (instead of everytime the mob moves), it could substancially cut down on processor time.