mob/enemy
var
spawnloc
damage
mob/target = null
proc/AI()
while(!target)
step_rand(src)
if(get_dist(src,spawnloc >= 5))
step_towards(src,spawnloc)
sleep(10)
while(target)
sleep(5)
src.dir = get_dir(src,target)
step(src,dir)
if(get_dist(src,target) == 1)
if(target.dir == "EAST")
if(src.dir == "EAST")
step(src,NORTHEAST)
src.dir = get_dir(src,target)
if(src.dir == "WEST")
step(src,NORTHWEST)
src.dir = get_dir(src,target)
if(src.dir == "SOUTH")
step(src,NORTHEAST)
src.dir = get_dir(src,target)
if(src.dir == "NORTH")
step(src,SOUTHWEST)
src.dir = get_dir(src,target)
if(get_dist(src,target) == 1)
target.takedamage(damage,src)
else
step_towards(src,target)
target.takedamage(damage,src)
step_away(src,target)
New()
spawnloc = src.loc
AI()
Problem description:
The code says that as long as the mob has no target, just walk within 5 blocks of your spawning point. Unfortunately, no enemies follow this behavior, and I cannot figure out the cause of it. I've tried specifically setting target to null, but that doesn't seem to work, either. Please help with this issue, thank you.
Also, a similar mob in the game is coded with almost the exact same principle, and it works fine:
mob/muggle/var/seenmagic = 0
mob/muggle/Officer
icon = 'npc.dmi'
icon_state = "officer"
var/mob/criminal
proc/AI()
while(!criminal)
step(src,EAST)
sleep(5)
step(src,EAST)
sleep(10)
step(src,WEST)
sleep(5)
step(src,WEST)
sleep(10)
while(criminal)
sleep(5)
step_towards(src,criminal)
if(get_dist(src,criminal) == 1)
criminal.locked = 1
view(src) << "<b>[src]:</b> That's it! I'm taking you to the station!"
criminal = null
New()
AI()
Though, I don't see any point where you are looking for a target.