Adding 10 units to 10 random regions

Discussion in 'World Editor Help' started by KvickaN, Dec 30, 2018.

  1. KvickaN

    KvickaN TH.net Regular

    Ratings:
    +23 / 0 / -0
    Hi!

    About 9 years since I last logged in to thehelper.net! o_O

    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:

    [​IMG]

    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? :D

    Help appreciated!
     
  2. KvickaN

    KvickaN TH.net Regular

    Ratings:
    +23 / 0 / -0
    I found a solution and it works fine!

    Code:
    Init Vars
        Events
            Map initialization
        Conditions
        Actions
            Set RRR[1] = (RRR1 <gen> offset by (0.00, 0.00))
            Set RRR[2] = (RRR2 <gen> offset by (0.00, 0.00))
            Set RRR[3] = (RRR3 <gen> offset by (0.00, 0.00))
            Set RRR[4] = (RRR4 <gen> offset by (0.00, 0.00))
            Set RRR[5] = (RRR5 <gen> offset by (0.00, 0.00))
            Set RRR[6] = (RRR6 <gen> offset by (0.00, 0.00))
            Set RRR[7] = (RRR7 <gen> offset by (0.00, 0.00))
            Set RRR[8] = (RRR8 <gen> offset by (0.00, 0.00))
            Set RRR[9] = (RRR9 <gen> offset by (0.00, 0.00))
            Set RRR[10] = (RRR10 <gen> offset by (0.00, 0.00))
            Set RRR[11] = (RRR11 <gen> offset by (0.00, 0.00))
            Set RRR[12] = (RRR12 <gen> offset by (0.00, 0.00))
            Set RRR[13] = (RRR13 <gen> offset by (0.00, 0.00))
            Set RRR[14] = (RRR14 <gen> offset by (0.00, 0.00))
            Set RRR[15] = (RRR15 <gen> offset by (0.00, 0.00))
            Set RRR[16] = (RRR16 <gen> offset by (0.00, 0.00))
            Set RRR[17] = (RRR17 <gen> offset by (0.00, 0.00))
            Set RRR[18] = (RRR18 <gen> offset by (0.00, 0.00))
            Set RRR[19] = (RRR19 <gen> offset by (0.00, 0.00))
            Set RRR[20] = (RRR20 <gen> offset by (0.00, 0.00))
            Set RRR[21] = (RRR21 <gen> offset by (0.00, 0.00))
            Set RRR[22] = (RRR22 <gen> offset by (0.00, 0.00))
            Set RRR[23] = (RRR23 <gen> offset by (0.00, 0.00))
            Set RRR[24] = (RRR24 <gen> offset by (0.00, 0.00))
            Set RRR[25] = (RRR25 <gen> offset by (0.00, 0.00))
            Set RRR[26] = (RRR26 <gen> offset by (0.00, 0.00))
            Set RRR[27] = (RRR27 <gen> offset by (0.00, 0.00))
            Set RRR[28] = (RRR28 <gen> offset by (0.00, 0.00))
            Set RRR[29] = (RRR29 <gen> offset by (0.00, 0.00))
            Set RRR[30] = (RRR30 <gen> offset by (0.00, 0.00))
            Set RRR[31] = (RRR31 <gen> offset by (0.00, 0.00))
            Set RRR[32] = (RRR32 <gen> offset by (0.00, 0.00))
            Set RRR[33] = (RRR33 <gen> offset by (0.00, 0.00))
            Set RRR[34] = (RRR34 <gen> offset by (0.00, 0.00))
            Set RRR[35] = (RRR35 <gen> offset by (0.00, 0.00))
            Set RRR[36] = (RRR36 <gen> offset by (0.00, 0.00))
            Set RRR[37] = (RRR37 <gen> offset by (0.00, 0.00))
            Set RRR[38] = (RRR38 <gen> offset by (0.00, 0.00))
            Set RRR[39] = (RRR39 <gen> offset by (0.00, 0.00))
            Set RRR[40] = (RRR40 <gen> offset by (0.00, 0.00))
            Set RRR[41] = (RRR41 <gen> offset by (0.00, 0.00))
            Set RRR[42] = (RRR42 <gen> offset by (0.00, 0.00))
            Set RRR[43] = (RRR43 <gen> offset by (0.00, 0.00))
            Set RRR[44] = (RRR44 <gen> offset by (0.00, 0.00))
            Set RRR[45] = (RRR45 <gen> offset by (0.00, 0.00))
            Set RRR[46] = (RRR46 <gen> offset by (0.00, 0.00))
            Set RRR[47] = (RRR47 <gen> offset by (0.00, 0.00))
            Set RRR[48] = (RRR48 <gen> offset by (0.00, 0.00))
            Set RRR[49] = (RRR49 <gen> offset by (0.00, 0.00))
            Set RRR[50] = (RRR50 <gen> offset by (0.00, 0.00))
            Set RRR[51] = (RRR51 <gen> offset by (0.00, 0.00))
            Set RRR[52] = (RRR52 <gen> offset by (0.00, 0.00))
            Set RRR[53] = (RRR53 <gen> offset by (0.00, 0.00))
            Set RRR[54] = (RRR54 <gen> offset by (0.00, 0.00))
            Set RRR[55] = (RRR55 <gen> offset by (0.00, 0.00))
            Set RRR[56] = (RRR56 <gen> offset by (0.00, 0.00))
            Set RRR[57] = (RRR57 <gen> offset by (0.00, 0.00))
            Set RRR[58] = (RRR58 <gen> offset by (0.00, 0.00))
            Set RRR[59] = (RRR59 <gen> offset by (0.00, 0.00))
            Set RRR[60] = (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: Dec 30, 2018
  3. AceHart

    AceHart Your Friendly Neighborhood Admin

    Ratings:
    +1,482 / 0 / -0
    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[1] = Region 0001
    Set Regions[2] = Region 0002
    ...
    Set Regions[60] = 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[1] = Unit type of Tree Unit
    Set UnitTypes[2] = Unit type of Stone Unit
    ...
    Set UnitTypes[5] = 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 :p
     
    • Like Like x 1
  4. KvickaN

    KvickaN TH.net Regular

    Ratings:
    +23 / 0 / -0
    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
            Visibility - Disable black mask
            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[1] = (RRR1 <gen> offset by (0.00, 0.00))
            Set RRR[2] = (RRR2 <gen> offset by (0.00, 0.00))
            ...
            Set RRR[69] = (RRR69 <gen> offset by (0.00, 0.00))
            Set Settlers[1] = Player Group - Player 1 (Red)
            Set Settlers[2] = Player Group - Player 2 (Blue)
            Set Settlers[3] = Player Group - Player 6 (Orange)
            Set Settlers[4] = 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[2])))
                                                            Set NumA[2] = 0
                                                            Game - Display to (All players) the text: (#3's:  + (String(NumA[3])))
                                                            Set NumA[3] = 0
                                                            Game - Display to (All players) the text: (#4's:  + (String(NumA[4])))
                                                            Set NumA[4] = 0
                                                            Game - Display to (All players) the text: (#5's:  + (String(NumA[5])))
                                                            Set NumA[5] = 0
                                                            Game - Display to (All players) the text: (#6's:  + (String(NumA[6])))
                                                            Set NumA[6] = 0
                                                            Game - Display to (All players) the text: (#8's:  + (String(NumA[8])))
                                                            Set NumA[8] = 0
                                                            Game - Display to (All players) the text: (#9's:  + (String(NumA[9])))
                                                            Set NumA[9] = 0
                                                            Game - Display to (All players) the text: (#10's:  + (String(NumA[10])))
                                                            Set NumA[10] = 0
                                                            Game - Display to (All players) the text: (#11's:  + (String(NumA[11])))
                                                            Set NumA[11] = 0
                                                            Game - Display to (All players) the text: (#12's:  + (String(NumA[12])))
                                                            Set NumA[12] = 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
                                                            Visibility - Disable black mask
                                                            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! :)
     

    Attached Files:

  5. KvickaN

    KvickaN TH.net Regular

    Ratings:
    +23 / 0 / -0
    Ok, now I have this:

    Code:
    Alg Generate resources
        Events
        Conditions
        Actions
            -------- Regions --------
            Set AlgRegionsCount = 69
            Set RRR[1] = (RRR1 <gen> offset by (0.00, 0.00))
            ...
            Set RRR[69] = (RRR69 <gen> offset by (0.00, 0.00))
            -------- Numbers --------
            Set AlgNumbersCount = 10
            Set AlgNumbersTypes[1] = 2
            Set AlgNumbersTypes[2] = 3
            Set AlgNumbersTypes[3] = 4
            Set AlgNumbersTypes[4] = 5
            Set AlgNumbersTypes[5] = 6
            Set AlgNumbersTypes[6] = 8
            Set AlgNumbersTypes[7] = 9
            Set AlgNumbersTypes[8] = 10
            Set AlgNumbersTypes[9] = 11
            Set AlgNumbersTypes[10] = 12
            -------- Resources --------
            Set AlgResourceTypesCount = 5
            Set AlgResourceTypes[1] = Sheep Resource
            Set AlgResourceTypes[2] = Clay Resource
            Set AlgResourceTypes[3] = Stone Resource
            Set AlgResourceTypes[4] = Tree Resource
            Set AlgResourceTypes[5] = Wheat Resource
            Set AlgResourceTypeListCount = 0
            -------- Terrain --------
            Set AlgTerrainCount = 5
            Set AlgTerrainTypes[1] = Lordaeron Summer - Grass
            Set AlgTerrainTypes[2] = Barrens - Rough Dirt
            Set AlgTerrainTypes[3] = Lordaeron Summer - Rock
            Set AlgTerrainTypes[4] = Lordaeron Summer - Dark Grass
            Set AlgTerrainTypes[5] = 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,...
    
     
  6. AceHart

    AceHart Your Friendly Neighborhood Admin

    Ratings:
    +1,482 / 0 / -0
    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
     
    • Like Like x 1
  7. KvickaN

    KvickaN TH.net Regular

    Ratings:
    +23 / 0 / -0
    You're a god!

    Works like a charm! A thousand thanks! :)
     

Share This Page