• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Help - Changing color of players to random color

Status
Not open for further replies.
Level 8
Joined
Oct 1, 2010
Messages
408
Hi, I'm trying to create a mode where, if selected, all players' names will be changed to Hidden and their colors will be changed to a random color.

The problem I'm having is figuring out how to randomly change a player's color. This is what I have so far:

  • Then - Actions
    • Do Multiple ActionsFor each (Integer A) from 1 to 12, do (Actions)
      • Loop - Actions
        • Player - Set name of (Player((Integer A))) to Hidden
Thank you for any help and plus rep

:grin:
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
pc is a playercolor variable without array, preset value does not matter.

  • For each (Integer A) from 1 to 12, do (Actions)
    • Loop - Actions
      • Player - Set name of (Player((Integer A))) to Hidden
      • Custom script: set udg_pc = ConvertPlayerColor(GetRandomInt(0, 11))
      • Player - Change color of (Player((Integer A))) to pc, ...
This includes the standard players' colors from red to brown.
 
Last edited:
  • For each (Integer A) from 1 to 12, do (Actions)
    • Loop - Actions
      • Player - Set name of (Player((Integer A))) to Hidden
      • Player - Change color of (Player((Integer A))) to (Color of (Player((Random integer number between 1 and 12)))), Changing color of existing units
Will do as well, but this your and my way will result some players end up with same colors.
 
Level 8
Joined
Oct 1, 2010
Messages
408
  • For each (Integer A) from 1 to 12, do (Actions)
    • Loop - Actions
      • Player - Set name of (Player((Integer A))) to Hidden
      • Player - Change color of (Player((Integer A))) to (Color of (Player((Random integer number between 1 and 12)))), Changing color of existing units
Will do as well, but this your and my way will result some players end up with same colors.

I haven't tested either of these methods, so please forgive me for that, but I just wanted to ask if there's a way to randomize colors and have it so that players won't end up as the same color.

Thank you both for the replies! +rep
 
There is way ofc, give me some time, will code that.

EDIT:

JASS:
function SetPlayerColors takes nothing returns nothing
    local integer i = 0
    local hashtable hash = InitHashtable()
    local group g = CreateGroup()
    local unit array u
    
    loop
    exitwhen i>11
        set u[i] = CreateUnit(Player(15), 'hfoo', 0,0,0)
        call SaveInteger(hash, 0, GetHandleId(u[i]), i)
        call GroupAddUnit(g, u[i])
        set u[i] = null
    set i = i + 1
    endloop
    
    set i = 0

    loop
    exitwhen i>11
        set u[12] = GroupPickRandomUnit(g)
        call GroupRemoveUnit(g, u[12])
        call SetPlayerColor(Player(i), ConvertPlayerColor(LoadInteger(hash, 0, GetHandleId(u[12]))))
        call RemoveUnit(u[12])
    set i = i + 1
    endloop
    
    call DestroyGroup(g)
    set g = null
    set u[12] = null
    call FlushParentHashtable(hash)
endfunction

Just call function from some other trigger like this:

  • Custom script: call SetPlayerColors()
I know it can be even more optimized, hashtable can be removed etc etc, but if someone like to work on it you are free to do so, I don't have time right now :)
 

Attachments

  • TestMap.w3x
    16.9 KB · Views: 56
Last edited:
Level 8
Joined
Oct 1, 2010
Messages
408
Awesome thanks a lot Kobas, but now I'm having trouble importing into the map. I tried just copy pasting the trigger over and got the error "Undeclared Function". So I tried making a new Jass trigger and then just copy pasting the text. Still got the error. Then I did some searches on the hive and found this http://www.hiveworkshop.com/forums/triggers-scripts-269/jass-undeclared-function-175107/ so I did what they suggested and tried putting the function above the trigger that calls the funciton. This fixed nothing. So, I tried their other suggestion and copy pasted the function into the map header. This just gave me a ton of other errors.

