ID:1249649
 
mob
Enemy
var
health=100
attack_power=10
target=null
move_delay=10
attack_delay=10

canhit=TRUE


//If we need to find a target, find one

proc/FindTarget()
var/got_target=FALSE

if(src.target != null && src.target in view(8))
got_target=TRUE
Goto_Target()
else
target=null

if(!got_target)
for(var/mob/player/Player in view(3))
target = Player
got_target=TRUE
break

sleep(10)
FindTarget()

//After we find a target, we call this to make the mob go to the target
proc/Goto_Target()

step_to(src, target)

//Hit Stuff
if(canhit && src.target in get_step(src, get_dir(src, src.target)))
world << "[src] attacks [src.target]"
AI_Hit_Cooldown()

sleep(move_delay)
FindTarget()

proc/AI_Hit_Cooldown()
canhit=FALSE
spawn(attack_delay)
canhit=TRUE

//When an enemy is created
New()
FindTarget()

//Mobs below + their stats
Blob
icon='Icons/Enemies/Blob.dmi'
//Blob stats
attack_power=3

So right now, I have that.. I think it could be better optimized in techniques I don't know yet. I think it's actually pretty important in case i have a lot of mobs.. I'm just curious on better ways of creating AI targeting + movement.
I don't think New() ever returns because it looks like FindTarget() never returns. You should do:

New()
spawn FindTarget()


instead.
You may also want to call the parent procedure there in New() as well.
More context is required to say if inherited New behavior is necessary, and the context shows that New doesn't do anything after FindTarget that could be kept from happening.

It would be better to use ohearers() instead of view() in this case, and don't forget to give it src instead of let it use usr by default.