Author Topic: How do I place bricks when a player is close to a fall?  (Read 892 times)

Like in a terrain generator, if you walk into or stand in a non-generated area, it generates the area. How do I do that?
« Last Edit: March 18, 2012, 06:14:54 AM by Axolotl »

there are actually quite a few ways to do this but depending on what you're trying to do the best method may change

The way you want probably involves creating bricks within a certain radius of the player.

I'm know there are a couple of terrain generators you can poke around through that do this, ill just throw in my terragen mod, mostly because I can't think of any others at the moment that are public.
http://dl.dropbox.com/u/20459676/client_terragen.zip

Start looking through the terragen_tick function, specifically line 230

Am I the only one who read the OP completely?

Quote
if you walk into a non-generated area, it generates the area

I don't see this text anywhere:
Quote
if you stand near a non-generated area, it generates the area

Am I the only one who read the OP completely?

I don't see this text anywhere:
Yeah, I want the bricks to generate when a player stands or walks into a non-generated area.

I'm know there are a couple of terrain generators you can poke around through that do this, ill just throw in my terragen mod, mostly because I can't think of any others at the moment that are public.
http://dl.dropbox.com/u/20459676/client_terragen.zip

Start looking through the terragen_tick function, specifically line 230
It's a little too complex because I don't know what the functions do.

Can I please have a standalone code that places 4x4f bricks in a flat plane when I stand or walk into a non-generated area?
« Last Edit: March 18, 2012, 06:29:52 AM by Axolotl »


Am I the only one who read the OP completely?
He said "Like in a terrain generator", and was not too specific, so I assumed he was using it for a terrain generator. I also used the word "probably" in my post as an indicator that I wasn't completely sure what he was asking.

Ninja: Title also is "How do I place bricks when a player is close to a fall?"

It's a little too complex because I don't know what the functions do.

Can I please have a standalone code that places 4x4f bricks in a flat plane when I stand or walk into a non-generated area?

I'll walk you through the core process
Code: [Select]
//from the tick function, called constantly on a loop
for(%c=0; %c<terragen.adventurercount; %c++)
{
if(isobject(%b = terragen.adventurer[%c]))
{
%gpos = terragen_getgridpos(terragen_getplayerpos(%b));
%xi = getword(%gpos, 0);
%yi = getword(%gpos, 1);

for(%a=$terragen::radius*-1; %a<=$terragen::radius; %a++)
{
for(%b=$terragen::radius*-1; %b<=$terragen::radius; %b++)
{
%x = %xi + %a;
%y = %yi + %b;

if(!terragen.plangrid[%x, %y])
{
terragen_addgridbricks(%x,  %y); //adding mega meat...
}
}
}
}
else
terragen_remove(%c);
}
This loops through all players, and for each player it does another loop to determine if any grid spaces in a certain radius of them have not been set.  This will be the core of what you want.


Once you have determined that a grid space needs something on it, generate that grid space
The function terragen_addgridbricks(%x, %y) is alot more complicated than you need to worry about, because it also adds numerous little details and smoothing and stuff.  Basically once you know the xy coordinate, it should be pretty straightforward to figure it out on your own.