ID:162577
 
How can I confine a group of mobs to an area, so that they don't wander aimlessly through the entire map?
proc/getArea(atom/A)
if(!isatom(A)) return null
while(A && !isarea(A))
A = A.loc
return A

mob
var/leashed = false
New()
..()
if(leashed)
//get the area we are in
leashed = getArea(src)
Move(var/atom/newloc)
if(!leashed || getArea(newloc) == leashed)
//allow normal movement only if we aren't leashed
//or the movement won't leave our leashed area
return ..()
else
return 0


Any mob with its leashed variable set to true will be restricted to the area it is created in. If you wish to change the leash, then you'll need to set it to a new area. Keep in mind that the mob cannot move while outside its area at all. This will result in a bit of silly behavior, like a mob being stuck at an invisible wall. It will also let players exploit this so that they can lure a mob to an area boundary and then plink away at it with no (or reduced) risk.
mob/var/areaGroup //set this to the area type (and subtypes) to allow this mob passage through that area
area
Enter(mob/M)
if(M.areaGroup && !istype(src,M.areaGroup)) return 0
return ..()


-- Data
In response to Android Data
Which is silly and annoying. You would be forced to define, in your code, subtypes of each area that you want to restrict mobs to, instead of creating new instances using the map editor. In addition, that would allow a mob that is forced into an area (for whatever reason) to continue moving around in it, which may be undesirable (I'd rather have a broken monster standing around than a monster tearing through newbies, personally).