• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Random Assigning Units

Status
Not open for further replies.
Level 2
Joined
Oct 22, 2012
Messages
17
Hey guys,
So my friend and I are working on a Risk style map and I'm having some very basic trigger problems. I tried searching through the threads before so hopefully someone hasn't asked this already, but if someone has just refer me to it, thanks.

I'm trying to make it so that at the beginning of the match, the cities are randomly assigned to the players equally.

So far my efforts have included:
1. Putting all the cities into a variable
2. Randomly picking a number out of those cities (total cities/total players) and then assigning those cities to a player and then removing those cities from the variable.
3. Repeat step 2 for all the players if they are playing.

For some reason, it get a sloppy number of cities and have some left over for neutral hostile, which is not what i want.

If any of you could help that would be great!
Thanks!
 
Level 2
Joined
Oct 22, 2012
Messages
17
So I try to use a trigger with arithmetic to figure out how many cities to give to each player playing (total cities/total players). The problem I think is when it doesn't divide evenly I think it just leaves some out. For example if I have an odd number of cities and an even number of players, it leaves one out.

So I'm wondering if anyone has any other ideas on how to do a randomly distributing trigger for cities. :/
 
Level 9
Joined
Jul 10, 2011
Messages
562
just let it like it is or loop through the cities and give city 1 to player 1, city 2 to player 2 and so on....so every city is set to player.
 
Level 2
Joined
Oct 22, 2012
Messages
17
just let it like it is or loop through the cities and give city 1 to player 1, city 2 to player 2 and so on....so every city is set to player.

So that wouldn't assign a building to a player who is not playing? Like say we have 6 players, when it gets to 'assign building 7 to player 7' would it just skip that and loop back to player 1?
 
Level 2
Joined
Oct 22, 2012
Messages
17
This is what i have so far, trying to follow your instructions.


Assign

Events

Time - Elapsed game time is 0.60 seconds

Conditions

(Execution count of (This trigger)) Less than or equal to 7

Actions

If (All Conditions are True) then do (Then Actions) else do (Else Actions)

If - Conditions

(Player 5 (Yellow) slot status) Equal to Is playing

Then - Actions

Unit Group - Pick every unit in (Random 1 units from Castles) and do (Actions)

Loop - Actions

Unit - Change ownership of (Picked unit) to Player 5 (Yellow) and Change color

Unit Group - Pick every unit in (Last created unit group) and do (Unit Group - Remove (Picked unit) from Castles)

Else - Actions

Do nothing
Trigger - Run (This trigger) (checking conditions)


So i have that trigger for player 5, and I have 4 more actions like it for each respective player below 5. For some reason, it gives player 2 only 1 castle, and player 1 4 castles, even if there are 5 players playing. Any ideas? :/
 
Level 9
Joined
Jul 10, 2011
Messages
562
here that should do the job.

  • Set Cities
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Do Multiple ActionsFor each (Integer TempInteger) from 1 to 200, do (Actions)
        • Loop - Actions
          • Set TempInt = (TempInt + 1)
            • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • 'IF'-Conditions
                • TempInt (>=) 13
              • 'THEN'-Actions
                • Set TempInt = (TempInt + 1)
              • 'ELSE'-Actions
                • Set TempInt = 1
            • Do Multiple ActionsFor each (Integer TempINT) from TempInt to 12, do (Actions)
              • Loop - Actions
                • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                  • 'IF'-Conditions
                    • ((Player(TempInt)) slot status) (==) Playing
                    • ((Player(TempInt)) controller) (==) User
                  • 'THEN'-Actions
                    • Unit - Change ownership of YourCityArray[TempInteger] to (Player(TempInt)) and Change Color
                    • Set TempInt = TempINT
                    • Set TempINT = 13
                  • 'ELSE'-Actions
                    • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                      • 'IF'-Conditions
                        • TempINT Gleich (==) 12
                        • (Owner of YourCity[TempInteger]) (==) Neutral Passive
                      • 'THEN'-Aktionen
                        • Do Multiple ActionsFor each (Integer TempINTEGER) from 1 to 12, do (Actions)
                          • Loop - Actions
                            • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
                              • 'IF'-Conditions
                                • ((Player(TempInt)) slot status) Gleich (==) Playing
                                • ((Player(TempInt)) controller) Gleich (==) User
                              • 'THEN'-Actions
                                • Unit - Change ownership of YourCityArray[TempInteger] to (Player(TempInt)) and Change Color
                                • Set TempInt = TempINT
                              • 'ELSE'-Actions
                      • 'ELSE'-Actions
you need 4 different integer variables (or 1 array integer). the trigger itself loops through your city array (here i used 200 as max value for the array...change it to your max city array value) and then loops through the players from the last one who got a city up to the max number(if you have less than 12 players change each 12 in the trigger to your max player number).


(its not tested so if its not working ill rework it)
 
Level 2
Joined
Oct 22, 2012
Messages
17
Thank you for the response. I did my best to put those actions into a 'test' map with only 5 cities. I think I may have put things in erroneously but I can't figure out where. So I am posting this test map here and was hoping you could take a look a the trigger, it is under 'assign.'
 

Attachments

  • Risk Test1.1.w3x
    18.2 KB · Views: 40
Level 2
Joined
Oct 22, 2012
Messages
17
Thanks! This works great! Now I just need to transfer that trigger into my real map haha. Thanks so much! I'll let you know if I need anything else!
 
Status
Not open for further replies.
Top