HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Randomising Teams - Problems

04-20-2008, 07:54 PM#1
Fulla
This trigger is meant to randomise teams after each 'round', but for some reason, the last bit bugs.

I've tested this a few times with 2 ppl.
Note: Ppl_Heroes is a unit array for each players Hero

Collapse JASS:
function StartRound takes nothing returns nothing
    local unit array h
    local integer i=0
    local integer c=0
    local integer f=0
    local real x=0
    local real y=0
    local boolean t=false
    
  //Sort players, by finding out which players are available.
    loop
        exitwhen i>11
        if Ppl_Heroes[i]!=null then
            set h[c]=Ppl_Heroes[i]
            set c=c+1
        endif
        set i=i+1
    endloop
    
    call BJDebugMsg("ppl count: "+I2S(c))
    
  //Randomise the players into 2 Teams
    set i=0
    loop
        exitwhen c==0
        set i=GetRandomInt(0,c)
        if t==false then
            call ForceAddPlayer(TeamA,GetOwningPlayer(h[i]))
            call BJDebugMsg("Add Team 1")
            set t=true
        else
            call ForceAddPlayer(TeamB,GetOwningPlayer(h[i]))
            call BJDebugMsg("Add Team 2")
            set t=false
        endif
        set f=i
        loop
            exitwhen f==c
            set h[f]=h[f+1]
            set f=f+1
        endloop
        set c=c-1
    endloop
    
    
  //Set the two teams as Enemies BUGS!!
    set i=0
    set c=0
    loop
        exitwhen i>11
        if IsPlayerInForce(Player(i),TeamA) then
            call BJDebugMsg("Enemy")
            loop
                exitwhen c>11
                if IsPlayerInForce(Player(c),TeamB) then
                    call BJDebugMsg("Set") // This bit NEVER happens!!!
                    call SetPlayerAlliance(Player(i),Player(c),ConvertAllianceType(0),false)
                    call SetPlayerAlliance(Player(c),Player(i),ConvertAllianceType(0),false)
                endif
                set c=c+1
            endloop
        endif
        set i=i+1
        set c=0
    endloop

In DebugMsges I get:

- ppl count: 2
- Add Team A
- Add Team B
- Enemy

but no
- Set

I fail to see why?
04-20-2008, 10:44 PM#2
DioD
Code:
//Load players to temporal array p
loop
    if GetUnitTypeId(Ppl_Heroes[i]) != 0 then     //check if unit valid, otherwise you rist having Player(0) multiple times
        set p[c] = GetOwningPlayer(Ppl_Heroes[i])
        set c = c + 1
    endif
    set i = i + 1
    exitwhen i = 12
endloop

//c will now return number of players, we have 2 teams soo decide what will have one more player if value cant be dividend by 2

if ModuloInteger(c,2) != 0 then
    set someinteger = GetRandomInt(1,2)
    
    if someinteger = 1 then
        call ForceAddPlayer(TeamA,p[c])
    else
        call ForceAddPlayer(TeamB,p[c])
    endif
    set c = c - 1
endif

set maxplayerperteam = c / 2

//presetup complete

set ForceSetting = false

loop
    if ForceSetting == false then
        set i=GetRandomInt(1,2)
        if i = 1 then
            call ForceAddPlayer(TeamA,p[c])
            call BJDebugMsg("Add Team 1")
            set c = c -1
            set valueA = valueA + 1
            if valueA > maxplayerperteam then
                set ForceSetting = true
                set i = 2
            endif
        else
            call ForceAddPlayer(TeamB,p[c])
            call BJDebugMsg("Add Team 2")
            set c = c -1
            set valueB = valueB + 1
            if valueB > maxplayerperteam then
                set ForceSetting = true
                set i = 1
            endif
        endif
    else
        if i = 1 then
            call ForceAddPlayer(TeamA,p[c])
            call BJDebugMsg("Add Team 1")
            set c = c -1
            set valueA = valueA + 1
            exitwhen valueA > maxplayerperteam
        else
            call ForceAddPlayer(TeamB,p[c])
            call BJDebugMsg("Add Team 2")
            set c = c -1
            set valueB = valueB + 1
            exitwhen valueB > maxplayerperteam
        endif
    endif    
endloop

Try something like this.
04-20-2008, 11:10 PM#3
Fulla
thx alot, I'll check it out

in my trigger, c was causing all the problems, fixed it now