ID:174358
 
Hello, again. Sorry to be such a pain. I want my person to be placed in a random place between X 10 and 40, and Y 10 and 40, so I put this:
        var/Y = rand(10,40)
var/X = rand(10,40)
src.loc=locate(X,Y,1)

And this bit works, but I also want it so that if it ISN'T grass he doesn't get placed there, so I put this:
        for(var/turf/T in world)
if(istype(T,/turf/Grass))
var/obj/O = new /obj/Town_Center/
O.loc = T.loc

But he still, sometimes, gets placed on water or others! Please help!

~GokuSS4Neo~
Gokuss4neo wrote:<code> > var/Y = rand(10,40) > var/X = rand(10,40) > var/turf/T > while (!istype(T,/turf/grass)) > T=locate(X,Y,1) > src.loc=T</code>
In response to Crispy
Now, sometimes, but not always, my Dreamseeker freezes when I run it, before I can even see the map!

~GokuSS4Neo~
In response to Gokuss4neo
It's probably just taking ages to find a /turf/grass. Now that I think of it, this way is better:

<code>src.Move(locate(/turf/grass) in block(locate(10,10,1),locate(40,40,1)))</code>

This will take the nearest available /turf/grass in the given block() and move the player there. If you want it to be completely random, you'd have to get the block(), put it in a list, remove all non-grass turfs from the list, and use pick() to select a turf to move to.
In response to Crispy
They always appear on the same block, and I don't know how to do the stuff you said to make it random. Can anyone recommend a demo or help file?

~GokuSS4Neo~
In response to Gokuss4neo
Like I said, it'll take the nearest available spot. If you log in several people on different keys, you'll notice them lining up next to each other.

I was hoping I wouldn't have to do the code for you, but so much for being lazy. =P Step by step, then:

<code>//Okay, so first we need to get the block(). As block() returns a list, we need to make a list var to hold it. var/list/blocklist=block(locate(10,10,1),locate(40,40,1)) //Now we have the turfs in our blocklist, but we need to make sure they're all /turf/grass. To remove everything else, we can loop through the list like this: for (var/turf/T in blocklist) if (!istype(T,/turf/grass)) //Looks like this isn't a grass turf! So remove it from the list, like this: blocklist -= T //Now we can use the handy pick() proc to take a random entry from our list, and move the player there. All in one line now, here we go! src.Move(pick(blocklist))</code>

Not too hard once you break it up into steps, yeah? =)
In response to Crispy
Thank you Crispy, you rock!

~GokuSS4Neo~