[ACS] Randomly-Spawning Trees in Outdoor Sectors?[SOLVED]

Archive of the old editing forum
Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. This forum is archived - please use this set of forums to ask new questions.
User avatar
P.Rex
Posts: 54
Joined: Sun May 15, 2016 12:32 pm
Preferred Pronouns: She/Her

[ACS] Randomly-Spawning Trees in Outdoor Sectors?[SOLVED]

Post by P.Rex »

Hey guys,
I've been trying since yesterday to implement a script that would randomly spawn BigTree objects in all outdoor sectors (i.e. sectors that use the ceiling texture "F_SKY1") whenever I run its pk3 file, so that I wouldn't have to individually edit each map to add more trees. Unfortunately, so far I couldn't get it to work.

I've been basing it on a script made by Vincent(PDP) a few years back:

Code: Select all

Script "TreeSpawn" OPEN
{
    //The count variable will be how many things you want to spawn. Let's say 64.
    For(Int count=64; count>0; count --)
    {
        Bool Worked = False;
        Int Tries = 0; //Amount of times it has tried to spawn a thing
       
        While(Worked == False)
        {
            Int randX = Random(-32767.0, 32767.0); //All coordinates must end with .0 since they have to be fixed point
            Int randY = Random(32767.0, -32767.0);
			Int randZ = Random(-4096.0, 4096.0); //Just some z coords...
            If(Spawn("BigTree", randX, randY, randZ, 3000+count, 0))
            {
                If(CheckActorCeilingTexture(3000+count, "F_SKY1") == True)
                {
                    Worked = True;
                }
                Else
                {
                    Thing_Remove(3000+count);
                }
            }
           
            Tries ++;
            If(Tries >= 512)
            {
                Worked = True;
            }
        }
    }
}
Please keep in mind that I'm a beginner to ACS so my abilities are rudimentary at best. You'd have to explain it slowly.
While we're at it, is it also possible to have the script destroy any tree item that was spawned on a floor with a liquid texture?
Last edited by P.Rex on Fri Aug 11, 2017 8:00 am, edited 1 time in total.
User avatar
gwHero
Posts: 360
Joined: Mon May 08, 2017 3:23 am
Graphics Processor: Intel with Vulkan/Metal Support
Location: The Netherlands

Re: [ACS] Randomly-Spawning Trees in Outdoor Sectors?

Post by gwHero »

Hi,

basically your script works, except there is one mistake: it will stop spawning trees after one was succesfully created.
So if you remove the line 'Worked = True;' following the sky check, it will keep trying until 512 attempts were made.
(this is because of the while loop that will end as soon as Worked is set True)

Apart from that, -32767.0 & 32767.0 are very large numbers; are your maps that large? If not, the chance that the trees will be spawned in a valid area, is pretty small.
The same goes for the -4096.0 Z coordinate; of course if you have many outdoor area's that deep, it's ok, but in my maps almost half of the attempts would be too far under the ground.

So I copied your script in a wad of mine, and changed it like this:

Code: Select all

Script "TreeSpawn" OPEN
{
    //The count variable will be how many things you want to spawn. Let's say 64.
    For(Int count=64; count>0; count --)
    {
        Bool Worked = False;
        Int Tries = 0; //Amount of times it has tried to spawn a thing
       
        While(Worked == False)
        {
            Int randX = Random(-2222.0, 2222.0); //All coordinates must end with .0 since they have to be fixed point
            Int randY = Random(-2222.0, 2222.0);
           //  Int randZ = Random(-4096.0, 4096.0); //Just some z coords...
            If(Spawn("BigTree", randX, randY, 0, 3000+count, 0))
            {
                If(CheckActorCeilingTexture(3000+count, "F_SKY1") == True)
                {
                   // Worked = True;
                }
                Else
                {
                    Thing_Remove(3000+count);
                }
            }
           
            Tries ++;
            If(Tries >= 512)
            {
                Worked = True;
            }
        }
    }
}
I commented out the the line after the If condition, changed 32767.0 to a much lower value (but that depends of course on your maps) and left out Z (so it becomes always zero). Another solution would be to raise 512 to a much higher value, but it's better to keep the values more in line with the actual sizes of your maps.

