These are commands i use to find the distance, it comes in 3 flavours.
`Gets distance between position (x,y,z) and (p,w,e)
function GetPPDist(x#,y#,z#,q#,w#,e#)
dist#=sqrt(((q#-x#)*(q#-x#)) + ((w#-y#)*(w#-y#)) + ((e#-z#)*(e#-z#)))
endfunction dist#
`Gets distance between position (q,w,e) and object obnum
function GetOPDist(Obnum,q#,w#,e#)
x#=Object position x(obnum)
y#=Object position y(obnum)
z#=Object position z(obnum)
dist#=sqrt(((q#-x#)*(q#-x#)) + ((w#-y#)*(w#-y#)) + ((e#-z#)*(e#-z#)))
endfunction dist#
` gets the distance between obnum1 and obnum2
function GetOODist(Obnum1,Obnum2)
x#=Object position x(obnum1)
y#=Object position y(obnum1)
z#=Object position z(obnum1)
q#=Object position x(obnum2)
w#=Object position y(obnum2)
e#=Object position z(obnum2)
dist#=sqrt(((q#-x#)*(q#-x#)) + ((w#-y#)*(w#-y#)) + ((e#-z#)*(e#-z#)))
endfunction dist#
So as anomer said if 'distance of enemy to player<enemyrange then turn enemy at character and move him towards player.