ID:141865
 
Problem description:
How do I make it so a user randomly spawns in one of the four corners of the map? (my map is 40x40)

If it's 40x40x1:
mob/proc/SpawnAtCorner()
x = pick(1, world.maxx)
y = pick(1, world.maxy)
In response to Popisfizzy
Thanks.

Another question: What's the code for spawning at a random turf?
In response to MaxPK
You can use lists containing each turf.
var/list/turfs=list()
//...
//add turfs to the list
//...
if(turfs.len) //if any turfs were added
var/turf/T=pick(turfs) //pick a turf from the list
loc=T



In response to Kaiochao
Or you know..

loc = locate(rand(1,40),rand(1,40),1)


In response to Andre-g1
Basically the same thing Pop said, except including everything in between..
I'd prefer to make invisible turfs of X type that are always spawn points. They can be placed anywhere.

var/spawn_count = 0

SpawnPoint
parent_type = /turf
var/number = 0

New()
spawn_count ++
src.number = spawn_count
tag = "spawnpoint_[src.number]"
..()

mob/proc/spawn()
var/turf/T
while(!T)
T = locate("spawnpoint_[rand(1, spawn_count)]")
if(!T.Move(src)) T = null


In response to Kaiochao
What about random spawning only at non dense turfs?
In response to MaxPK
I actually forgot about the block() procedure, and I used it in a project just yesterday :P

block() returns a list of turfs in a 3D "block" of space on the map.

So, using the way I said earlier...
var/list/turfs=block(locate(1,1,1),locate(40,40,1)) //All turfs within the block

//Below is the code to remove any dense turfs within the block.
for(var/turf/t in turfs) //for all the turfs in the list
if(t.density)//if the turf is dense,
turfs-=t //remove it from the list.
//---

var/turf/t=pick(turfs)
loc=t

Or if you want to check if there are any dense objects in the turf...
//The allclear() proc. Checks if a turf is undense and anything in it is undense.
turf/proc/allclear()
for(var/atom/t in range(0,t))if(t.density)return 0
return 1
//Just replace if(t.density) to if(!t.allclear()) in the example above.