• 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.

Randomize ownership for every players.

Status
Not open for further replies.
Level 18
Joined
Jun 2, 2009
Messages
1,233
Hello everyone. In my Risk map i wanted to create normal mode.
Mod is simple. There are 120 barracks within map, i want to change 7 barracks ownership for each player.

Example: You and your 2 friends playing a game. There are 30 structures on the map but they are not belongs to you.
You wanted to get 7 of these for yourself and your friends too. But it should be random.
After the randomize, you get random 7 structures on the battleground. And your friends as well.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,286
The basic idea is that you add these barracks to a unit group and then for each player that needs random barracks you pick a random unit from that unit group, give it to the player and then also remove it from the unit group so it cannot be picked again. Repeat for how many random barracks you need for the player. Repeat for how many different players need random barracks from the group.
 
Level 18
Joined
Jun 2, 2009
Messages
1,233
The problem is, i don't know how to do that. Here is the triggers for capital mod. This mod gives only 1 barracks for the players.

  • Capital Mode Random Capital
    • Events
    • Conditions
    • Actions
      • Set TempInteger = (Random integer number between 1 and TOTAL_BARRACKS_COUNT)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • CapitalTaken[TempInteger] Equal to False
        • Then - Actions
          • Set CapitalTaken[TempInteger] = True
          • Set Capital[(Player number of TempPlayer)] = TempInteger
          • Unit - Change ownership of Barracks[TempInteger] to TempPlayer and Change color
          • Unit - Change ownership of Towers[TempInteger] to TempPlayer and Change color
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • OnlyPiyadeModOn Equal to True
            • Then - Actions
              • Unit - Add Chaos (Convert to OP Capital) to Barracks[TempInteger]
            • Else - Actions
              • Unit - Add Chaos (Convert to Capital) to Barracks[TempInteger]
          • Camera - Pan camera for TempPlayer to (Position of Barracks[TempInteger]) over 0.00 seconds
          • Selection - Select Barracks[TempInteger] for TempPlayer
        • Else - Actions
          • Trigger - Run (This trigger) (checking conditions)
This trigger gives 1 capital for each player. But i want to give each players to 7 random barracks.
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,873
The first step is to add all of your Barracks to a Unit Group. You can do it like this:
  • Events
  • Map initialization
  • Actions
  • Set Variable BarracksGroup = (Units in playable map area matching Unit-type of matching unit Equal to Barracks)
Now you have access to every single Barracks.

Next you'll want to add all of your active Players to a Player Group:
  • Events
  • Time - Elapsed time equal to 0.01 seconds
  • Actions
  • Set Variable ActivePlayers = (All players matching Player slot status Equal to Is Playing and Player controller Equal to User)
Now you have access to every User currently playing your map.

Then when it comes time to distribute the Barracks you simply Loop over the ActivePlayers player group:
  • Player Group - Pick every player in ActivePlayers and do actions:
And use a For Loop that loops 7 times, since we want to give out 7 Barracks:
  • For each integer (Integer A) from 1 to 7 do actions:
Inside of the For Loop you need to get a random Barracks and give it to the picked player:
  • Set Variable RandomBarracks = (Random unit from BarracksGroup)
  • Unit - Change ownership of RandomBarracks to (Picked player) and Change color
  • Unit Group - Remove RandomBarracks from BarracksGroup
And that's it. Now each active Player will receive 7 Barracks at random.


Side Note: Unit Group arrays need to have their array size initialized manually. Same goes for Player Groups and Timers. You would do this in the variable editor, most likely setting the size to whatever the highest possible [index] is. In a lot of cases this would be the highest player number.
 