Sorry if the solution is simple or I'm just doing something wrong, I'm really new to triggers. But thank you so much for your help Kobas. +rep!
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
The code of trigger pages only gets sorted according to the left list when the map is reloaded. Else new pages travel to the bottom first. Direct function calls can only be made upwards. What's wrong with the header I do not know, it works for me. Maybe you have some name conflicts with other stuff in the map?

Another approach that requires the players hold the different colors at the beginning:

i is an integer variable without array, preset value does not matter.

  • For each (Integer A) from 1 to 12, do (Actions)
    • Loop - Actions
      • Player - Set name of (Player((Integer A))) to Hidden
      • Set i = (Random integer number between (Integer A) and 12)
      • Set pc = (Color of (Player((Integer A))))
      • Spieler - Change color of (Player((Integer A))) to (Color of (Player(i)))...
      • Player - Change color of (Player(i)) to pc...
 
Level 8
Joined
Oct 1, 2010
Messages
408
The code of trigger pages only gets sorted according to the left list when the map is reloaded. Else new pages travel to the bottom first. Direct function calls can only be made upwards. What's wrong with the header I do not know, it works for me. Maybe you have some name conflicts with other stuff in the map?

Another approach that requires the players hold the different colors at the beginning:

i is an integer variable without array, preset value does not matter.

  • For each (Integer A) from 1 to 12, do (Actions)
    • Loop - Actions
      • Player - Set name of (Player((Integer A))) to Hidden
      • Set i = (Random integer number between (Integer A) and 12)
      • Set pc = (Color of (Player((Integer A))))
      • Spieler - Change color of (Player((Integer A))) to (Color of (Player(i)))...
      • Player - Change color of (Player(i)) to pc...

I never would of thought of that... I feel dumb. Thanks so much both of you for your help. I'm going to use this method because it's easy for me to understand (I'm even more clueless about Jass then I am about GUI) and this way I won't waste anymore of your guys' time.

Thanks so much!! +rep

Edit: I am having a problem with the multiboard atm. First, it's not updating the colors but it is updating the names. Example, if player 1's color was changed from red to pink, his name on the multiboard is Hdden but his color on the multiboard is still red. Second, and I just realized this would be a problem, but now I need to randomly list players on the multiboard, otherwise player 1 will always be the first one on the multiboard etc. But I'll try and solve this myself first (in the morning, no time atm) before I use anymore of your guys' time. Again, thanks for all your help have a great day.
 
Last edited:
Player name is string, player color is well playercolor :D
2 different variable types :)

It can be fixed in few min.

EDIT:

JASS:
function SetPlayerColors takes nothing returns nothing
    local integer i = 0
    local group g = CreateGroup()
    local group array G
    
    local unit array u
    local unit temp
    local string array TXTC
    local hashtable hash = InitHashtable()
    
    set TXTC[0] = "|CFFFF0303"
    set TXTC[1] = "|c000042FF"
    set TXTC[2] = "|C0000FFFF"
    set TXTC[3] = "|c00540081"
    set TXTC[4] = "|c00FFFC01"
    set TXTC[5] = "|c00FEBA0E"
    set TXTC[6] = "|c0020C000"
    set TXTC[7] = "|c00E55BB0"
    set TXTC[8] = "|c00959697"
    set TXTC[9] = "|CFF7EBFF1"
    set TXTC[10] = "|CFF106246"
    set TXTC[11] = "|CFF4E2A04"
    
    // Here we make setup for changes below
    loop
    exitwhen i>11
        set u[i] = CreateUnit(Player(15), 'hfoo', 0,0,0)
        call SaveInteger(hash, 0, GetHandleId(u[i]), i)
        call SaveStr(hash, 0, GetHandleId(u[i]), TXTC[i])
        call GroupAddUnit(g, u[i])
        set u[i] = null
        set G[i] = CreateGroup()
        call GroupEnumUnitsOfPlayer(G[i], Player(i), null)
    set i = i + 1
    endloop
    
    set i = 0
    
    // Here we change everything :)
    loop
    exitwhen i>11
        set u[12] = GroupPickRandomUnit(g)
        call GroupRemoveUnit(g, u[12])
        // Player Color
        call SetPlayerColor(Player(i), ConvertPlayerColor(LoadInteger(hash, 0, GetHandleId(u[12]))))
        
        // Player Name
        call SetPlayerName(Player(i), LoadStr(hash, 0, GetHandleId(u[12])) + GetPlayerName(Player(i)))
        
        // All Units Owned by Player Color
        loop
            set temp = FirstOfGroup(G[i])
            exitwhen temp == null
            call GroupRemoveUnit(G[i], temp)
            call SetUnitColor(temp, ConvertPlayerColor(LoadInteger(hash, 0, GetHandleId(u[12]))))
        endloop
         
         // Cleaning Leaks
        call DestroyGroup(G[i])
        set G[i] = null
        call RemoveUnit(u[12])
    set i = i + 1
    endloop
    
    // Cleaning Leaks
    call DestroyGroup(g)
    set g = null
    set u[12] = null
    call FlushParentHashtable(hash)
