# Adding 10 units to 10 random regions

#### KvickaN

##### TH.net Regular
Hi!

About 9 years since I last logged in to thehelper.net! I lost most of my triggerskills since I was active here and I'm now in need of some assistance, probably basic stuff for you guys! So:

I have 60 regions. In these regions I need 50 resources, 10 each of the 5 different resources that exist. So that leaves 10 regions without any resources.

Resources are units for the time being.

How would I go about generating this at the start of the map?

I know this is totally wrong, but it might help paint the picture to what I'm after: My thought is to create a region array with the size: 60. Randomly assign the 60 different 60 regions to 60 randomly picked numbers in the array. Then spawn 10 random "Wheat resource" in 10 random regions and so on... Do I make any sense? Help appreciated!

#### KvickaN

##### TH.net Regular
I found a solution and it works fine!

Code:
``````Init Vars
Events
Map initialization
Conditions
Actions
Set RRR = (RRR1 <gen> offset by (0.00, 0.00))
Set RRR = (RRR2 <gen> offset by (0.00, 0.00))
Set RRR = (RRR3 <gen> offset by (0.00, 0.00))
Set RRR = (RRR4 <gen> offset by (0.00, 0.00))
Set RRR = (RRR5 <gen> offset by (0.00, 0.00))
Set RRR = (RRR6 <gen> offset by (0.00, 0.00))
Set RRR = (RRR7 <gen> offset by (0.00, 0.00))
Set RRR = (RRR8 <gen> offset by (0.00, 0.00))
Set RRR = (RRR9 <gen> offset by (0.00, 0.00))
Set RRR = (RRR10 <gen> offset by (0.00, 0.00))
Set RRR = (RRR11 <gen> offset by (0.00, 0.00))
Set RRR = (RRR12 <gen> offset by (0.00, 0.00))
Set RRR = (RRR13 <gen> offset by (0.00, 0.00))
Set RRR = (RRR14 <gen> offset by (0.00, 0.00))
Set RRR = (RRR15 <gen> offset by (0.00, 0.00))
Set RRR = (RRR16 <gen> offset by (0.00, 0.00))
Set RRR = (RRR17 <gen> offset by (0.00, 0.00))
Set RRR = (RRR18 <gen> offset by (0.00, 0.00))
Set RRR = (RRR19 <gen> offset by (0.00, 0.00))
Set RRR = (RRR20 <gen> offset by (0.00, 0.00))
Set RRR = (RRR21 <gen> offset by (0.00, 0.00))
Set RRR = (RRR22 <gen> offset by (0.00, 0.00))
Set RRR = (RRR23 <gen> offset by (0.00, 0.00))
Set RRR = (RRR24 <gen> offset by (0.00, 0.00))
Set RRR = (RRR25 <gen> offset by (0.00, 0.00))
Set RRR = (RRR26 <gen> offset by (0.00, 0.00))
Set RRR = (RRR27 <gen> offset by (0.00, 0.00))
Set RRR = (RRR28 <gen> offset by (0.00, 0.00))
Set RRR = (RRR29 <gen> offset by (0.00, 0.00))
Set RRR = (RRR30 <gen> offset by (0.00, 0.00))
Set RRR = (RRR31 <gen> offset by (0.00, 0.00))
Set RRR = (RRR32 <gen> offset by (0.00, 0.00))
Set RRR = (RRR33 <gen> offset by (0.00, 0.00))
Set RRR = (RRR34 <gen> offset by (0.00, 0.00))
Set RRR = (RRR35 <gen> offset by (0.00, 0.00))
Set RRR = (RRR36 <gen> offset by (0.00, 0.00))
Set RRR = (RRR37 <gen> offset by (0.00, 0.00))
Set RRR = (RRR38 <gen> offset by (0.00, 0.00))
Set RRR = (RRR39 <gen> offset by (0.00, 0.00))
Set RRR = (RRR40 <gen> offset by (0.00, 0.00))
Set RRR = (RRR41 <gen> offset by (0.00, 0.00))
Set RRR = (RRR42 <gen> offset by (0.00, 0.00))
Set RRR = (RRR43 <gen> offset by (0.00, 0.00))
Set RRR = (RRR44 <gen> offset by (0.00, 0.00))
Set RRR = (RRR45 <gen> offset by (0.00, 0.00))
Set RRR = (RRR46 <gen> offset by (0.00, 0.00))
Set RRR = (RRR47 <gen> offset by (0.00, 0.00))
Set RRR = (RRR48 <gen> offset by (0.00, 0.00))
Set RRR = (RRR49 <gen> offset by (0.00, 0.00))
Set RRR = (RRR50 <gen> offset by (0.00, 0.00))
Set RRR = (RRR51 <gen> offset by (0.00, 0.00))
Set RRR = (RRR52 <gen> offset by (0.00, 0.00))
Set RRR = (RRR53 <gen> offset by (0.00, 0.00))
Set RRR = (RRR54 <gen> offset by (0.00, 0.00))
Set RRR = (RRR55 <gen> offset by (0.00, 0.00))
Set RRR = (RRR56 <gen> offset by (0.00, 0.00))
Set RRR = (RRR57 <gen> offset by (0.00, 0.00))
Set RRR = (RRR58 <gen> offset by (0.00, 0.00))
Set RRR = (RRR59 <gen> offset by (0.00, 0.00))
Set RRR = (RRR60 <gen> offset by (0.00, 0.00))``````
Code:
``````Generate resources
Events
Time - Every 0.05 seconds of game time
Conditions
Actions
Set RandomInteger = (Random integer number between 1 and 60)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Number of units in (Units in RRR[RandomInteger])) Equal to 0
(Number of units in (Units owned by Neutral Passive of type Sheep Resource)) Less than or equal to 9
Then - Actions
Unit - Create 1 Sheep Resource for Neutral Passive at (Center of RRR[RandomInteger]) facing Default building facing degrees
Else - Actions
Set RandomInteger = (Random integer number between 1 and 60)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Number of units in (Units in RRR[RandomInteger])) Equal to 0
(Number of units in (Units owned by Neutral Passive of type Clay Resource)) Less than or equal to 9
Then - Actions
Unit - Create 1 Clay Resource for Neutral Passive at (Center of RRR[RandomInteger]) facing Default building facing degrees
Else - Actions
Set RandomInteger = (Random integer number between 1 and 60)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Number of units in (Units in RRR[RandomInteger])) Equal to 0
(Number of units in (Units owned by Neutral Passive of type Stone Resource)) Less than or equal to 9
Then - Actions
Unit - Create 1 Stone Resource for Neutral Passive at (Center of RRR[RandomInteger]) facing Default building facing degrees
Else - Actions
Set RandomInteger = (Random integer number between 1 and 60)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Number of units in (Units in RRR[RandomInteger])) Equal to 0
(Number of units in (Units owned by Neutral Passive of type Tree Resource)) Less than or equal to 9
Then - Actions
Unit - Create 1 Tree Resource for Neutral Passive at (Center of RRR[RandomInteger]) facing Default building facing degrees
Else - Actions
Set RandomInteger = (Random integer number between 1 and 60)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Number of units in (Units in RRR[RandomInteger])) Equal to 0
(Number of units in (Units owned by Neutral Passive of type Wheat Resource)) Less than or equal to 9
Then - Actions
Unit - Create 1 Wheat Resource for Neutral Passive at (Center of RRR[RandomInteger]) facing Default building facing degrees
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Number of units in (Units owned by Neutral Passive of type Tree Resource)) Equal to 10
(Number of units in (Units owned by Neutral Passive of type Wheat Resource)) Equal to 10
(Number of units in (Units owned by Neutral Passive of type Stone Resource)) Equal to 10
(Number of units in (Units owned by Neutral Passive of type Sheep Resource)) Equal to 10
(Number of units in (Units owned by Neutral Passive of type Clay Resource)) Equal to 10
Then - Actions
Game - Display to (All players) the text: Resources successfu...
Trigger - Turn off (This trigger)
Else - Actions
Do nothing``````

