ID:1088885
 
(See the best response by Jemai1.)
Code:
proc/AIattack(mob/A as mob in view(3))
if(src.dir==SOUTH)
if(A.loc==locate(src.x,src.y-1,src.z))
// world<<"test2"
var/dmg
flick(src,"punch")
dmg=src.Strength-A.Defense
A.Stamina-=dmg
A.BanditAIkill()


Problem description:
Everything is fine, but when it calls this proc, it says can't read null.loc?
Where are you calling this proc?
Well, you have not assigned a value for A so it will give you that error.

Quick fix:
proc/AIattack()
var/mob/A = locate() in get_step(src,dir) // get the mob in front of you
if(A)
flick("punch",src)
var/dmg = Strength - A.Defense
A.Stamina -= dmg
A.BanditAIkill()
proc/AIattack()
var/mob/A = locate() in get_step(src,dir)
if(A)
flick("punch",src)
var/dmg=Strength-A.Defense
world<<"[src] hits [A] for [dmg] damage!"
A.Stamina-=dmg
A.Death()


Okay, it works a little bit, but it's attacking itself and hitting things 4 times.
proc/BanditAInucleus()
var/delay = 10
var/fightdelay=30
src.step_size=4
for(var/mob/Player/M in view(3))
src.targets=M
world<<"Test"
if(get_dist(src,src.targets)<=2)
world<<"hey"
walk_to(src,src.targets)
spawn(fightdelay)
src.AIattack()
else
walk(src,M)
src.targets=null
step_rand(src)


Proc that is calling the AIattack
In response to Aisukagee
for(var/mob/m in oview(3))//remove the center turf and it's contents, so not to include itself.
[actions]
break//break here so it only attacks the one mob at a time, and not every mob in oview(3).
proc/BanditAInucleus()
var/delay = 10
var/fightdelay=30
src.step_size=4
for(var/mob/M in oview(3))
src.targets=M
world<<"Test"
if(get_dist(src,src.targets)<=2)
world<<"hey"
walk_to(src,src.targets)
spawn(fightdelay)
src.AIattack()
else
walk(src,M)
src.targets=null
step_rand(src)
break


@NNAAAAHH

It runs to me, attacks me and itself once, then walks away?
Best response
Aside from the algorithm given by NNAAAAHH, you would be better off with bounds_dist instead of get_dist since you are using pixel movement.

Also, pass the target as a parameter of AIattack proc.
proc/AIattack(mob/A)
// stuff

Call that with
src.AIattack(your_target_here)


Take note that you should be using oview(3,src)
Thanks, it works now.