endfunction

EDIT 2:

TestMap as well.
 

Attachments

  • TestMap.w3x
    18.6 KB · Views: 81
Last edited:
Level 8
Joined
Oct 1, 2010
Messages
408
OK, this did fix the colors on the multiboard but the problem I'm having is that when I put call SetPlayerColor in a condition statement then it doesn't work (even when the condition equals true or false). I'm guessing this is because the condition statement works with a GUI variable but I'm not sure. I'll attach the map, it uses NewGen and the UMSWE in NewGen. I just copy and pasted the Initialization folder into this map and then put the call SetPlayerColor into the trigger Start Game (which is in the folder Starting Triggers).

Testmode is initially set to 0 in the trigger Startmods (which is in the first folder, Intialization). It's set to 1 if player 1 activates an item in his invetory (before the triggers run during Host Selection). To test it, just start a game as player 1 and activate the item in your inventory called 'Test Mode'. Then activate the ability 'Start Game' or just wait for the timer to run out.

Sorry I didn't mention this before, I was going to last night but I thought I wouldn't need to since Waterknight's method was working, though now I see I also need to effect the multiboard as well. Thanks a lot Kobas, I've attached the map below.
 

Attachments

  • WoWRiskCata.w3x
    2.4 MB · Views: 57
I can't open map because you use USMWE and some of it's "Advanced" GUI functions.
Now when you told me that you use Jass New Gen I will convert this into vJass.

EDIT:

Copy and paste this anywhere it should work.
JASS:
scope PlayerColors initializer Init

    function SetPlayerColors takes nothing returns nothing
        local integer i = 0
        local group g = CreateGroup()
        local group array G
        
        local unit array u
        local unit temp
        local string array TXTC
        local hashtable hash = InitHashtable()
        
        set TXTC[0] = "|CFFFF0303"
        set TXTC[1] = "|c000042FF"
        set TXTC[2] = "|C0000FFFF"
        set TXTC[3] = "|c00540081"
        set TXTC[4] = "|c00FFFC01"
        set TXTC[5] = "|c00FEBA0E"
        set TXTC[6] = "|c0020C000"
        set TXTC[7] = "|c00E55BB0"
        set TXTC[8] = "|c00959697"
        set TXTC[9] = "|CFF7EBFF1"
        set TXTC[10] = "|CFF106246"
        set TXTC[11] = "|CFF4E2A04"
        
        // Here we make setup for changes below
        loop
        exitwhen i>11
            set u[i] = CreateUnit(Player(15), 'hfoo', 0,0,0)
            call SaveInteger(hash, 0, GetHandleId(u[i]), i)
            call SaveStr(hash, 0, GetHandleId(u[i]), TXTC[i])
            call GroupAddUnit(g, u[i])
            set u[i] = null
            set G[i] = CreateGroup()
            call GroupEnumUnitsOfPlayer(G[i], Player(i), null)
        set i = i + 1
        endloop
        
        set i = 0
        
        // Here we change everything :)
        loop
        exitwhen i>11
            set u[12] = GroupPickRandomUnit(g)
            call GroupRemoveUnit(g, u[12])
            // Player Color
            call SetPlayerColor(Player(i), ConvertPlayerColor(LoadInteger(hash, 0, GetHandleId(u[12]))))
            
            // Player Name
            call SetPlayerName(Player(i), LoadStr(hash, 0, GetHandleId(u[12])) + GetPlayerName(Player(i)))
            
            // All Units Owned by Player Color
            loop
                set temp = FirstOfGroup(G[i])
                exitwhen temp == null
                call GroupRemoveUnit(G[i], temp)
                call SetUnitColor(temp, ConvertPlayerColor(LoadInteger(hash, 0, GetHandleId(u[12]))))
            endloop
             
             // Cleaning Leaks
            call DestroyGroup(G[i])
            set G[i] = null
            call RemoveUnit(u[12])
        set i = i + 1
        endloop
        
        // Cleaning Leaks
        call DestroyGroup(g)
        set g = null
        set u[12] = null
        call FlushParentHashtable(hash)
    endfunction
    
    function Init takes nothing returns nothing
        call SetPlayerColors()
        call FogModifierStart( CreateFogModifierRect(Player(0), FOG_OF_WAR_VISIBLE, bj_mapInitialPlayableArea, true, false) )
    endfunction
    