Last edited:

#### AceHart

With a better algorithm, or, rather, with an actual algorithm rather than hoping for the best, the entire thing can be pretty much streamlined into something that is actually almost understandable

Make a list of all 60 regions:
Code:
``````Set RegionsCount = 60
Set Regions = Region 0001
Set Regions = Region 0002
...
Set Regions = Region 0060``````

Make a (short) list of your 5 "units"
(note: actually uses "unit type" here and beyond, not "unit"):
Code:
``````Set UnitTypesCount = 5
Set UnitTypes = Unit type of Tree Unit
Set UnitTypes = Unit type of Stone Unit
...
Set UnitTypes = Unit type of ... Unit``````

Use that to construct the final "unit" list, with each type used 10 times:
Code:
``````Set UnitTypeListCount = 0
For Integer A from 1 to 10
For Integer B from 1 to UnitTypesCount
Set UnitTypeListCount = UnitTypeListCount + 1
Set UnitTypeList[UnitTypeListCount] = Unit type of (UnitTypes[Integer B])``````

Finally, generate some actual in-game content:
Code:
``````Set TempInteger = UnitTypeListCount
For each Integer A from 1 to TempInteger
// Randomly pick an unused region
Set RandomRegion = Random integer between 1 and RegionsCount
// Randomly pick an unused "unit"
Set RandomUnitType = Random integer between 1 and UnitTypeListCount
// Create the thing
Unit - Create 1 Unit of type UnitTypeList[RandomUnitType] at Center of Regions[RandomRegion]
// Forget the region
Set Regions[RandomRegion] = Regions[RegionsCount]
Set RegionsCount = RegionsCount - 1
// Forget the "unit"
Set UnitTypeList[RandomUnitType] = UnitTypeList[UnitTypeListCount]
Set UnitTypeListCount = UnitTypeListCount - 1``````

