Can't Efficiently Make Trigger T.T (Very Difficult)

Frosthowl

TH.net Regular
Reaction score
15
Ok, ive been stuck on this all day...ive done it in both gui and jass... I need to do the following: I have an array of integers from 0-7, 0 being player red and 7 being player pink. I need to find a way to make it so that the array randomly gives each integer a value of someone else's player number. None of the integers can be the same, nor can they be the same number as the integers position in the array...

To make it easier to understand...lets say players red(0), teal(2), and purple(3) are all in the game. The game needs to assign the integer in position 0 to have the value of 2 or 3 (lets say 2). The integer in position 2 would then be assigned a 3. The integer in position 3 must then be assigned to 0. Notice that even though blue is not present, it does not assign him a value. The numbers must be randomly assigned as well to make it rotate each round.

+Rep for solving this, thanks and GL! Ask if you need clarification.
 

Frosthowl

TH.net Regular
Reaction score
15
Finaly! Got it working

Code:
function Trig_Shuffle_Actions takes nothing returns nothing
    local integer i = 0
    local integer j = 0
    local integer l = GetRandomInt(0, 20)
    local integer x
    local integer q
    local integer array a
    local integer array b
    local integer c
    local integer d
    local integer e
    local integer f
    
    //Checks who is in the game and adds their numbers to an array with a being their number and b being their target
    loop
        exitwhen i > 7
        if GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING then
            set a[j] = i
            set b[j] = i+1
            set j = j + 1
        endif
        set i = i + 1
    endloop
    
    //Sets up the arrays to begin sorting
    set q = j - 1
    set i = 0
    loop
        exitwhen i > q
        if i == q then
            set b[i] = a[0]
        else
            set b[i] = a[i + 1]
        endif
        set i = i + 1
    endloop
    
    //Randomly mixes the array targets
    loop
        exitwhen l == 0
        set c = GetRandomInt(0, j-1)
        set d = GetRandomInt(0, j-1)
        if c != b[d] and d != b[c] then
            set e = b[c]
            set f = b[d]
            set b[d] = e
            set b[c] = f
            set l = l-1  
        endif
    endloop
    
    //Sets the array values into the final global array
    set i = 0
    loop
        exitwhen i > q
        set udg_PlayerTargets[a[i]] = b[i]
        set i = i + 1
    endloop
endfunction

That was fun =P
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top