• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[General] Create buildings and trees in random spots, but in the same region.

Level 11
Joined
Sep 11, 2013
Messages
327
Greetings!
I want to create in a specific region 2 gold mines and 2 trees. All 4 must be placed in random positions each time when the game start.
Now will be hard to explain..
In my map, I created another building for Gold mine just for custom pathing in order to achive only 1 entrence in gold mine. So the first problem is how to create those 2 gold mines in random positions in region, but with that second building around them for custom pathing.
The Only Entrance In Mine.jpg
The second problem.. I don't want bugs.. so if the first random point in region for gold mine 1 is very close to the seconds random point in region for gold mine 2, those 2 mines will be created one on top of another and i don't want that.
The last problem is the same, but with trees. I don't want to see trees on top of mines or one into another stuck.. or mines in top of trees etc..

Is there a way to solve those problems?:peasant-work-work:

The help will be appreciated! :peasant-bowing:
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,558
Seems easy enough, create the custom pathing objects first, then proceed to create a gold mine on top of each of them.

When creating your custom pathing objects you can use distance checks to prevent them from being too close to one another. It may also be wise to split up the map into multiple large regions which you can use to guarantee that the gold mines always spawn a decent distance away from one another.
 
Last edited:
Level 10
Joined
May 8, 2009
Messages
253
To avoid having trees on top of each other or on the gold mines I suggest to use the builder trick,
It goes like this:
You select a random point within the region and order a dummy builder to build a building that has same pathing as your trees (and with no cost) at this point.
Right after the order is given you check the current order of the unit. If it returns null it’s not pathable and if it returns something there’s room for the tree.
In both cases you remove the dummy builder since you don’t want to build anything and only actually create the tree if there’s room.
You can loop this many times as it’s not heavy on performance.
 
Level 11
Joined
Sep 11, 2013
Messages
327
Seems easy enough, create the custom pathing objects first, then proceed to create a gold mine on top of each of them.

When creating your custom pathing objects you can use distance checks to prevent them from being too close to one another. It may also be wise to split up the map into multiple large regions which you can use to guarantee that the gold mines always spawn a decent distance away from one another.
I tried, but i don't understand how to make this trigger.. I have no idea how to check distance to prevent them from being one on top of another(Is not a problem if 2 gold mines or 2 trees are very close if the pathing not collide.)

Here is what I tried and failed..:)

  • Spawn Gold Mines and Trees
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Set VariableSet Random_Point1 = (Random point in Region1 <gen>)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Terrain pathing at Random_Point1 of type Buildability is off) Equal to False
        • Then - Actions
          • Unit - Create 1 Gold Mine Custom for Neutral Passive at Random_Point1 facing Default building facing degrees
          • Unit - Create 1 Pathing for Gold Mine for Neutral Passive at Random_Point1 facing Default building facing degrees
        • Else - Actions
          • Game - Display to (All players) the text: Else
      • Custom script: call RemoveLocation(udg_Random_Point1)
To avoid having trees on top of each other or on the gold mines I suggest to use the builder trick,
It goes like this:
You select a random point within the region and order a dummy builder to build a building that has same pathing as your trees (and with no cost) at this point.
Right after the order is given you check the current order of the unit. If it returns null it’s not pathable and if it returns something there’s room for the tree.
In both cases you remove the dummy builder since you don’t want to build anything and only actually create the tree if there’s room.
You can loop this many times as it’s not heavy on performance.
The same problem here.. I don't know how to create this trigger because I am still a noob:)
Here is what I tried and failed again..:)

  • Dummy Builder
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Set VariableSet Random_Point2 = (Random point in Region1 <gen>)
      • Unit - Create 1 Dummy Builder for Neutral Passive at (Center of (Playable map area)) facing Default building facing degrees
      • Unit - Add a 5.00 second Generic expiration timer to (Last created unit)
      • Unit - Order (Last created unit) to build a Farm X at Random_Point2
      • Set VariableSet UnitWispDummy = (Last created unit)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Current order of UnitWispDummy) Equal to (Order(stop))
        • Then - Actions
          • Game - Display to (All players) the text: then
          • Unit - Remove (Last created unit) from the game
        • Else - Actions
          • Destructible - Create a Summer Tree Custom at Random_Point2 facing (Random angle) with scale 1.00 and variation (Random integer number between 1 and 10)
          • Unit - Remove (Last created unit) from the game
      • Custom script: call RemoveLocation(udg_Random_Point2)

