• 🏆 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!

Help with random tree placement?

Status
Not open for further replies.
Level 13
Joined
Oct 16, 2010
Messages
731
So. I've made a little trigger that will create loads of trees around the map. However they get placed in places such as water and they clash into other objects and stuff. Any ideas?

Here's my trigger:
  • Untitled Trigger 001
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • For each (Integer A) from 1 to (Random integer number between 25 and 75), do (Actions)
        • Loop - Actions
          • Destructible - Create a Tree 01 at (Random point in (Entire map)) facing (Random angle) with scale 2.00 and variation 1
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Terrain cliff level at (Position of (Last created destructible))) Less than 2
            • Then - Actions
              • Destructible - Remove (Last created destructible)
            • Else - Actions
      • For each (Integer A) from 1 to (Random integer number between 75 and 150), do (Actions)
        • Loop - Actions
          • Destructible - Create a Tree 02 at (Random point in (Entire map)) facing (Random angle) with scale 2.00 and variation 1
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Terrain cliff level at (Position of (Last created destructible))) Less than 2
            • Then - Actions
              • Destructible - Remove (Last created destructible)
            • Else - Actions
      • For each (Integer A) from 1 to (Random integer number between 75 and 150), do (Actions)
        • Loop - Actions
          • Destructible - Create a Tree 03 at (Random point in (Entire map)) facing (Random angle) with scale 2.00 and variation 1
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Terrain cliff level at (Position of (Last created destructible))) Less than 2
            • Then - Actions
              • Destructible - Remove (Last created destructible)
            • Else - Actions
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Add the "Pathability" condition. It's a terrain comparison I think, or something like that. You can check the terrain of the point before placing the object.

BTW, the trigger leaks a lot of points.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
  • (Terrain pathing at (Center of (Playable map area)) of type Walkability is off) Equal to True
Be ware of the leaks from the first moment. Fixing them later is really annoying.

  • Set TPoint = (Random point in (Entire map))
  • Custom script: call RemoveLocation(udg_TPoint)
  • Untitled Trigger 001
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
    • Set Destructible[1] = Tree 01
    • Set Destructible[2] = Tree 02
    • Set Destructible[3] = Tree 03
      • For each (Integer A) from 1 to (Random integer number between 175 and 375), do (Actions)
        • Loop - Actions
          • Set TPoint = (Random point in (Entire map))
          • Destructible - Create a Destructible[Random Integer between 1 and 3] at TPoint facing (Random angle) with scale 2.00 and variation 1
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Terrain cliff level at TPoint) Less than 2
              • (Terrain pathing at TPoint) of type Walkability is off) Equal to True
            • Then - Actions
              • Destructible - Remove (Last created destructible)
            • Else - Actions
          • Custom script: call RemoveLocation(udg_TPoint)
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
  • Untitled Trigger 001
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
    • Set Destructible[1] = Tree 01
    • Set Destructible[2] = Tree 02
    • Set Destructible[3] = Tree 03
      • For each (Integer A) from 1 to (Random integer number between 175 and 375), do (Actions)
        • Loop - Actions
          • Set TPoint = (Random point in (Entire map))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Terrain cliff level at TPoint) Less than 2
              • (Terrain pathing at TPoint) of type Walkability is off) Equal to True
            • Then - Actions
              • Custom script: set bj_forLoopAIndex = bj_forLoopAIndex - 1
            • Else - Actions
              • Destructible - Create a Destructible[Random Integer between 1 and 3] at TPoint facing (Random angle) with scale 2.00 and variation 1
          • Custom script: call RemoveLocation(udg_TPoint)
No need to create the destructible if the point isn't valid. The custom script makes sure that you create the randomized amount of destructibles.
 
Status
Not open for further replies.
Top