mob/proc/AI()
for(var/mob/M in view(5))//within 5 steps
if(!M.key) return //dont attack if not player
else
if(get_dist(src,M) > 1)//if farther than one
step_to(src,M)
else
src.attack()
mob/proc/attack(mob/M)
if(src.str-M.def <=0)
view(2,src)<<"[M] has dodged [src]'s attack!"
sleep(5)
else
var/crit=rand(1,15)
var/critdamage=(src.str-M.def)*3
var/damage=(src.str-M.def)+rand(-M.lvl,M.lvl)
if(crit==1)
M.hp-=critdamage
M<<"[src] critically hit you for [critdamage]"
M.deathcheck()
else
M.hp-=damage
M<<"[src] hit you for [damage]"
M.deathcheck()
mob
New()//when a mob is created
sleep(20)
if(!src.key)//if it's not human
AI()
..()
else
..()
mob
icon='Enemies.dmi'
CircleDemon
icon_state="CircleDemon"
hp = 50
str = 7
def = 10
lvl=10
gold=40
Problem description:
This is a quick piece of code i put together in a couple minutes trying to pursue a slightly usable AI code(which i never could do) but the mobs just sit there and dont move :(
Second, return is the wrong thing to have in that loop. You want "continue" to make it skip to the next mob in the list, rather than return which ends the entire proc.
Third, you don't have a loop there. You need to wrap the whole body of the AI() proc in a while(src) or something of that sort.
Fourth, after making AI() into an infinite loop, you'll want to use spawn() to call it in a separate thread (just "spawn() AI()" instead of "AI()") so it doesn't prevent New() from finishing.
Fifth, you aren't passing an argument to attack(). It should be attack(M) when you call it.