I'll attach the map for tests if you can fix the triggers for me.

Thanks🔥!
 

Attachments

  • Gold mine with pathing and trees.w3m
    20.7 KB · Views: 1

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,558
I tried, but i don't understand how to make this trigger.. I have no idea how to check distance to prevent them from being one on top of another(Is not a problem if 2 gold mines or 2 trees are very close if the pathing not collide.)
Here's an example map that should work for you. How it works:

Step 1: Create the trees.
Step 2: Find a random point that is completely buildable in a 256.00 radius and is at least 500.00 distance away from other existing gold mines.
Step 3: Create a gold mine + pathing unit at this random point.
Step 4: Repeat step 2 -> step 4 until all of the gold mines have been created or until a limit is reached.

All of the numbers are adjustable. I also don't use a Region for my random point but you can easily fix that. This is all handled inside a For Loop which allows us to repeat the logic multiple times up to a certain limit and also stop early once we've reached our goal.

Note that I added an Item to test pathing since creating or moving an Item on top of deep water, buildings, cliff edges, and any standard pathing will force the Item to move to the nearest pathable point. I use this in combination with the "Is buildability" condition you were using already to determine pathability.

I've also made it so if you fail to create the necessary number of Gold Mines it will run the trigger again. However, it will only repeat the trigger up to 10 times, because a limit was needed to prevent it from repeating an infinite number of times (and crashing the game). That being said, I imagine it's practically impossible for a complete failure since it makes so many attempts.
 

Attachments

  • Pathing Fix 1.w3m
    25.7 KB · Views: 2
Last edited:
Level 11
Joined
Sep 11, 2013
Messages
327
Here's an example map that should work for you. How it works:

Step 1: Create the trees.
Step 2: Find a random point that is completely buildable in a 256.00 radius and is at least 500.00 distance away from other existing gold mines.
Step 3: Create a gold mine + pathing unit at this random point.
Step 4: Repeat step 2 -> step 4 until all of the gold mines have been created or until a limit is reached.

All of the numbers are adjustable. I also don't use a Region for my random point but you can easily fix that. This is all handled inside a For Loop which allows us to repeat the logic multiple times up to a certain limit and also stop early once we've reached our goal.

Note that I added an Item to test pathing since creating or moving an Item on top of deep water, buildings, cliff edges, and any standard pathing will force the Item to move to the nearest pathable point. I use this in combination with the "Is buildability" condition you were using already to determine pathability.

I've also made it so if you fail to create the necessary number of Gold Mines it will run the trigger again. However, it will only repeat the trigger up to 10 times, because a limit was needed to prevent it from repeating an infinite number of times (and crashing the game). That being said, I imagine it's practically impossible for a complete failure since it makes so many attempts.
This work like a charm. Remarcable as always. Thank you so much, Uncle!:peasant-thumbs-up-cheers:

That trigger is huge, complex and complicated for me, that's for sure and I want to ask you something.

What do you recommend me to do if I want to separate my map in 8 big regions(like a square separate in 9 regions, but without region in the middle)?
I must copy & paste the entire trigger you made with rename variables 8 times for each region?
Is there a better way?

Additional questions:
1709154356174.png
1.As you can see in this image, the trees that are created by trigger(in general) are not showing on minimap. Is there a way to solve this?
2.Also, the building that is made for pathing porpose it appear on top on gold mine on minimap. Is there a way to hide that black square?
(converting the building into unit is not a solution from what I can see, because the pathing dissapear and a little black dot will still remain on minimap).

I think this is hardcoded, but Thank you again anyway:)
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,558
No problem :)

It's best to keep things organized in one trigger instead of having duplicates of the same trigger. With clever use of Array variables you can keep the trigger mostly the same and have it work for all 8 Regions.

