ID:179517
 
For some reason the concepts involving area have escaped me so far. What I want to do is place a mob randomly within an area after it dies.
I tried something like this but it just places them in the bottum left corner of the area.
M.Move(locate(/area/home))

If one of the libraries covers this just slap me and point me to it please. I looked through them but none of them seem to address this.
English wrote:
For some reason the concepts involving area have escaped me so far. What I want to do is place a mob randomly within an area after it dies.
I tried something like this but it just places them in the bottum left corner of the area.
M.Move(locate(/area/home))

By default an area puts you in the Southwest corner, as you've seen.

To put them somewhere random in there, you need to randomly choose a turf from within the area. Turfs are stored as part of the area's contents, so you can search through the contents for turfs and choose one to put the mob on.
In response to Deadron
Well, I figured it out. In the below code I used M3.Move(locate(T)) but that is supposed to be used to find the turf and I already have it! I changed it to M3.Move(T) and it seems to be working fine now. I haven't extensively tested it yet but so far so good. I'll just leave the code down below incase you still wanted to take a peak even though I think I fixed the problem.

[Edit]

Here's my attempt, it compiles fine, but it doesn't place the mob correctly. I put in testing statements so I know it's creating the mob, using the correct area, and seemingly the correct turf but it places the mob at (0,0,0) which is null right?:

spawnMob(var/mob/M,var/mob/M3) //M = dying mob, M3 = new mob
var/turf/T
var/area/A = M.spawnArea //spawnArea is aquired during Login
var
turfNum = 1 //position of turf in A.contents
var/mob/M2 = null //dummy variable for inner loop
for() //want it to run until it places mob
turfNum = rand(1,A.contents.len) //chooses random content of spawnArea
world << "[turfNum]" //just a check, gives valid number
if(isturf(A.contents[turfNum]))
T = A.contents[turfNum]
world << "[T.loc],[T]" //gives correct area and turf
else
world << "Restarting search" //if not turf, start over
continue
for(M2 as mob in T) //looks for mobs already on Turf
world << "[M2] is in [T]"
if(M2) //if there is a mob, stop looking
break
if(M2 == null && !T.density) //if there is no mob, and turf is not dense, move mob there
M3.Move(locate(T))
M3.spawnArea = M.spawnArea //transfers spawning info
world << "Moving [M3] to [M3.x],[M3.y]"
break //exit main loop
if(M3.loc == null) //if mob didn't get placed properly, delete it
del(M3)
del(M) //delete dying mob



I think the problem might be in the assignment of the Turf variable T.

T = A.contents[turfNum]

It looks right and compiles but this is a gray area for me so I'm not sure if it will actually make T that particular turf, or basically make T a copy of it.

Any other suggestions?

Just incase you wanted to know, this is what runs at Login time.

for(var/mob/M as mob in world)
M.spawnArea = M.loc.loc //location of mobs turf, which is area
world << "[M] is in the [M.spawnArea]" //just checking if it's working