endscope
 
Level 8
Joined
Oct 1, 2010
Messages
408
Darn, sorry Kobas, I did like you said and just copied your new script and pasted it into the old one (after deleting the old scripts text) but I'm still getting the undeclared function error. It works just fine when I leave call SetPlayerColors() in the folder I originally copied it from, but the moment I remove it from that trigger and put it in the condition statement I get the undeclared function error when I try to save the map. Sorry for all this hassle.
 
Level 3
Joined
Nov 16, 2011
Messages
54
Why bothering with JASS when there are 8 lines in GUI that will do the trick?
  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Set Color[(Integer A)] = (Color of (Player((Integer A))))
      • Set PlayerGroup = (All players controlled by a User player)
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Player Group - Pick every player in (Player group((Random player from PlayerGroup))) and do (Actions)
            • Loop - Actions
              • Player - Change color of (Picked player) to Color[(Integer A)], Changing color of existing units
              • Player - Set name of (Picked player) to I am Invisible
 
Level 3
Joined
Nov 16, 2011
Messages
54
Yes i forgot to remove the player
  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Set Color[(Integer A)] = (Color of (Player((Integer A))))
      • Set PlayerGroup = (All players controlled by a User player)
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Player Group - Pick every player in (Player group((Random player from PlayerGroup))) and do (Actions)
            • Loop - Actions
              • Player - Change color of (Picked player) to Color[(Integer A)], Changing color of existing units
              • Player - Set name of (Picked player) to I am Invisible
              • Player Group - Remove (Picked player) from PlayerGroup
Edit:
JASS Still shorter? :)
JASS:
function Trig_Melee_Initialization_Func003Func001A takes nothing returns nothing
    call SetPlayerColorBJ( GetEnumPlayer(), udg_Color[GetForLoopIndexA()], true )
    call SetPlayerName( GetEnumPlayer(), "TRIGSTR_001" )
    call ForceRemovePlayerSimple( GetEnumPlayer(), udg_PlayerGroup )
endfunction

function Trig_Melee_Initialization_Actions takes nothing returns nothing
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 12
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        set udg_Color[GetForLoopIndexA()] = GetPlayerColor(ConvertedPlayer(GetForLoopIndexA()))
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    set udg_PlayerGroup = GetPlayersByMapControl(MAP_CONTROL_USER)
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 12
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        call ForForce( GetForceOfPlayer(ForcePickRandomPlayer(udg_PlayerGroup)), function Trig_Melee_Initialization_Func003Func001A )
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
endfunction

//===========================================================================
function InitTrig_Melee_Initialization takes nothing returns nothing
    set gg_trg_Melee_Initialization = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Melee_Initialization, function Trig_Melee_Initialization_Actions )
endfunction
 
