ID:143323
 
mob
enemy
proc
Wander() // This is going to be the proc where it walks around, or looks for the enemy.
while(src) // While we still exist
sleep(5) // Change this depending on how fast you want the enemy to move
for(var/mob/Player/M in oview(10)) // If there is a player around 10 spaces...
src.Target = M // It sets it to its target
break
if(src.Target) // If we have a target..
// var/mob/Player/
if(src.HP<Target.HP) // If our HP is less then the Players HP...
var/Rand = rand(1,10) // Picks a number from 1 to 10
if(Rand>=8) // It has a 80% chance to run away
step_away(src,Target) // Runs away from the Player..
sleep(1)
step_away(src,Target)
sleep(1)
step_away(src,Target)
else
step_towards(src,Target)

else // If not though...
step_towards(src,Target)

else // If there isnt a Target....
step_rand(src) // We step randomly...


Problem description:I tried on of my own, lots of demos, this one seems to be the best, the problem is that it doesnt accepts Target, i tried whit M but doesnt work... so im asking for a very simple chasing proc...

you might want a sleep at the end of the while() or else your game will crash.
In response to Kakashi24142
He already has a sleep() call, that isn't his problem.
You're calling step_rand() every fifths of a second if there's no target.
In response to Kaiochao2536
It's ~half a second. sleep(10)=1sec. Besides, what you wrote is obviously quite intended behavior. By the one who wrote that code, at least.
In response to Kaioken
btw whats the need for a target variable? Why not continue coding in the loop and adding breaks?
In response to Kakashi24142
Uh, so he can go towards/away from the intended target/reference, it is shown like that in the snippet...
In response to GhostAnime
You can do the same by continuing with the loop.
mob
enemy
proc
Wander() // This is going to be the proc where it walks around, or looks for the enemy.
while(src) // While we still exist
sleep(5) // Change this depending on how fast you want the enemy to move
var/action=0
for(var/mob/Player/M in oview(10))
if(src.HP<M.HP)
var/Rand=rand(1,10)
if(Rand>=8)//you're saying you want any number that's 8,9,10 out of 10 so you just might want to do if(prob(30)) which returns 1 at a 30% chance.
step_away(src,M)
sleep(1)
step_away(src,M)
sleep(1)
step_away(src,M)
action=1
break
//maybe you should use walk_away()?
else
step_towards(src,M)
action=1
break
else
step_towards(src,M)
action=1
break
if(!action)step_rand(src)

The problem could be that Target is not a variable that represents a mob, it should be defined like this:
mob/enemy/var/mob/Player/Target

This could possibly be the problem although I'm not 100% sure.