# [Solved]Creating units in a region randomly that omit areas with deep water

Status
Not open for further replies.

#### Tazuwukei

Level 4
I don't know if this is possible or not. Maybe I did at one point, but now I forget.

The region covers an entire island, and because the island is circle instead of square, the region covers a lot of deep water areas as well. As such the randomly created units are often placed in unreachable areas, which I'd like to avoid.

I'm looking for the simplest fix possible for this, anyone know what I should do?

#### Maker

Level 37
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Terrain pathing at point of type Walkability is off) Equal to False // Boolean -> Environment - Terrain pathing is off
• Then - Actions
• Game - Display to Player Group - Player 1 (Red) the text: walk
• Else - Actions
• Game - Display to Player Group - Player 1 (Red) the text: no walk

#### Tazuwukei

Level 4
Thanks Maker! That looks like it should work.

#### Tazuwukei

Level 4
• Set Resource_Integer = (Random integer number between 1 and 2)
• For each (Integer A) from 1 to Resource_Integer, do (Actions)
• Loop - Actions
• Set RandomPoint = (Random point in SWC island 2 <gen>)
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Terrain pathing at RandomPoint of type Walkability is off) Equal to False
• Then - Actions
• Unit - Create 1 Uranium for Player 9 (Gray) at RandomPoint facing Default building facing degrees
• Else - Actions
• Set Resource_Integer = (Resource_Integer + 1)
How does this look? It's supposed to loop infinitely until it finds a valid area in the region.

#### Bannar

Code Reviewer
Level 26
• Custom script: call RemoveLocation(udg_RandomPoint)
At the bottom of trigger to clear leak and prevent lag in late game.

#### Tazuwukei

Level 4
• Custom script: call RemoveLocation(udg_RandomPoint)
At the bottom of trigger to clear leak and prevent lag in late game.

I'll follow your advice and include this at the end of my trigger, but would it really cause a leak just by continuing to store one variable?
It's just one string of extra data being stored.

#### Tazuwukei

Level 4
• Actions
• Set Resource_Integer = (Random integer number between 5 and 10)
• For each (Integer A) from 1 to Resource_Integer, do (Actions)
• Loop - Actions
• Set RandomPoint = (Random point in SWC island 2 <gen>)
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Terrain pathing at RandomPoint of type Walkability is off) Equal to False
• Then - Actions
• Unit - Create 1 Uranium for Player 9 (Gray) at RandomPoint facing Default building facing degrees
• Else - Actions
• Set Resource_Integer = (Resource_Integer + 1)
• Custom script: call RemoveLocation(udg_RandomPoint)
The point of the trigger is to generate 5-10 units randomly within a region that are on walkable terrain. I can't seem to get it working, something is wrong with the Integer update within the loop. It's supposed to make it loop longer to guarantee 5-10 units are created, but I'm constantly getting less than 5 units created. Help me more please? lol

#### Bannar

Code Reviewer
Level 26
• Set Resource_Integer = (Random integer number between 5 and 10)
• Custom script: loop
• Custom script: exitwhen 0 == udg_Resource_Integer
• Set RandomPoint = (Random point in SWC island 2 <gen>)
• If (All Conditions are True) then do (Then Actions) else do (Else Actions)
• If - Conditions
• (Terrain pathing at RandomPoint of type Walkability is off) Equal to False
• Then - Actions
• Unit - Create 1 Uranium for Player 9 (Gray) at RandomPoint facing Default building facing degrees
• Set Resource_Integer = (Resource_Integer - 1)
• Else - Actions
• Custom script: call RemoveLocation(udg_RandomPoint)
• Custom script: endloop

#### Tazuwukei

Level 4
Nice, thanks Spinnaker! This works flawlessly. /solved

Status
Not open for further replies.