Red line of code will call another function.
When you split everything you get this:

JASS:
function SetPlayerColorBJEnumX takes nothing returns nothing
    call SetUnitColor(GetEnumUnit(), bj_setPlayerTargetColor)
endfunction

function ForcePickRandomPlayerEnumX takes nothing returns nothing
    set bj_forceRandomConsidered = bj_forceRandomConsidered + 1
    if (GetRandomInt(1,bj_forceRandomConsidered) == 1) then
        set bj_forceRandomCurrentPick = GetEnumPlayer()
    endif
endfunction

function SetPlayerColorBJX takes player whichPlayer, playercolor color, boolean changeExisting returns nothing
    local group g

    call SetPlayerColor(whichPlayer, color)
    if changeExisting then
        set bj_setPlayerTargetColor = color
        set g = CreateGroup()
        call GroupEnumUnitsOfPlayer(g, whichPlayer, null)
        call ForGroup(g, function SetPlayerColorBJEnumX)
        call DestroyGroup(g)
    endif
endfunction

function ForceRemovePlayerSimpleX takes player whichPlayer, force whichForce returns nothing
    call ForceRemovePlayer(whichForce, whichPlayer)
endfunction


function ConvertedPlayerX takes integer convertedPlayerId returns player
    return Player(convertedPlayerId - 1)
endfunction


function GetForLoopIndexAX takes nothing returns integer
    return bj_forLoopAIndex
endfunction


function GetPlayersByMapControlX takes mapcontrol whichControl returns force
    local force f = CreateForce()
    local integer playerIndex
    local player  indexPlayer

    set playerIndex = 0
    loop
        set indexPlayer = Player(playerIndex)
        if GetPlayerController(indexPlayer) == whichControl then
            call ForceAddPlayer(f, indexPlayer)
        endif

        set playerIndex = playerIndex + 1
        exitwhen playerIndex == bj_MAX_PLAYER_SLOTS
    endloop

    return f
endfunction

function GetForceOfPlayerX takes player whichPlayer returns force
    local force f = CreateForce()
    call ForceAddPlayer(f, whichPlayer)
    return f
endfunction

function ForcePickRandomPlayerX takes force whichForce returns player
    set bj_forceRandomConsidered = 0
    set bj_forceRandomCurrentPick = null
    call ForForce(whichForce, function ForcePickRandomPlayerEnumX)
    return bj_forceRandomCurrentPick
endfunction

function Trig_Melee_Initialization_Func003Func001A takes nothing returns nothing
    call SetPlayerColorBJX( GetEnumPlayer(), udg_Color[GetForLoopIndexAX()], true )
    call SetPlayerName( GetEnumPlayer(), "TRIGSTR_001" )
    call ForceRemovePlayerSimpleX( GetEnumPlayer(), udg_PlayerGroup )
endfunction

function Trig_Melee_Initialization_Actions takes nothing returns nothing
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 12
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        set udg_Color[GetForLoopIndexAX()] = GetPlayerColor(ConvertedPlayerX(GetForLoopIndexAX()))
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
    set udg_PlayerGroup = GetPlayersByMapControlX(MAP_CONTROL_USER)
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 12
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        call ForForce( GetForceOfPlayerX(ForcePickRandomPlayerX(udg_PlayerGroup)), function Trig_Melee_Initialization_Func003Func001A )
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
endfunction

//===========================================================================
function InitTrig_Melee_Initialization takes nothing returns nothing
    set gg_trg_Melee_Initialization = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Melee_Initialization, function Trig_Melee_Initialization_Actions )
endfunction
Where is X added at the end of each "red function".
 
Level 3
Joined
Nov 16, 2011
Messages
54
The only thing that was clear to me was that you just said that blizzard are unable to convert GUI to JASS. I got no idea how JASS is working this is why i ask for help people like you that are familiar with it and thanks to them i manage to do my goals. Yet my priority is to keep things simple and working as intended. I already noticed that this guy like me is not familiar with JASS. Yet now i finally am able to see of parts how JASS works yet it's 2 late because warcraft is alive no more for me. My only goal is to pass as much GUI knowledge to the new people as possible and I am sure most of them like me will be unable to find out how JASS work for years to come.
 
