ID:155182
 
ive been coding for somewhat a while i thought i was turning into a good coder but once again lack of knowledge hit me in the back of my head

anyways i cant get my codes to work my question to you:
"How do i make grass spawn and randomly have or not have a tree on it?"

basicly just how do i make a tree randomly spawn on grass
You can try a for() loop and then have a rand() with like... a random chance(1/10 depending how big your map is) for a new Tree on G.

for(var/turf/Grass/G in world)
var/obj/Tree/T = new //or whatever your path is for a Tree
var/X = rand(1,10)
if(X==3)
T.loc = locate(G.x,G.y,G.z)

In response to Kenny84
Or he could just spawn them randomly in the turf's New() proc, without running the additional loop.

Also, that code is kind of redundant in a lot of places.

turf/grass
New()
..()
if(rand(1,10)==1)
new obj/tree(src)

In response to Robertbanks2
You can use prob(10) to roll for a 10% chance. No need to use rand() like that. (rand() can be used for this purpose of course, but prob() is a bit more straight-forward when reading over the code)
In response to Robertbanks2
Robertbanks2 wrote:
Or he could just spawn them randomly in the turf's New() proc, without running the additional loop.

Also, that code is kind of redundant in a lot of places.

>
> turf/grass
> New()
> ..()
> if(rand(1,10)==1)
> new obj/tree(src)
>
>


Welp, I guess I get a bit of help on learning too ^^
I should have thought of that, though :/
In response to Robertbanks2
thanks for the help :)