I've gone and added this functionality to the map (see attached below). I also fixed some other problems as well. For instance, I'm relying on a special Pathing Blocker destructible instead of your Pathing for Gold Mine unit. It makes more sense for it to be a Destructible since it's really only there to block pathing. I also reduced the minimum distance to 300.00 and attempt count to 200, of course you should customize these values to your liking.

To answer your other two questions:

1) The trees will need to be preplaced on the map in order to show up since they're sort of baked into the minimap image. But you can use triggers to create special minimap icons, so you can create icons at each tree's position. If that doesn't work, you can try to create a unit at the position of the trees that has a special minimap icon, just give it the Locust ability so it can't be interacted with.

I tried doing this but it didn't work. Not sure why, could be a bad icon path:
  • Cinematic - Create Minimap Icon at SGT_Point[0] of color (255, 255, 255) using UI\Minimap\MinimapIconCircleOfPower.blp and fog visibility Black mask
2) You can Hide the minimap display of any unit in the Object Editor.
1709155421290.png
 

Attachments

  • Pathing Fix 2.w3m
    26.4 KB · Views: 2
Last edited:
Level 11
Joined
Sep 11, 2013
Messages
327
No problem :)

It's best to keep things organized in one trigger instead of having duplicates of the same trigger. With clever use of Array variables you can keep the trigger mostly the same and have it work for all 8 Regions.

I've gone and added this functionality to the map (see attached below). I also fixed some other problems as well. For instance, I'm relying on a special Pathing Blocker destructible instead of your Pathing for Gold Mine unit. It makes more sense for it to be a Destructible since it's really only there to block pathing. I also reduced the minimum distance to 300.00 and attempt count to 200, of course you should customize these values to your liking.

To answer your other two questions:

1) The trees will need to be preplaced on the map in order to show up since they're sort of baked into the minimap image. But you can use triggers to create special minimap icons, so you can create icons at each tree's position. If that doesn't work, you can try to create a unit at the position of the trees that has a special minimap icon, just give it the Locust ability so it can't be interacted with.

I tried doing this but it didn't work. Not sure why, could be a bad icon path:
  • Cinematic - Create Minimap Icon at SGT_Point[0] of color (255, 255, 255) using UI\Minimap\MinimapIconCircleOfPower.blp and fog visibility Black mask
2) You can Hide the minimap display of any unit in the Object Editor.
View attachment 463892
It work pretty amazing with all 8 regions. 🔥 :peasant-thumbs-up-cheers: 🔥 Thumbs up for that!
Indeed, it makes more sense to be a destructible for Pathing Gold Mine.

About those 2 questions..
1. Is not a bad icon path, but is bugged that specific path. I tried a different one and it works(UI\MiniMap\minimap-item.blp).
I also tried to import from mpq the same blp file and many others blp files for Minimap Icon, but I can't select them in import section from trigger because the imports do not appear. I don't know why. I think is another bug.. I tried to make my own blp file but the same probleam appear.

I personaly don't like this options from below and I want to make my own minimap icon.. just like a normal tree(a green dot).
{UI\MiniMap\minimap-gold.blp/UI\MiniMap\minimap-hero.blp/UI\MiniMap\minimap-item.blp/UI\MiniMap\minimap-neutralbuilding.blp/UI\MiniMap\MinimapIconCircleOfPower.blp}

One problem here.. I don't know how to make a special minimap icon for a specific unit.. I mean where or how I can find that field to change icon on minimap for a specific unit?

2.I didn't know about that Hide Minimap Display option. Now I know:)
Thanks!
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,558
I tried that method, but it didn't work..

For the moment, I'll use this UI\MiniMap\MiniMapIcon\MiniMapUnitIcon.mdl with (32 90 32)

Is very similar to a tree::peasant-smile:

Thank you for all your precious work!

:peasant-victory:
I have a feeling it's very precise, so maybe adding, changing, or removing the file extension would work. Also, no problem, I always enjoy making these kinds of random generators.
 
Top