Level 8
Joined
Oct 1, 2010
Messages
408
Here is the condition statement, I didn't copy the entire trigger because it is massive and unrelated to the call SetPlayerColors.

  • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • Testmode Equal to (==) 1
    • Then - Actions
      • Do Multiple ActionsFor each (Integer A) from 1 to 11, do (Actions)
        • Loop - Actions
          • Custom script: call SetPlayerColors()
      • Trigger - Turn on Test Duplify <gen>
      • Trigger - Turn on Test Remove <gen>
      • Trigger - Turn on Test Teleport <gen>
      • Trigger - Turn on Test heros <gen>
      • Trigger - Turn on Test Enemy <gen>
      • Trigger - Turn on test <gen>
    • Else - Actions
Testmode is initially set to 0 and set to 1 in-game via clicking an item if you're red. Is there a way to just disable this part of the trigger and having it run when testmode is == 1 (like you suggested) without disabling the rest?
 
Last edited:
Level 8
Joined
Oct 1, 2010
Messages
408
Yes i forgot to remove the player
  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Set Color[(Integer A)] = (Color of (Player((Integer A))))
      • Set PlayerGroup = (All players controlled by a User player)
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Player Group - Pick every player in (Player group((Random player from PlayerGroup))) and do (Actions)
            • Loop - Actions
              • Player - Change color of (Picked player) to Color[(Integer A)], Changing color of existing units
              • Player - Set name of (Picked player) to I am Invisible
              • Player Group - Remove (Picked player) from PlayerGroup

Kadabra does this do anything that Waterknight's trigger doesn't? Sorry I just can't tell, but if not I'd like to just stick with Waterknight's because it's easier for me to read. Thanks for the help +rep

  • For each (Integer A) from 1 to 12, do (Actions)
    • Loop - Actions
      • Player - Set name of (Player((Integer A))) to Hidden
      • Set i = (Random integer number between (Integer A) and 12)
      • Set pc = (Color of (Player((Integer A))))
      • Spieler - Change color of (Player((Integer A))) to (Color of (Player(i)))...
      • Player - Change color of (Player(i)) to pc...
Sorry for double posting I didn't want to confuse you guys with all my quotes.
 
nickel510 :)
Did you checked my trigger it will randomize colors for all players.
  • Do Multiple ActionsFor each (Integer A) from 1 to 11, do (Actions)
    • Loop - Actions
      • Custom script: call SetPlayerColors()
Will do it 11 times :D
Just remove for and place call SetPlayerColors there instead.
  • If - Conditions
    • Testmode Equal to (==) 1
  • Then - Actions
    • Custom script: call SetPlayerColors()
 
Level 8
Joined
Oct 1, 2010
Messages
408
nickel510 :)
Did you checked my trigger it will randomize colors for all players.
  • Do Multiple ActionsFor each (Integer A) from 1 to 11, do (Actions)
    • Loop - Actions
      • Custom script: call SetPlayerColors()
Will do it 11 times :D
Just remove for and place call SetPlayerColors there instead.
  • If - Conditions
    • Testmode Equal to (==) 1
  • Then - Actions
    • Custom script: call SetPlayerColors()
HeHe I did read your trigger >< lol I don't know how I missed that, I have to go to work soon but I will do this when I get home wow I feel silly.

call SetPlayerColors()

Do not forget the paranthesis that mark beginning and ending of passed arguments.

Yeah sorry I did have the () in the trigger I just forgot to add them in the quote.
 
Level 3
Joined
Nov 16, 2011
Messages
54
Kadabra does this do anything that Waterknight's trigger doesn't? Sorry I just can't tell, but if not I'd like to just stick with Waterknight's because it's easier for me to read. Thanks for the help +rep

  • For each (Integer A) from 1 to 12, do (Actions)
    • Loop - Actions
      • Player - Set name of (Player((Integer A))) to Hidden
      • Set i = (Random integer number between (Integer A) and 12)
      • Set pc = (Color of (Player((Integer A))))
      • Spieler - Change color of (Player((Integer A))) to (Color of (Player(i)))...
      • Player - Change color of (Player(i)) to pc...