Anyway, after these changes, it worked for my map.
User avatar
P.Rex
Posts: 54
Joined: Sun May 15, 2016 12:32 pm
Preferred Pronouns: She/Her

Re: [ACS] Randomly-Spawning Trees in Outdoor Sectors?

Post by P.Rex »

Thanks for the help. Unfortunately, I've tested your script on the first Doom 2 map (since it has a nice outdoor portion) and still no dice. What am I doing wrong here?
User avatar
gwHero
Posts: 360
Joined: Mon May 08, 2017 3:23 am
Graphics Processor: Intel with Vulkan/Metal Support
Location: The Netherlands

Re: [ACS] Randomly-Spawning Trees in Outdoor Sectors?

Post by gwHero »

I was not completely right about the first script: I overlooked the first iteration, so my conclusion that it would spawn only one tree is not correct; however, the chance was far too low, even with the 64 iterations.

Don't know why it doesn't work on the original levels; I tested it in my own level. I will give it a try later.
User avatar
gwHero
Posts: 360
Joined: Mon May 08, 2017 3:23 am
Graphics Processor: Intel with Vulkan/Metal Support
Location: The Netherlands

Re: [ACS] Randomly-Spawning Trees in Outdoor Sectors?

Post by gwHero »

It's mostly a matter of chance, so you have to check the actual X, Y and Z ranges in the specific maps and see if the ranges will work at all.

I tested this code:

Code: Select all

#library "gentrees.acs"
#include "zcommon.acs"

Script "TreeSpawn" OPEN
{
    //The count variable will be how many things you want to spawn. Let's say 64.
    For(Int count=64; count>0; count --)
    {
        Bool Worked = False;
        Int Tries = 0; //Amount of times it has tried to spawn a thing
       
        While(Worked == False)
        {
            Int randX = Random(300.0, 3000.0); //All coordinates must end with .0 since they have to be fixed point
            Int randY = Random(1500.0, 4000.0);
            Int randZ = Random(-32.0, +200.0); //Just some z coords...
            If(Spawn("BigTree", randX, randY, randZ, 3000+count, 0))
            {
                If(CheckActorCeilingTexture(3000+count, "F_SKY1") == True)
                {
                   // Worked = True;
                }
                Else
                {
                    Thing_Remove(3000+count);
                }
            }
           
            Tries ++;
            If(Tries >= 512)
            {
                Worked = True;
            }
        }
		//delay(1);
    }
}
with MAP01 and the area with the chainsaw was already cluttered with trees.

Wat also could be wrong is: did you compile the script?
User avatar
P.Rex
Posts: 54
Joined: Sun May 15, 2016 12:32 pm
Preferred Pronouns: She/Her

Re: [ACS] Randomly-Spawning Trees in Outdoor Sectors?

Post by P.Rex »

Still not working. If it's not too much trouble, would you mind sending your PK3? It's probably a very small and stupid mistake on my part but I have no idea what it is.
EDIT: As far as number ranges go, I only need something that would reasonably cover all of the vanilla Doom 2 maps.
User avatar
gwHero
Posts: 360
Joined: Mon May 08, 2017 3:23 am
Graphics Processor: Intel with Vulkan/Metal Support
Location: The Netherlands

Re: [ACS] Randomly-Spawning Trees in Outdoor Sectors?

Post by gwHero »

Hi, no problem! I added my pk3. I have tested it only with MAP 1; LOL the number of trees was far too many :)
So I guess you have to check all the levels and choose the ranges wisely.
You do not have the required permissions to view the files attached to this post.
User avatar
P.Rex
Posts: 54
Joined: Sun May 15, 2016 12:32 pm
Preferred Pronouns: She/Her

Re: [ACS] Randomly-Spawning Trees in Outdoor Sectors?

Post by P.Rex »

It works! I had to tweak the numbers on the file you sent me, but now the trees are finally showing up- tested this on multiple levels. Thank you very much!
User avatar
gwHero
Posts: 360
Joined: Mon May 08, 2017 3:23 am
Graphics Processor: Intel with Vulkan/Metal Support
Location: The Netherlands

Re: [ACS] Randomly-Spawning Trees in Outdoor Sectors?[SOLVED

Post by gwHero »

My pleasure :) Have fun!

Return to “Editing (Archive)”