ID:169914
 
I was just wondering if there is a way to restrict the user from moving out of the distance of, lets say an object?

For example I want it so the user cannot move out of 8 squares from anyone of their soldier. This is the code I have so far but I just cant seem to get it to work. All it does is stick the users mob on the spot and continually print "Out Of Range" to the screen.


mob
Move()
if(src.selected == 1)
if(src.action_points > 0)
src.action_points -= 1
usr.APRefresh()
..()
else
world << "Not enough AP for this action!"
else
for(var/mob/soldier/M in world)
var/dist = get_dist(src, M)
if(dist > 8)
src << "Out Of Range"
step_towards(src,M)
else
..()


Any help anyone?

Thanks in advance

- GunRunner
replace the client procs South() SouthEast() East() ... and check whether you allow the movement.

if (get_dist(a, b) < limit) . = ..()
In response to Sven van Bolt
You know I realised I should try that just after I clicked the submit button and loe and behold, It works! Thanks to you anyway!


- GunRunner
In response to Sven van Bolt
That'd be dumb. Just use Move().

var/list/Players[]
var/Move_Limit=8
mob/Move()
if(Players&&Players.len)
for(var/i in Players)
if(get_dist(src,i)>=Move_Limit)
return
..()