Sorry for double posting I didn't want to confuse you guys with all my quotes.

It's not how you read a trigger it's if you know how it works. And if you "read" it careful you will have realised that his trigger return brown for player 12 every time .... :ogre_icwydt::vw_death:
 
Level 3
Joined
Nov 16, 2011
Messages
54
Nope, does not. There is no color change at the last iteration but the color of any player and brown might be swapped before.

"might be" be is not like "will be" and no player 12 will keep his color because
  • Set i = (Random integer number between (Integer A) and 12)
how much is (Random integer number between (12) and 12)?

Some times I wonder why i even bother explaining to people the basics of logic. Yes I am NAZI and SPAMER you can hate me but you can't prove my logic is wrong!
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
"Might be" because it's randomized. I have already admitted that there is no change on iteration 12 but for example on first run, a number between 1 and 12 is rolled. If it hits 12, Player 1 swaps its color with that of Player 12, meaning Player 1 gets Brown, Player 12 Red.
 
Last edited:
Level 8
Joined
Oct 1, 2010
Messages
408
Alright this is what I did then:

  • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • Testmode Equal to (==) 1
    • Then - Actions
      • Custom script: call SetPlayerColors()
    • Else - Actions
However it still doesn't work, same error as before. I can't disable the trigger because this above function is inside a much bigger trigger that has to stay enabled.

This is actually much more complicated then I first realized. For the past couple days I've been lworking on this problem with practically no results. I'm sorry Kobas but I was wrong when I said I needed to have the color of player names changed as well. I thought I needed them changed because of the multiboard, but now I realize that the multiboard can show colored names with scripts that contain color codes. Now my real problem is figuring out how to make the multiboard sort players by color and not by their number, or if it's possible randomize player numbers instead of their color.

However, it's not that simple since the sorting of players on the multiboard isn't static and changes every turn according to stats. This is where it gets really complicated but I know its possible because Risk Next Gen and Risk Devo both do what I'm trying to. One of my biggest problems is trying to decipher and understand the triggers used to create the Multiboard and update it, which Priwin made. There's so many variables and I don't understand what most of the triggers (involving the multiboard) even do. Like I understand when the basics of what the trigger is doing, but I don't understand the relationship between all these variables that he's using together.

I'm sorry if I've wasted any of your guys' time, I've read a multiboard tutorial now and I think I understand how to make a simple multiboard but there's still some very advanced things that Priwin did in these triggers that I can't find a reason for. I understand totally if you guys don't want to spend anymore time trying to help me with this. But if you do, and I ask that you please do lol, then I can paste some of the triggers that are confusing me here or maybe you could open up the map? Again I totally understand if you don't want to get involved with this as I am clearly in over my head here.

Regardless, sorry for the long post but +rep to all you guys. Thanks for your help!! You guys are awesome.
 
Level 3
Joined
Nov 16, 2011
Messages
54
You just said that you need to randomize the players into your multiboard and after this you said the players are randomized after each round. Creating a multiboard is not that simple if it's your first time but with some experiments you will get it done. Upgrading the multiboard is done by updating all of the params you have added into your multiboard by using variables because you can set them into other triggers related to the stats of the players. There are many ways to update multiboards but the most simple and efficient in my opinion is with periodic event. When you have actually created and multiboard and if you still have problems doing something post a thread here. Until then there are enough tutorials i believe about creating multiboards. If you are still stuck after reading them you can open a map that already have one and try doing your job with it until you find out how they work. But again find out what is your exact problem and then ask how to solve it.