This can all be done in one go, in the above order, without those weird timed loopings

N.b. The title and the problem description do not agree with each other • KvickaN

#### KvickaN

##### TH.net Regular
Lol, I agree with the title, I was confused of what I even meant when typing it. Thanks for taking your time to help with an optimized solution that really make sense!

I've dug my self quite deep at the moment, the trigger is now quite much larger hehe. But I will for sure try to implement this algorithm instead!

I'm actually making Settlers of Catan, a multiplayer board game designed by Klaus Teuber.

So there's now stuff like: remember regions and numbers to be able to know what resource to give to players when a specific number is rolled.

This is the current trigger (now with 69 regions):

Code:
``````Game setup
Events
Map initialization
Conditions
Actions
Unit Group - Pick every unit in (Units owned by Neutral Passive) and do (Actions)
Loop - Actions
Unit - Hide (Picked unit)
Cinematic - Disable user control for (All players)
Cinematic - Turn cinematic mode On for (All players)
Player Group - Pick every player in (All players) and do (Camera - Set (Picked player)'s camera Angle of attack to 305.00 over 1.00 seconds)
Player Group - Pick every player in (All players) and do (Camera - Set (Picked player)'s camera Far Z to 10000.00 over 1.00 seconds)
Player Group - Pick every player in (All players) and do (Camera - Set (Picked player)'s camera Distance to target to 1800.00 over 1.00 seconds)
Player Group - Pick every player in (All players) and do (Camera - Set (Picked player)'s camera Field of view to 3500.00 over 1.00 seconds)
Visibility - Disable fog of war
Game - Set the time of day to 12.00
Player Group - Pick every player in (All players) and do (Player - Set (Picked player) Current gold to 150)
Player Group - Pick every player in (All players) and do (Player - Set (Picked player) Current lumber to 150)
Player Group - Pick every player in (All players) and do (Camera - Pan camera for (Picked player) to (Center of Lock camera region <gen>) over 1.00 seconds)
Set RRR = (RRR1 <gen> offset by (0.00, 0.00))
Set RRR = (RRR2 <gen> offset by (0.00, 0.00))
...
Set RRR = (RRR69 <gen> offset by (0.00, 0.00))
Set Settlers = Player Group - Player 1 (Red)
Set Settlers = Player Group - Player 2 (Blue)
Set Settlers = Player Group - Player 6 (Orange)
Set Settlers = Player Group - Player 22 (Snow)
Game - Display to (All players) the text: |c00f45050Generatin...``````
Code:
``````RNG
Events
Time - Every 0.01 seconds of game time
Conditions
Actions
Set RandomInteger = (Random integer number between 1 and 69)``````
Code:
``````Time to generate sec
Events
Time - Every 1.00 seconds of game time
Conditions
Actions
Set CountTimeSec = (CountTimeSec + 1)``````
Code:
``````Generate resources
Events
Time - Every (Random real number between 0.02 and 0.15) seconds of game time
Conditions
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Number of units in (Units in RRR[RandomInteger])) Equal to 0
(Number of units in (Units owned by Neutral Passive of type Sheep Resource)) Less than or equal to 12
Then - Actions
Set RandomNumbers[RandomInteger] = (Random integer number between 2 and 12)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
RandomNumbers[RandomInteger] Equal to 7
Then - Actions
Set OopsSeven = (OopsSeven + 1)
Game - Display to (All players) for 5.00 seconds the text: (|c00ff0000#|r7 |c00ff0000was rolled for |c0050f4d3Sheep|r   + (|c00ff0000at loc: |r + ((String(RandomInteger)) + |c00ff0000, rerolling...|r)))
Set RandomNumbers[RandomInteger] = (Random integer number between 2 and 12)
Else - Actions
Set NumA[RandomNumbers[RandomInteger]] = (NumA[RandomNumbers[RandomInteger]] + 1)
Floating Text - Create floating text that reads (|c0050f4d3#|r + (String(RandomNumbers[RandomInteger]))) at (Center of RRR[RandomInteger]) with Z offset 0.00, using font size 8.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
Set FloatTextNumber[RandomInteger] = (Last created floating text)
Set ResTypeA[RandomInteger] = 1
Set ResNumberA[RandomInteger] = RandomNumbers[RandomInteger]
Unit - Create 1 Sheep Resource for Neutral Passive at (Center of RRR[RandomInteger]) facing (Random real number between 1.00 and 360.00) degrees
Environment - Change terrain type at (Center of RRR[RandomInteger]) to Lordaeron Summer - Grass using variation -1 in an area of size 2 and shape Square
Game - Display to (All players) for 5.00 seconds the text: (|c0050f4d3Sheep|r resource with |c0050f4d3#|r + ((String(RandomNumbers[RandomInteger])) + ( created at loc:  + (String(RandomInteger)))))
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Number of units in (Units in RRR[RandomInteger])) Equal to 0
(Number of units in (Units owned by Neutral Passive of type Clay Resource)) Less than or equal to 12
Then - Actions
Set RandomNumbers[RandomInteger] = (Random integer number between 2 and 12)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
RandomNumbers[RandomInteger] Equal to 7
Then - Actions
Set OopsSeven = (OopsSeven + 1)
Game - Display to (All players) for 5.00 seconds the text: (|c00ff0000#|r7 |c00ff0000was rolled for |c00c67000Clay|r   + (|c00ff0000at loc: |r + ((String(RandomInteger)) + |c00ff0000, rerolling...|r)))
Set RandomNumbers[RandomInteger] = (Random integer number between 2 and 12)
Else - Actions
Set NumA[RandomNumbers[RandomInteger]] = (NumA[RandomNumbers[RandomInteger]] + 1)
Floating Text - Create floating text that reads (|c00c67000#|r + (String(RandomNumbers[RandomInteger]))) at (Center of RRR[RandomInteger]) with Z offset 0.00, using font size 8.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
Set FloatTextNumber[RandomInteger] = (Last created floating text)
Set ResTypeA[RandomInteger] = 2
Set ResNumberA[RandomInteger] = RandomNumbers[RandomInteger]
Unit - Create 1 Clay Resource for Neutral Passive at (Center of RRR[RandomInteger]) facing (Random real number between 1.00 and 360.00) degrees
Environment - Change terrain type at (Center of RRR[RandomInteger]) to Barrens - Rough Dirt using variation -1 in an area of size 2 and shape Square
Game - Display to (All players) for 5.00 seconds the text: (|c00c67000Clay|r resource with |c00c67000#|r + ((String(RandomNumbers[RandomInteger])) + ( created at loc:  + (String(RandomInteger)))))
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Number of units in (Units in RRR[RandomInteger])) Equal to 0
(Number of units in (Units owned by Neutral Passive of type Stone Resource)) Less than or equal to 12
Then - Actions
Set RandomNumbers[RandomInteger] = (Random integer number between 2 and 12)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
RandomNumbers[RandomInteger] Equal to 7
Then - Actions
Set OopsSeven = (OopsSeven + 1)
Game - Display to (All players) for 5.00 seconds the text: (|c00ff0000#|r7 |c00ff0000was rolled for |c00c4c4c4Stone|r   + (|c00ff0000at loc: |r + ((String(RandomInteger)) + |c00ff0000, rerolling...|r)))
Set RandomNumbers[RandomInteger] = (Random integer number between 2 and 12)
Else - Actions
Set NumA[RandomNumbers[RandomInteger]] = (NumA[RandomNumbers[RandomInteger]] + 1)
Floating Text - Create floating text that reads (|c00c4c4c4#|r + (String(RandomNumbers[RandomInteger]))) at (Center of RRR[RandomInteger]) with Z offset 0.00, using font size 8.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
Set FloatTextNumber[RandomInteger] = (Last created floating text)
Set ResTypeA[RandomInteger] = 3
Set ResNumberA[RandomInteger] = RandomNumbers[RandomInteger]
Unit - Create 1 Stone Resource for Neutral Passive at (Center of RRR[RandomInteger]) facing (Random real number between 1.00 and 360.00) degrees
Environment - Change terrain type at (Center of RRR[RandomInteger]) to Lordaeron Summer - Rock using variation -1 in an area of size 2 and shape Square
Game - Display to (All players) for 5.00 seconds the text: (|c00c4c4c4Stone|r resource with |c00c4c4c4#|r + ((String(RandomNumbers[RandomInteger])) + ( created at loc:  + (String(RandomInteger)))))
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Number of units in (Units in RRR[RandomInteger])) Equal to 0
(Number of units in (Units owned by Neutral Passive of type Tree Resource)) Less than or equal to 12
Then - Actions
Set RandomNumbers[RandomInteger] = (Random integer number between 2 and 12)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
RandomNumbers[RandomInteger] Equal to 7
Then - Actions
Set OopsSeven = (OopsSeven + 1)
Game - Display to (All players) for 5.00 seconds the text: (|c00ff0000#|r7 |c00ff0000was rolled for |c0000bf16Tree|r   + (|c00ff0000at loc: |r + ((String(RandomInteger)) + |c00ff0000, rerolling...|r)))
Set RandomNumbers[RandomInteger] = (Random integer number between 2 and 12)
Else - Actions
Set NumA[RandomNumbers[RandomInteger]] = (NumA[RandomNumbers[RandomInteger]] + 1)
Floating Text - Create floating text that reads (|c0000bf16#|r + (String(RandomNumbers[RandomInteger]))) at (Center of RRR[RandomInteger]) with Z offset 0.00, using font size 8.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
Set FloatTextNumber[RandomInteger] = (Last created floating text)
Set ResTypeA[RandomInteger] = 4
Set ResNumberA[RandomInteger] = RandomNumbers[RandomInteger]
Unit - Create 1 Tree Resource for Neutral Passive at (Center of RRR[RandomInteger]) facing (Random real number between 1.00 and 360.00) degrees
Environment - Change terrain type at (Center of RRR[RandomInteger]) to Lordaeron Summer - Dark Grass using variation -1 in an area of size 2 and shape Square
Game - Display to (All players) for 5.00 seconds the text: (|c0000bf16Tree|r resource with |c0000bf16#|r + ((String(RandomNumbers[RandomInteger])) + ( created at loc:  + (String(RandomInteger)))))
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Number of units in (Units in RRR[RandomInteger])) Equal to 0
(Number of units in (Units owned by Neutral Passive of type Wheat Resource)) Less than or equal to 12
Then - Actions
Set RandomNumbers[RandomInteger] = (Random integer number between 2 and 12)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
RandomNumbers[RandomInteger] Equal to 7
Then - Actions
Set OopsSeven = (OopsSeven + 1)
Game - Display to (All players) for 5.00 seconds the text: (|c00ff0000#|r7 |c00ff0000was rolled for |c00ffd400Wheat|r   + (|c00ff0000at loc: |r + ((String(RandomInteger)) + |c00ff0000, rerolling...|r)))
Set RandomNumbers[RandomInteger] = (Random integer number between 2 and 12)
Else - Actions
Set NumA[RandomNumbers[RandomInteger]] = (NumA[RandomNumbers[RandomInteger]] + 1)
Floating Text - Create floating text that reads (|c00ffd400#|r + (String(RandomNumbers[RandomInteger]))) at (Center of RRR[RandomInteger]) with Z offset 0.00, using font size 8.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
Set FloatTextNumber[RandomInteger] = (Last created floating text)
Set ResTypeA[RandomInteger] = 5
Set ResNumberA[RandomInteger] = RandomNumbers[RandomInteger]
Unit - Create 1 Wheat Resource for Neutral Passive at (Center of RRR[RandomInteger]) facing (Random real number between 1.00 and 360.00) degrees
Environment - Change terrain type at (Center of RRR[RandomInteger]) to Lordaeron Fall - Grassy Dirt using variation -1 in an area of size 2 and shape Square
Game - Display to (All players) for 5.00 seconds the text: (|c00ffd400Wheat|r resource with |c00ffd400#|r + ((String(RandomNumbers[RandomInteger])) + ( created at loc:  + (String(RandomInteger)))))
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Number of units in (Units owned by Neutral Passive of type Tree Resource)) Equal to 13
(Number of units in (Units owned by Neutral Passive of type Wheat Resource)) Equal to 13
(Number of units in (Units owned by Neutral Passive of type Stone Resource)) Equal to 13
(Number of units in (Units owned by Neutral Passive of type Sheep Resource)) Equal to 13
(Number of units in (Units owned by Neutral Passive of type Clay Resource)) Equal to 13
Then - Actions
Trigger - Turn off RNG <gen>
Trigger - Turn off Time to generate sec <gen>
Set PrintTime = (Resource generation completed in: |c009af450 + ((String(CountTimeSec)) +  |rseconds!))
Set CountTimeSec = 0
Game - Display to (All players) the text: (#2's:  + (String(NumA)))
Set NumA = 0
Game - Display to (All players) the text: (#3's:  + (String(NumA)))
Set NumA = 0
Game - Display to (All players) the text: (#4's:  + (String(NumA)))
Set NumA = 0
Game - Display to (All players) the text: (#5's:  + (String(NumA)))
Set NumA = 0
Game - Display to (All players) the text: (#6's:  + (String(NumA)))
Set NumA = 0
Game - Display to (All players) the text: (#8's:  + (String(NumA)))
Set NumA = 0
Game - Display to (All players) the text: (#9's:  + (String(NumA)))
Set NumA = 0
Game - Display to (All players) the text: (#10's:  + (String(NumA)))
Set NumA = 0
Game - Display to (All players) the text: (#11's:  + (String(NumA)))
Set NumA = 0
Game - Display to (All players) the text: (#12's:  + (String(NumA)))
Set NumA = 0
Game - Display to (All players) the text: (#7 rerolls:  + (String(OopsSeven)))
Set OopsSeven = 0
Game - Display to (All players) the text: PrintTime
Game - Display to (All players) for 30.00 seconds the text: |c00ff0000Red settl...
Game - Display to (All players) for 30.00 seconds the text: Type |c009af450-rea...
Cinematic - Turn cinematic mode Off for (All players)
Visibility - Disable fog of war
Cinematic - Enable user control for (All players)
Trigger - Turn off (This trigger)
Else - Actions
Do nothing``````
Code:
``````Regenerate resources
Events
Player - Player 1 (Red) types a chat message containing -reg as An exact match
Conditions
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Number of living Village units owned by Player 1 (Red)) Equal to 0
(Number of living Village units owned by Player 2 (Blue)) Equal to 0
(Number of living Village units owned by Player 6 (Orange)) Equal to 0
(Number of living Village units owned by Player 22 (Snow)) Equal to 0
(Number of living City units owned by Player 1 (Red)) Equal to 0
(Number of living City units owned by Player 2 (Blue)) Equal to 0
(Number of living City units owned by Player 6 (Orange)) Equal to 0
(Number of living City units owned by Player 22 (Snow)) Equal to 0
(Number of living Spiritway (road) units owned by Player 1 (Red)) Equal to 0
(Number of living Spiritway (road) units owned by Player 2 (Blue)) Equal to 0
(Number of living Spiritway (road) units owned by Player 6 (Orange)) Equal to 0
(Number of living Spiritway (road) units owned by Player 22 (Snow)) Equal to 0
Then - Actions
Cinematic - Disable user control for (All players)
Cinematic - Turn cinematic mode On for (All players)
Game - Display to (All players) the text: |c00f45050Removing ...
Wait 0.50 seconds
For each (Integer A) from 1 to 69, do (Actions)
Loop - Actions
Floating Text - Destroy FloatTextNumber[(Integer A)]
Wait 0.50 seconds
Game - Display to (All players) the text: Removing resource: ...
Unit Group - Pick every unit in (Units owned by Neutral Passive of type Clay Resource) and do (Environment - Change terrain type at (Position of (Picked unit)) to Lordaeron Summer - Rough Dirt using variation -1 in an area of size 2 and shape Square)
Wait 0.25 seconds
Unit Group - Pick every unit in (Units owned by Neutral Passive of type Clay Resource) and do (Unit - Remove (Picked unit) from the game)
Wait 0.50 seconds
Game - Display to (All players) the text: Removing resource: ...
Unit Group - Pick every unit in (Units owned by Neutral Passive of type Sheep Resource) and do (Environment - Change terrain type at (Position of (Picked unit)) to Lordaeron Summer - Rough Dirt using variation -1 in an area of size 2 and shape Square)
Wait 0.25 seconds
Unit Group - Pick every unit in (Units owned by Neutral Passive of type Sheep Resource) and do (Unit - Remove (Picked unit) from the game)
Wait 0.50 seconds
Game - Display to (All players) the text: Removing resource: ...
Unit Group - Pick every unit in (Units owned by Neutral Passive of type Stone Resource) and do (Environment - Change terrain type at (Position of (Picked unit)) to Lordaeron Summer - Rough Dirt using variation -1 in an area of size 2 and shape Square)
Wait 0.25 seconds
Unit Group - Pick every unit in (Units owned by Neutral Passive of type Stone Resource) and do (Unit - Remove (Picked unit) from the game)
Wait 0.50 seconds
Game - Display to (All players) the text: Removing resource: ...
Unit Group - Pick every unit in (Units owned by Neutral Passive of type Tree Resource) and do (Environment - Change terrain type at (Position of (Picked unit)) to Lordaeron Summer - Rough Dirt using variation -1 in an area of size 2 and shape Square)
Wait 0.25 seconds
Unit Group - Pick every unit in (Units owned by Neutral Passive of type Tree Resource) and do (Unit - Remove (Picked unit) from the game)
Wait 0.50 seconds
Game - Display to (All players) the text: Removing resource: ...
Unit Group - Pick every unit in (Units owned by Neutral Passive of type Wheat Resource) and do (Environment - Change terrain type at (Position of (Picked unit)) to Lordaeron Summer - Rough Dirt using variation -1 in an area of size 2 and shape Square)
Wait 0.25 seconds
Unit Group - Pick every unit in (Units owned by Neutral Passive of type Wheat Resource) and do (Unit - Remove (Picked unit) from the game)
Wait 0.50 seconds
Game - Display to (All players) the text: |c00f45050Regenerat...
Trigger - Turn on RNG <gen>
Trigger - Turn on Time to generate sec <gen>
Trigger - Turn on Generate resources <gen>
Else - Actions
Game - Display to (All players) the text: |c00f45050Too late,...``````
I've attached the map so you can see it in-game, it's actually pretty cool. Thanks again for your time and I will try to implement your method instead for sure! I have some obstacles ahead and will ask for help again for sure! #### Attachments

• 185.8 KB Views: 286

#### KvickaN

##### TH.net Regular
Ok, now I have this:

Code:
``````Alg Generate resources
Events
Conditions
Actions
-------- Regions --------
Set AlgRegionsCount = 69
Set RRR = (RRR1 <gen> offset by (0.00, 0.00))
...
Set RRR = (RRR69 <gen> offset by (0.00, 0.00))
-------- Numbers --------
Set AlgNumbersCount = 10
Set AlgNumbersTypes = 2
Set AlgNumbersTypes = 3
Set AlgNumbersTypes = 4
Set AlgNumbersTypes = 5
Set AlgNumbersTypes = 6
Set AlgNumbersTypes = 8
Set AlgNumbersTypes = 9
Set AlgNumbersTypes = 10
Set AlgNumbersTypes = 11
Set AlgNumbersTypes = 12
-------- Resources --------
Set AlgResourceTypesCount = 5
Set AlgResourceTypes = Sheep Resource
Set AlgResourceTypes = Clay Resource
Set AlgResourceTypes = Stone Resource
Set AlgResourceTypes = Tree Resource
Set AlgResourceTypes = Wheat Resource
Set AlgResourceTypeListCount = 0
-------- Terrain --------
Set AlgTerrainCount = 5
Set AlgTerrainTypes = Lordaeron Summer - Grass
Set AlgTerrainTypes = Barrens - Rough Dirt
Set AlgTerrainTypes = Lordaeron Summer - Rock
Set AlgTerrainTypes = Lordaeron Summer - Dark Grass
Set AlgTerrainTypes = Lordaeron Summer - Grassy Dirt
Set AlgTerrainTypeListCount = 0
For each (Integer A) from 1 to 13, do (Actions)
Loop - Actions
For each (Integer B) from 1 to AlgResourceTypesCount, do (Actions)
Loop - Actions
Set AlgResourceTypeListCount = (AlgResourceTypeListCount + 1)
Set AlgResourceTypes[AlgResourceTypeListCount] = AlgResourceTypes[(Integer B)]
Set AlgTerrainTypeListCount = (AlgTerrainTypeListCount + 1)
Set AlgTerrainTypes[AlgTerrainTypeListCount] = AlgTerrainTypes[(Integer B)]
Set AlgTempInteger = AlgResourceTypeListCount
For each (Integer A) from 1 to AlgTempInteger, do (Actions)
Loop - Actions
Set AlgRandomRegion = (Random integer number between 1 and AlgRegionsCount)
Set AlgRandomResourceType = (Random integer number between 1 and AlgResourceTypeListCount)
Set AlgTerrainCount = ((Random integer number between 1 and AlgTerrainTypeListCount) + 1)
Set AlgNumbersCount = AlgNumbersTypes[(Random integer number between 1 and 10)]
Floating Text - Create floating text that reads (|c0050f4d3#|r + (String(AlgNumbersCount))) at (Center of RRR[AlgRandomRegion]) with Z offset 0.00, using font size 8.00, color (100.00%, 100.00%, 100.00%), and 0.00% transparency
Set FloatTextNumber[AlgRandomRegion] = (Last created floating text)
Environment - Change terrain type at (Center of RRR[AlgRandomRegion]) to AlgTerrainTypes[AlgRandomResourceType] using variation -1 in an area of size 2 and shape Square
Unit - Create 1 AlgResourceTypes[AlgRandomResourceType] for Neutral Passive at (Center of RRR[AlgRandomRegion]) facing (Random angle) degrees
Unit Group - Add (Last created unit) to AllResources
Set RRR[AlgRandomRegion] = RRR[AlgRegionsCount]
Set AlgRegionsCount = (AlgRegionsCount - 1)
Set AlgResourceTypes[AlgRandomResourceType] = AlgResourceTypes[AlgResourceTypeListCount]
Set AlgResourceTypeListCount = (AlgResourceTypeListCount - 1)
Set AlgTerrainTypes[AlgRandomResourceType] = AlgTerrainTypes[AlgTerrainTypeListCount]
Set AlgTerrainTypeListCount = (AlgTerrainTypeListCount - 1)``````
It seems to be super fast! It's already done when I enter the game. However, when I run the regenerate trigger there seem to be some problems with the floating text numbers not removing themselves. Did I miss something? See trigger below:

Code:
``````Regenerate resources
Events
Player - Player 1 (Red) types a chat message containing -reg as An exact match
Conditions
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Number of living Village units owned by Player 1 (Red)) Equal to 0
(Number of living Village units owned by Player 2 (Blue)) Equal to 0
(Number of living Village units owned by Player 6 (Orange)) Equal to 0
(Number of living Village units owned by Player 22 (Snow)) Equal to 0
(Number of living City units owned by Player 1 (Red)) Equal to 0
(Number of living City units owned by Player 2 (Blue)) Equal to 0
(Number of living City units owned by Player 6 (Orange)) Equal to 0
(Number of living City units owned by Player 22 (Snow)) Equal to 0
(Number of living Spiritway (road) units owned by Player 1 (Red)) Equal to 0
(Number of living Spiritway (road) units owned by Player 2 (Blue)) Equal to 0
(Number of living Spiritway (road) units owned by Player 6 (Orange)) Equal to 0
(Number of living Spiritway (road) units owned by Player 22 (Snow)) Equal to 0
Then - Actions
Game - Display to (All players) the text: |c00f45050Removing ...
For each (Integer A) from 1 to 69, do (Actions)
Loop - Actions
Floating Text - Destroy FloatTextNumber[(Integer A)]
Unit Group - Pick every unit in AllResources and do (Actions)
Loop - Actions
Environment - Change terrain type at (Position of (Picked unit)) to Lordaeron Summer - Dirt using variation -1 in an area of size 2 and shape Square
Unit - Remove (Picked unit) from the game
Game - Display to (All players) the text: |c00f45050Regenerat...
Wait 2.00 seconds
Trigger - Run Alg Generate resources <gen> (ignoring conditions)
Else - Actions
Game - Display to (All players) the text: |c00f45050Too late,...``````

#### AceHart

Well,
Floating Text - Destroy FloatTextNumber[(Integer A)]
assumes that all positions from 1 to 69 are actually used, and used only once

However, that list is filled from
Set FloatTextNumber[AlgRandomRegion] = (Last created floating text)
which does not guarantee that - seeing as it is pretty random

So, you probably want to use its own variable here:
Set FloatCount = 0
... stuff

later:
Set FloatCount = FloatCount + 1
Set FloatTextNumber[FloatCount] = (Last created floating text)

and
For each Integer A from 1 to FloatCount to remove them

• KvickaN

#### KvickaN

##### TH.net Regular
You're a god!

Works like a charm! A thousand thanks! General chit-chat
Help Users