ID:262329
 
Code:
proc/grp_walk(list/Mobs,turf/Trg)
var/Size = Mobs.len
var/DivideNum = 2
for(var/i=2 to 100)
if(isloc(locate(Trg.x+round(Size/i,1),round(Trg.y+Size/i,1))))
DivideNum = i;break
var/list/New_Locs = block(locate(Trg.x,Trg.y,Trg.z),locate(Trg.x+round(Size/DivideNum,1),round(Trg.y+Size/DivideNum,1),Trg.z))
for(var/i=1 to Size)
walk_to(Mobs[i],New_Locs[i])


Problem description:

Well I am making a proc that makes a group of mobs move to a turf's location. But I'm having trouble making them all find good locations on the map. Anyone know how to fix this?

-Ryan
Hey,

I'm not sure what you mean by good location on map. But if your talking about a random location where there is not another dense obj or mob, try this:
proc/grp_walk(list/Mobs)
for(var/mob/M in Mobs)
var/goodspot=1
var/turf/T
START
T=locate(rand(minX,maxX),rand(minY,maxY),rand(minZ,maxZ))
for(var/atom/A in view("1x1",T))
if(A.density==1)
goodspot=0
break
if(goodspot)
M.loc=locate(T.x,T.y,T.z)
else
goodspot=1
goto START

Depending on the size of your maps you can set min/max X,Y,Z variables accordingly.