@WaterKnight
Swapping is not like randomizing because if you find one of the players and you know he was player 1 in the game start and his color is blue, now this mean that the player 2 in the game start will be red. Not to mention your trigger can return same color to 10 players which will be amusing. Not to mention the above bug that player 12 will always be brown and some players will have same colors which i don't know if it's even possible.
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
@WaterKnight
Swapping is not like randomizing because if you find one of the players and you know he was player 1 in the game start and his color is blue, now this mean that the player 2 in the game start will be red. Not to mention your trigger can return same color to 10 players which will be amusing. Not to mention the above bug that player 12 will always be brown and some players will have same colors which i don't know if it's even possible.

My requirement (which I stated) was that all colors would be available once within the player pool. The script will shuffle those colors then and each player gains another color. It won't be that Player 12 always ends up Brown. Just try it out, if you do not believe me.
 
Level 3
Joined
Nov 16, 2011
Messages
54
My requirement (which I stated) was that all colors would be available once within the player pool. The script will shuffle those colors then and each player gains another color. It won't be that Player 12 always ends up Brown. Just try it out, if you do not believe me.

True true player 12 is not always brown. Yet when you test it pick a color and follow it's path and count how many times you will have to swap colors in order this color to go through all units. I picked the Red color for testing your trigger and it took 30+ times for this color to be obtained at least once from every unit.
Edit: Note that the red color is going very often to the same 4-5 units again and again and again.
Edit: Your trigger is working as intended yet it's not the best choice for such a simple thing that will take you less than 5 minutes to make.
 

Attachments

  • Da Test.w3x
    19.3 KB · Views: 34
Level 26
Joined
Aug 18, 2009
Messages
4,097
n=12

The odds of Player 1 getting Red are 1/n
The odds of Player 1 getting any other color are 1/n

How can Player 2 get Red? By Player 1 not picking Red in the first run and Player 2 picking it in the second run: (n-1)/n*1/(n-1) = 1/n
How can Player 2 get Blue? By Player 1 not picking Blue in the first run and Player 2 picking it in the second run: (n-1)/n*1/(n-1) = 1/n
How can Player 2 get any other color? By Player 1 not picking that color in the first run and Player 2 picking it in the second run: (n-1)/n*1/(n-1) = 1/n

How can Player 3 get Red? By Player 1 not picking Red in the first run, Player 2 not picking it in the second run and Player 3 picking it in the third run: (n-1)/n*(n-2)/(n-1)*1/(n-2) = 1/n
How can Player 3 get Blue? By Player 1 not picking Blue in the first run, Player 2 not picking it in the second run and Player 3 picking it in the third run: (n-1)/n*(n-2)/(n-1)*1/(n-2) = 1/n
How can Player 3 get any other color? By Player 1 not picking that color in the first run, Player 2 not picking it in the second run and Player 3 picking it in the third run: (n-1)/n*(n-2)/(n-1)*1/(n-2) = 1/n

How can Player X get any color? By Player 1 not picking that color in the first run, Player 2 not picking it in the second run, ..., Player (X-1) not picking it in the (X-1)-th run, Player X picking it in the X-th run: (n-1)/n*(n-2)/(n-1)*...*(n-(X-1))/(n-((X-1)-1))*1/(n-(X-1)) = 1/n

Can easily see that the numerator always cancels itself out with the denominator of the next run, therefore only the first denominator and the last numerator remain and those are 1/n.

So every player has the same odds to gain any color.

What do you find so baffling about that it has taken 30 times until everyone had Red at least once?
 
Level 3
Joined
Nov 16, 2011
Messages
54
What i found odd is this way no matter that it should not work at all by my logic it work yet it does have pattern of swapping the colors. As i said until one color pass through all players it will take longer than by using the random option i provided. Just check for 2-3 colors how long it will take for them to pass every player and write the results (map restarts are needed as to start clear) then check out my trigger with the same colors and write down how much passes are needed. Then compare the results. Yes logic dictates that odds may be against me no matter how small they are. Yet knowing that mine is randomizing as much as possible for warcraft and your is working in some bizzare way that i can't get even how is possible to work but w/e. As I said before I believe that for such a simple things is better to optimize the solution as much a possible and use the best we got.
 
Status
Not open for further replies.
Top