Level 18
Joined
Jun 2, 2009
Messages
1,233
@Uncle You are amazing. Because you are explaning perfectly. Thank you for your interest. Now here it comes the most vital question. We have a problem in here. All barracks and their towers are linked to each other. Here is the part of the trigger.

  • RegionBarracksTowersVariableleri
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set COPName[1] = Dublin <gen>
      • Set Barracks[1] = Barracks 0052 <gen>
      • Set Towers[1] = Tower 0103 <gen>
      • Set COPName[2] = Glasgow <gen>
      • Set Barracks[2] = Barracks 0053 <gen>
      • Set Towers[2] = Tower 0108 <gen>
      • Set COPName[3] = Leeds <gen>
      • Set Barracks[3] = Barracks 0054 <gen>
      • Set Towers[3] = Tower 0113 <gen>
      • Set COPName[4] = London <gen>
      • Set Barracks[4] = Barracks 0056 <gen>
      • Set Towers[4] = Tower 0120 <gen>
      • Set COPName[5] = Southampton <gen>
      • Set Barracks[5] = Barracks 0055 <gen>
      • Set Towers[5] = Tower 0124 <gen>
  • And goes on like this until 89
COPName[1] Region Array
Barracks[1] Present Barracks
Towers[1] Present Towers.

I haven't tested it yet but even if they will work, we have to link to the towers too.. I am very sorry for this one...
 
Level 18
Joined
Jun 2, 2009
Messages
1,233
@Uncle You are amazing. Because you are explaning perfectly. Thank you for your interest. Now here it comes the most vital question. We have a problem in here. All barracks and their towers are linked to each other. Here is the part of the trigger.

  • RegionBarracksTowersVariableleri
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set COPName[1] = Dublin <gen>
      • Set Barracks[1] = Barracks 0052 <gen>
      • Set Towers[1] = Tower 0103 <gen>
      • Set COPName[2] = Glasgow <gen>
      • Set Barracks[2] = Barracks 0053 <gen>
      • Set Towers[2] = Tower 0108 <gen>
      • Set COPName[3] = Leeds <gen>
      • Set Barracks[3] = Barracks 0054 <gen>
      • Set Towers[3] = Tower 0113 <gen>
      • Set COPName[4] = London <gen>
      • Set Barracks[4] = Barracks 0056 <gen>
      • Set Towers[4] = Tower 0120 <gen>
      • Set COPName[5] = Southampton <gen>
      • Set Barracks[5] = Barracks 0055 <gen>
      • Set Towers[5] = Tower 0124 <gen>
  • And goes on like this until 89
COPName[1] Region Array
Barracks[1] Present Barracks
Towers[1] Present Towers.

I haven't tested it yet but even if they will work, we have to link to the towers too.. I am very sorry for this one...
Wow. Initially i am starting with 8 barracks, when i type this it gives me +7 barracks too. But the weird part is, all the map color is turquose. Player 10. I can find my own barracks while searching but their colors are Player 10 color in minimap

  • Normal Mode
    • Events
      • Player - Player 1 (Red) types a chat message containing -normal as An exact match
    • Conditions
      • FirstTurnEnd Equal to False
    • Actions
      • Set NormalModOn = True
      • Unit Group - Pick every unit in (Units in (Playable map area) matching (((Matching unit) is A structure) Equal to False)) and do (Actions)
        • Loop - Actions
          • Unit - Remove (Picked unit) from the game
      • Player Group - Pick every player in PlayingPlayers and do (Actions)
        • Loop - Actions
          • Player - Set (Picked player) Current gold to 20
          • Player - Set (Picked player) Current lumber to 1
      • For each (Integer A) from 1 to TOTAL_BARRACKS_COUNT, do (Actions)
        • Loop - Actions
          • Unit - Change ownership of Towers[(Integer A)] to Player 10 (Light Blue) and Change color
      • Player Group - Pick every player in PlayingPlayers and do (Actions)
        • Loop - Actions
          • For each (Integer A) from 1 to 7, do (Actions)
            • Loop - Actions
              • Set RandomBarracks = (Random unit from BarracksGroup)
              • Unit - Change ownership of RandomBarracks to (Picked player) and Change color
              • Unit Group - Remove RandomBarracks from BarracksGroup
 

Uncle

Warcraft Moderator
Level 73
Joined
Aug 10, 2018
Messages
7,873
I would use a Unit Indexer to link all of the Barracks to their Towers and vice versa. This way whenever you reference one, you can get the other:
  • Set Variable BuildingLink[custom value of barracks] = Tower
  • Set Variable BuildingLink[custom value of tower] = Barracks

I'm not sure about the color issues.
 
Status
Not open for further replies.
Top