ID:1032837
 
Code:
mob
monsters
Move(var/turf/NewTurf,var/StepDir) //Move() is built-in
switch(StepDir)
if(NORTHWEST) pick(step(src,NORTH),step(src,WEST))
if(NORTHEAST) pick(step(src,NORTH),step(src,EAST))
if(SOUTHWEST) pick(step(src,SOUTH),step(src,WEST))
if(SOUTHEAST) pick(step(src,SOUTH),step(src,EAST))
else return ..(NewTurf,StepDir)
New(/**/)
spawn(-1) src.CombatAI(/**/)
return ..(/**/)
MouseEntered(/**/)
src.AddName(/**/)
MouseExited(/**/)
for(var/I in src.overlays)
src.overlays-=I
proc
CombatAI()
while(src)
for(var/mob/player/M in oview(/**/))
if(get_dist(src,M)<=1)
src.dir=get_dir(src,M)
else
step_to(src,M)
break
sleep(rand(4,8))
EarthMonsters
icon='Monsters_1.dmi'
Rabbit
icon_state = "Rabbit"
race = "Rabbit"
hp=10
maxhp=10
level = 11
exp = 172
dodge=1


Problem description:
My goal was to prevent AI from walking diagonally. But the problem is that when monster is facing client(player) it could be diagonally sometimes. Any help would be appreciated!

Not sure if this work, but just a suggestion D:
var/next_dir = get_dir(src,M)
switch(next_dir)
if(NORTHEAST){src.y+=1;sleep(5);src.x+=1}
if(NORTHWEST){src.y+=1;sleep(5);src.x-=1}
if(SOUTHEAST){src.y-=1;sleep(5);src.x+=1}
if(SOUTHWEST){src.y-=1;sleep(5);src.x-=1}

EDIT
I also, think it shud be placed under the Combat_AI() procedure
        proc
CombatAI()
while(src)
for(var/mob/player/M in oview(7))
if(get_dist(src,M)<=1)
src.dir=get_dir(src,M)
var/next_dir = get_dir(src,M)
switch(next_dir)
if(NORTHEAST){src.y+=1;sleep(5);src.x+=1}
if(NORTHWEST){src.y+=1;sleep(5);src.x-=1}
if(SOUTHEAST){src.y-=1;sleep(5);src.x+=1}
if(SOUTHWEST){src.y-=1;sleep(5);src.x-=1}
else
step_to(src,M)
break
sleep(rand(4,8))


It works, but if you go down or up while monster is facing you he will teleport right in the middle of the player icon :)
if(NORTHEAST){step(src,NORTH);sleep(5);step(src,EAST)}
if(NORTHWEST){step(src,NORTH);sleep(5);step(src,WEST)}
if(SOUTHEAST){step(src,SOUTH);sleep(5);step(src,EAST)}
if(SOUTHWEST){step(src,SOUTH);sleep(5);step(src,WEST)}

I believe this will work, since it auto-detects collision when using step(), in other words, if there is an obj with density. It'll actually collide
When monster is facing player, he starts to move North, East or West randomly.
Bump :/