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

Randomizing Player Colors

Status
Not open for further replies.
Level 6
Joined
Sep 19, 2005
Messages
169
I'm probably just not thinking hard enough, but I need to create a trigger that will randomize the player colors. I've manage to create a trigger that does this, but more specifically I need a trigger that will randomize player colors but make sure no two players are assigned the same color. I could always just individually change each players color (ie. Change Reds color to Green etc) but ideally each player would receive a different color in each game. (Player 1 is blue one game, next game player 1 is assigned a totally diff color)
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
In theory, I believe this should work:


  • Player Color
    • Events
      • Time - Elapsed game time is 1.00 seconds
    • Conditions
    • Actions
      • Player Group - Pick every player in (All players) and do (Player Group - Add (Picked player) to PlayerGroup)
      • For each (Integer A) from 1 to (number of players in PlayerGroup), do (Actions)
        • Loop - Actions
          • Set Player = (Random player from PlayerGroup)
          • Player - Change color of (Player((Integer A))) to (Color of Player), Changing color of existing units
          • Player Group - Remove Player from PlayerGroup
      • Custom script: call DestroyForce(udg_PlayerGroup)
It will pick a random player out of all players and change the color of player (integer A) to the color of the random player
The random player is then removed from the player group, to prevent 2 or more players having the same color



Although I've had some problems with the "All Players" in the past, you can also use "all players controlled by user/computer/neutral".
 
Level 28
Joined
Jan 26, 2007
Messages
4,789
Thats what I've tried, but occasionally I'll end up with players getting the same color

I guess that's why I have said "in theory".
I think that the cause of that is that not all players are in the player group, try doing "for each integer A from 1 to 12, add player(Integer A) to PlayerGroup".

If that doesn't work, my theory is incorrect :)
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,255
Well, for true random player colur, simply set all players to a random integer playercolour between 0 and 13 odd.

To stop duplicates you need to create a playercolour array and set it up with each index to the specified player colour with an integer of the last used slot. Then randomly choose one from the array, and get the last slot one to overwrite the used one and finally reduce the integer by one. Repeat and no duplicate colours would be present and colours would be random.
 
Level 6
Joined
Sep 19, 2005
Messages
169
Ok I think I somewhat understood what you said. I attempted something similar to what I believe you said, but it wasn't working like I wanted to it to. I did end up finding a method though... Involving 5 variables and one mega multiple layer if/then script...
 
Status
Not open for further replies.
Top