Below is a function which calculates the distance between two objects.You can use it to make for example a monster attack you depending on how close you are.It is generally for beginners and uses pythagoras' theorem.
function distance(obj1,obj2)
dist=sqrt(((object position x(obj1)-object position x(obj2))*(object position x(obj1)-object position x(obj2)))+((object position z(obj1)-object position z(obj2))*(object position z(obj1)-object position z(obj2))))
endfunction dist