ID:142375
 
Code:
    proc
AosLoop()
if(src.client)return
var
list/piv
mob/attack
while(Health>0)
piv = list()
while(piv.len<=0)
if(walks)
step_rand(src)
sleep(wspeed)
for(var/mob/m in oview(1))
if(m.client&&m.key)
piv+=m
attack=pick(piv)
while(get_dist(attack,src)<=view)
if(get_dist(attack,src)==1)
var/dmg=rand(mdmg,Mdmg)-attack.def
if(dmg<0)
attack<<"[name] has attacked you,but missed you!"
sleep(aspeed)
attack<<"[name] has attacked you for [dmg] damage!"
attack.Health-=dmg
attack.Death(src)
sleep(aspeed)
else
step_towards(src,attack)
sleep(wspeed)
if(walks)
step_rand(src)
sleep(wspeed)


Problem description:

hi, how can i make it so that the monster can only move when it gets attacked, so its standins till untill someone attacks it then it runs after it.
Don't call the proc until they are attacked.

You'll also have to change oview(1) to oview(src,1) or you'll get logic errors.
In response to Garthor
Actually, it's oview(1,src). I did it the other way around and it didn't work out too well. When I used to forget stupid things like that, I check the DM Reference. It's very useful in case you forget something or are looking for a built-in proc to shorten your code.
In response to Kaiochao
oview() actually works either way. Don't know why you had problems with it.