ID:171438
 
I want the monster to wander around aimlessly, but, when the monster sees a player, to walk up to the player and attack it. What is happening is all of the above, but, the monster keeps trying to walk away but cant, which says to me that the walkforever proc is still being called even though the monster has found a player to attack. Any ideas of how to stop this from happening?

Heres my code,

I have taken snippets of code from a couple of different demos, so please ignore most of the comments as most of em dont make sence any more!

mob/proc
attack(mob/M in oview(1))
var/dmg = rand(1,((M.powerlevel + M.strength) / src.defence) / 8)//make a random damage variable
if(dmg <= 1)
dmg = 1
return
view() << "<B>[src] attacks [M]</B>"//sends a attack message to the every 1 in view
M.HP -= dmg// takes away the person there attackings HP depending on the damage variable
M.DeathCheck(M)
mobattack(mob/M in oview(1))//this makes it so the user has the verb attack but can only be used when someone is next to him
var/dmg = rand(1,15)//make a random damage variable
if(dmg <= 1)
dmg = 1
return
view() << "<B>[src] attacks [M]</B>"//sends a attack message to the every 1 in view
M.HP -= dmg// takes away the person there attackings HP depending on the damage variable
M.DeathCheck(M)//sends deathcheck which is right below this*/

mob/monsters/EvilSaiyan//Defines a /mob/NPC
icon = 'male.dmi'
icon_state = "normal"
race = "NPC"
defence = 5
HP = 1000//different health than the main mob
Click()//When clicked
if(src in oview(1))
usr.attack(src)//attack!
else
return
proc/move()//Now, this proc handles NPC movement
for(var/mob/M in oview())//loops over all mobs in view
if(get_step_away(src,M,3))//checks distance
if(!M.client)//Not a player
continue//continues through the loop
else//Player
walk_to(src,M,1,2)//Move to the person
else//4-or-more spaces away
continue
spawn(20) move()//loops the proc after 2 seconds

proc/attackplayer()//Handles attacking
for(var/mob/M in oview(1))//Within one space this time
if(get_step_away(src,M,1))
if(!M.client)
continue
else
src.mobattack(M)//Calls the attack proc
else
return..()
spawn(20) attackplayer()
return
proc/walkforever()
while(1)
var/list/dirs = list(NORTH,NORTHEAST,NORTHWEST,SOUTHEAST,SOUTHWEST,SOUTH,EAST,WEST)
var/a = pick(dirs)
Walk(rand(1,10),a,8)
sleep(rand(10,50))

proc/Walk(Steps as num, Direction, Speed as num)
while(Steps)
Steps--
step(src,Direction)
sleep(Speed)

New()//When created
attackplayer()//Calls the procs for it
move()
walkforever()


Oh, and yes this is a DBZ game i am making,

Thanks in advance

Farkas
It's already broken, because you're using usr in procs. oview() and related procs have a default first argument of usr. You should use src instead.