Customizable team options

D

dArKzEr0

Guest
This was originally posted in the World Editor Help Zone under MrApple's "A Very Long Problem" thread, but I believe it's better suited in this subforum. Anyway, the trigger is supposed to do what MrApples originally tried to do, though in JASS and IMO more effectively. I really don't have the time to debug it, I'm actually moving out in a little over a week and won't have much time for any mapping once that happens. Anyway, I was hoping someone could read through this for obvious bugs or ways to make the code more efficient.

Triggers:
Code:
GameSetup
    Events
        Time - Elapsed game time is 0.01 seconds
    Conditions
    Actions
        Custom script:   call GameSetup()
Code:
PlayersPerTeam IsClicked
    Events
        Dialog - A dialog button is clicked for Dialog_PlayersPerTeam
    Conditions
    Actions
        Custom script:   call PlayersPerTeam_Algorithm()
Code:
SelectCorner IsClicked
    Events
        Dialog - A dialog button is clicked for Dialog_SelectCorner
    Conditions
    Actions
        Custom script:   call SelectCorner_IsClicked()
Custom Script Code:
Code:
// ===========================================================================
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// = = =                  Variable Setting Functions                     = = =
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// ===========================================================================
function Set_Buttons takes nothing returns nothing
    if (CountPlayersInForceBJ(udg_PlayersPlaying) <= 8) then
        set udg_Buttons_PlayersPerTeam[1] = DialogAddButton(udg_Dialog_PlayersPerTeam, "Teams of 1", 1)
    endif
    if (CountPlayersInForceBJ(udg_PlayersPlaying) >= 3) then
        set udg_Buttons_PlayersPerTeam[2] = DialogAddButton(udg_Dialog_PlayersPerTeam, "Teams of 2", 2)
    endif
    if (CountPlayersInForceBJ(udg_PlayersPlaying) >= 4) then
        set udg_Buttons_PlayersPerTeam[3] = DialogAddButton(udg_Dialog_PlayersPerTeam, "Teams of 3", 3)
    endif
    if (CountPlayersInForceBJ(udg_PlayersPlaying) >= 5) then
        set udg_Buttons_PlayersPerTeam[4] = DialogAddButton(udg_Dialog_PlayersPerTeam, "Teams of 4", 4)
    endif
    if (CountPlayersInForceBJ(udg_PlayersPlaying) == 10) then
        set udg_Buttons_PlayersPerTeam[5] = DialogAddButton(udg_Dialog_PlayersPerTeam, "Teams of 5", 5)
    endif
    set udg_Buttons_SelectCorner[0] = DialogAddButton(udg_Dialog_SelectCorner, "No Preference", 0)
    set udg_Buttons_SelectCorner[1] = DialogAddButton(udg_Dialog_SelectCorner, "Top Right", 1)
    set udg_Buttons_SelectCorner[2] = DialogAddButton(udg_Dialog_SelectCorner, "Top Left", 2)
    set udg_Buttons_SelectCorner[3] = DialogAddButton(udg_Dialog_SelectCorner, "Bottom Left", 3)
    set udg_Buttons_SelectCorner[4] = DialogAddButton(udg_Dialog_SelectCorner, "Bottom Right", 4)
endfunction
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
function Set_Regions takes nothing returns nothing
    set udg_Corner1[1] = gg_rct_Quadrant1_Loc1
    set udg_Corner1[2] = gg_rct_Quadrant1_Loc2
    set udg_Corner1[3] = gg_rct_Quadrant1_Loc3
    set udg_Corner1[4] = gg_rct_Quadrant1_Loc4
    set udg_Corner1[5] = gg_rct_Quadrant1_Loc5
    set udg_Corner2[1] = gg_rct_Quadrant2_Loc1
    set udg_Corner2[2] = gg_rct_Quadrant2_Loc2
    set udg_Corner2[3] = gg_rct_Quadrant2_Loc3
    set udg_Corner2[4] = gg_rct_Quadrant2_Loc4
    set udg_Corner2[5] = gg_rct_Quadrant2_Loc5
    set udg_Corner3[1] = gg_rct_Quadrant3_Loc1
    set udg_Corner3[2] = gg_rct_Quadrant3_Loc2
    set udg_Corner3[3] = gg_rct_Quadrant3_Loc3
    set udg_Corner3[4] = gg_rct_Quadrant3_Loc4
    set udg_Corner3[5] = gg_rct_Quadrant3_Loc5
    set udg_Corner4[1] = gg_rct_Quadrant4_Loc1
    set udg_Corner4[2] = gg_rct_Quadrant4_Loc2
    set udg_Corner4[3] = gg_rct_Quadrant4_Loc3
    set udg_Corner4[4] = gg_rct_Quadrant4_Loc4
    set udg_Corner4[5] = gg_rct_Quadrant4_Loc5
endfunction
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
function Set_Barracks takes nothing returns nothing
    set udg_Barracks_Corner1[1] = gg_unit_hbar_0271
    set udg_Barracks_Corner1[2] = gg_unit_hbar_0041
    set udg_Barracks_Corner1[3] = gg_unit_hbar_0272
    set udg_Barracks_Corner1[4] = gg_unit_hbar_0040
    set udg_Barracks_Corner1[5] = gg_unit_hbar_0042
    set udg_Barracks_Corner2[1] = gg_unit_hbar_0038
    set udg_Barracks_Corner2[2] = gg_unit_hbar_0037
    set udg_Barracks_Corner2[3] = gg_unit_hbar_0265
    set udg_Barracks_Corner2[4] = gg_unit_hbar_0039
    set udg_Barracks_Corner2[5] = gg_unit_hbar_0266
    set udg_Barracks_Corner3[1] = gg_unit_hbar_0047
    set udg_Barracks_Corner3[2] = gg_unit_hbar_0046
    set udg_Barracks_Corner3[3] = gg_unit_hbar_0270
    set udg_Barracks_Corner3[4] = gg_unit_hbar_0048
    set udg_Barracks_Corner3[5] = gg_unit_hbar_0267
    set udg_Barracks_Corner4[1] = gg_unit_hbar_0269
    set udg_Barracks_Corner4[2] = gg_unit_hbar_0045
    set udg_Barracks_Corner4[3] = gg_unit_hbar_0268
    set udg_Barracks_Corner4[4] = gg_unit_hbar_0043
    set udg_Barracks_Corner4[5] = gg_unit_hbar_0044
endfunction
// ===========================================================================
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// = = =                End ofVariable Setting Functions                 = = =
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// ===========================================================================

// ===========================================================================
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// = = =                      Ordering Functions                         = = =
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// = = =     FirstPriority(a,b,c,d) returns the location (1-4) of        = = =
// = = =     the largeest numerical value of an integer set a,b,c,d      = = =
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// = = =     SecondPriority(a,b,c,d) returns the location (1-4) of the   = = =
// = = =     second largest numerical value of an integer set a,b,c,d    = = =
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// = = =     ThirdPriority(a,b,c,d) returns the location (1-4) of the    = = =
// = = =     third largest numerical value of an integer set a,b,c,d     = = =
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// = = =     LastPriority(a,b,c,d) returns the location (1-4) of the     = = =
// = = =     fourth highest numerical value of an integer set a,b,c,d    = = =
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// ===========================================================================
function FirstPriority takes integer int1, integer int2, integer int3, integer int4 returns integer
    local integer loopX
    local integer a
    local integer b
    local integer c
    local integer d
    local integer array corner
    local integer priority    
    set corner[1] = int1
    set corner[2] = int2
    set corner[3] = int3
    set corner[4] = int4    
    if ( corner[1] >= corner[2] ) then
        set c = corner[1]
        set d = corner[2]
    else
        set d = corner[1]
        set c = corner[2]
    endif    
    if ( c >= corner[3] ) then
        set b = c
        set c = corner[3]
    else
        set b = corner[3]
    endif    
    if ( b >= corner[4] ) then
        set a = b
        set b = corner[4]
    else
        set a = corner[4]
    endif
    set loopX = 4
    loop
        exitwhen loopX < 1
        if ( corner[loopX] == a ) then
            set priority = loopX
        endif
        set loopX = loopX-1
    endloop    
    return priority    
endfunction
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
function SecondPriority takes integer int1, integer int2, integer int3, integer int4 returns integer
    local integer array corner
    local integer priority   
    set corner[1] = int1
    set corner[2] = int2
    set corner[3] = int3
    set corner[4] = int4    
    set priority = FirstPriority( corner[1],corner[2],corner[3],corner[4] )
    set corner[priority] = -3
    set priority = FirstPriority( corner[1],corner[2],corner[3],corner[4] )   
    return priority    
endfunction
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
function ThirdPriority takes integer int1, integer int2, integer int3, integer int4 returns integer
    local integer array corner
    local integer priority    
    set corner[1] = int1
    set corner[2] = int2
    set corner[3] = int3
    set corner[4] = int4    
    set priority = FirstPriority( corner[1],corner[2],corner[3],corner[4] )
    set corner[priority] = -3
    set priority = FirstPriority( corner[1],corner[2],corner[3],corner[4] )
    set corner[priority] = -2
    set priority = FirstPriority( corner[1],corner[2],corner[3],corner[4] )
    return priority    
endfunction
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
function LastPriority takes integer int1, integer int2, integer int3, integer int4 returns integer
    local integer array corner
    local integer priority
    set corner[1] = int1
    set corner[2] = int2
    set corner[3] = int3
    set corner[4] = int4
    set priority = FirstPriority( corner[1],corner[2],corner[3],corner[4] )
    set corner[priority] = -3
    set priority = FirstPriority( corner[1],corner[2],corner[3],corner[4] )
    set corner[priority] = -2
    set priority = FirstPriority( corner[1],corner[2],corner[3],corner[4] )
    set corner[priority] = -1
    set priority = FirstPriority( corner[1],corner[2],corner[3],corner[4] )
    return priority    
endfunction
// ===========================================================================
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// = = =                 End of Ordering Functions                       = = =
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// ===========================================================================

// ===========================================================================
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// = = =                     Game Setup Functions                        = = =
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// = = =       Note: These functions are read from bottom to top         = = =
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// ===========================================================================
function AssignLocation takes nothing returns nothing
    local integer a
    local integer array positionTaken
    local player tempPlayer
    local force array tempTeam
    local group tempGroup
    local unit tempUnit
    set a = 1
    loop
        exitwhen a > udg_NumOfTeams
        set tempTeam[a] = udg_Team[a]
        set a = a+1
    endloop
    set a = 1
    loop
        exitwhen a > 20
        set positionTaken[a] = 0    
        set a = a+1
    endloop
    set a = 1
// = = =  For teams of one  = = =
    if ( udg_PlayersPerTeam == 1 ) then
        loop
            exitwhen a > udg_NumOfTeams
            set tempPlayer = ForcePickRandomPlayer(tempTeam[a])
            call ForceRemovePlayer(tempTeam[a], tempPlayer)
            if ( udg_TeamCorner[a] == 1 ) then
                if ( positionTaken[1] < 1 ) then
                    call SetUnitOwner( udg_Barracks_Corner1[2], tempPlayer, true )
                    set positionTaken[1] = positionTaken[1] + 1
                else
                    call SetUnitOwner( udg_Barracks_Corner1[4], tempPlayer, true )
                endif
            endif
            if ( udg_TeamCorner[a] == 2 ) then
                if ( positionTaken[2] < 1 ) then
                    call SetUnitOwner( udg_Barracks_Corner2[2], tempPlayer, true )
                    set positionTaken[2] = positionTaken[2] + 1
                else
                    call SetUnitOwner( udg_Barracks_Corner2[4], tempPlayer, true )
                endif
            endif
            if ( udg_TeamCorner[a] == 3 ) then
                if ( positionTaken[3] < 1 ) then
                    call SetUnitOwner( udg_Barracks_Corner3[2], tempPlayer, true )
                    set positionTaken[3] = positionTaken[3] + 1
                else
                    call SetUnitOwner( udg_Barracks_Corner3[4], tempPlayer, true )
                endif
            endif
            if ( udg_TeamCorner[a] == 4 ) then
                if ( positionTaken[4] < 1 ) then
                    call SetUnitOwner( udg_Barracks_Corner4[2], tempPlayer, true )
                    set positionTaken[4] = positionTaken[4] + 1
                else
                    call SetUnitOwner( udg_Barracks_Corner4[4], tempPlayer, true )
                endif
            endif
// = = =  For teams of two  = = =
// = = =      NOT COMPLETE! = = =
// = = =  For teams of three= = =
// = = =      NOT COMPLETE! = = =
// = = =  For teams of four = = =
// = = =      NOT COMPLETE! = = =
// = = =  For teams of five = = =
// = = =      NOT COMPLETE! = = =
            set a = a+1
        endloop
    endif
endfunction
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
function SelectCorner_Algorithm takes nothing returns nothing
    local integer a
    local integer b
    local integer teamNum
    local integer playerNum
    local integer corner
    local integer array cornerPriority
    local integer array teamFirstPriority
    local integer array teamSecondPriority
    local integer array teamThirdPriority
    local integer array teamLastPriority
    local integer array cornerFull
    set playerNum = 1
    loop
        exitwhen playerNum > udg_NumOfPlayersPlaying
        set teamNum = 1
        loop
            exitwhen teamNum > udg_NumOfTeams
            if ( IsPlayerInForce(udg_Player[playerNum],udg_Team[teamNum]) ) then
                set corner = 1
                loop
                    exitwhen corner > 4
                    if ( udg_SelectCorner[playerNum] == corner ) then
                        set cornerPriority[(4*(teamNum-1)+corner)] = cornerPriority[(4*(teamNum-1)+corner)]+1 
                    endif
                    set corner = corner+1
                endloop
            endif
            set teamNum = teamNum+1
        endloop
        set playerNum = playerNum+1
    endloop
    set teamNum = 1
    loop
        exitwhen teamNum > udg_NumOfTeams
        set teamFirstPriority[teamNum] = FirstPriority(cornerPriority[(4*(teamNum-1)+(1))],cornerPriority[(4*(teamNum-1)+(2))],cornerPriority[(4*(teamNum-1)+(3))],cornerPriority[(4*(teamNum-1)+(4))] )
        set teamSecondPriority[teamNum] = SecondPriority(cornerPriority[(4*(teamNum-1)+(1))],cornerPriority[(4*(teamNum-1)+(2))],cornerPriority[(4*(teamNum-1)+(3))],cornerPriority[(4*(teamNum-1)+(4))] )
        set teamThirdPriority[teamNum] = ThirdPriority(cornerPriority[(4*(teamNum-1)+(1))],cornerPriority[(4*(teamNum-1)+(2))],cornerPriority[(4*(teamNum-1)+(3))],cornerPriority[(4*(teamNum-1)+(4))] )
        set teamLastPriority[teamNum] = LastPriority(cornerPriority[(4*(teamNum-1)+(1))],cornerPriority[(4*(teamNum-1)+(2))],cornerPriority[(4*(teamNum-1)+(3))],cornerPriority[(4*(teamNum-1)+(4))] )    
        set teamNum = teamNum+1
    endloop
    if ( udg_PlayersPerTeam == 1 or udg_PlayersPerTeam == 2 ) then
        set b = -1
    else
        set b = 0
    endif
    loop
        exitwhen a > 4
        set cornerFull[a] = b
        set a = a+1
    endloop            
    set teamNum = 1
    loop
        exitwhen teamNum > udg_NumOfTeams
        if ( cornerFull[teamFirstPriority[teamNum]] < 1 ) then
            set udg_TeamCorner[teamNum] = teamFirstPriority[teamNum]
            set cornerFull[teamFirstPriority[teamNum]] = cornerFull[teamFirstPriority[teamNum]]+1
        else
            if ( cornerFull[teamSecondPriority[teamNum]] < 1 ) then
                set udg_TeamCorner[teamNum] = teamSecondPriority[teamNum]
                set cornerFull[teamSecondPriority[teamNum]] = cornerFull[teamSecondPriority[teamNum]]+1
            else
                if ( cornerFull[teamThirdPriority[teamNum]] < 1 ) then
                    set udg_TeamCorner[teamNum] = teamThirdPriority[teamNum]
                    set cornerFull[teamThirdPriority[teamNum]] = cornerFull[teamThirdPriority[teamNum]]+1
                else
                    set udg_TeamCorner[teamNum] = teamLastPriority[teamNum]
                    set cornerFull[teamLastPriority[teamNum]] = cornerFull[teamLastPriority[teamNum]]+1
                endif
            endif
        endif
        set teamNum = teamNum+1
    endloop
    call AssignLocation()
endfunction
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
function SelectCorner_IsClicked takes nothing returns nothing
    local integer a
    local integer playerX
    local boolean allPlayersClicked
    set a = 1
    loop
        exitwhen a > udg_NumOfPlayersPlaying
        if ( udg_Player[a] == GetTriggerPlayer() ) then
            set udg_Clicked_SelectCorner[a] = true
            set playerX = a
        endif
        set a = a+1
    endloop
    set a = 1
    set allPlayersClicked = true
    loop
        exitwhen a > udg_NumOfPlayersPlaying
        if ( udg_Clicked_SelectCorner[a] == false ) then
            set allPlayersClicked = false
        endif
        set a = a+1
    endloop
    set a = 0
    loop
        exitwhen a > 4
        if ( GetClickedButton() == udg_Buttons_SelectCorner[a] ) then
            set udg_SelectCorner[playerX] = a
        endif
        set a = a+1
    endloop
    if ( allPlayersClicked ) then
        set udg_Clicked_SelectCorner[0] = true
        call SelectCorner_Algorithm()
    endif
endfunction
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
function DisplaySelectCornerDialog takes nothing returns nothing
    local integer a
    call DialogSetMessage( udg_Dialog_SelectCorner, "Preferred Corner" )
    set a = 1
    loop
        exitwhen a > udg_NumOfPlayersPlaying
        set udg_Clicked_SelectCorner[a] = false
        call DialogDisplay( udg_Player[a], udg_Dialog_SelectCorner, true )
        set a = a+1
    endloop
    call TriggerSleepAction( 20.00 )
    if ( udg_Clicked_SelectCorner[0] == false ) then
        set a = 1
        loop
            exitwhen a > udg_NumOfPlayersPlaying
            if ( udg_Clicked_SelectCorner[a] == false ) then
                call DialogDisplay( udg_Player[a], udg_Dialog_SelectCorner, false )
                set udg_SelectCorner[a] = 0
            endif
            set a = a+1
        endloop
        set udg_Clicked_SelectCorner[0] = true
    endif
    call SelectCorner_Algorithm()
endfunction
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
function PlayersPerTeam_Algorithm takes nothing returns nothing
    local integer a
    local integer b
    local integer x
    set udg_Clicked_PlayersPerTeam = true
    set a = 1
    loop
        exitwhen a > 5
        if ( GetClickedButton() == udg_Buttons_PlayersPerTeam[a] ) then
            set udg_PlayersPerTeam = a
        endif
        set a = a+1
    endloop
    set a = 1
    set b = 1
    set x = 0
    loop
        exitwhen a > udg_NumOfPlayersPlaying
        if (x < udg_PlayersPerTeam) then
            call ForceAddPlayer(udg_Team[b], udg_Player[a])
            set x = x+1
        else
            call ForceAddPlayer(udg_Team[(b+1)], udg_Player[a])
            set b = b+1
            set x = 1
        endif
        set a = a+1
    endloop
    set udg_NumOfTeams = b
    set a = 1
    loop
        exitwhen a > udg_NumOfPlayersPlaying
        set b = 1
        loop
            exitwhen b > udg_NumOfTeams
            if (IsPlayerInForce( udg_Player[a], udg_Team[b] )) then
                set x = 1
                loop
                    exitwhen x > udg_NumOfPlayersPlaying
                    if (x != a) then
                        if (IsPlayerInForce( udg_Player[x], udg_Team[b] )) then
                            call SetPlayerAllianceStateBJ( udg_Player[a], udg_Player[x], bj_ALLIANCE_ALLIED_VISION )
                            call SetPlayerAllianceStateBJ( udg_Player[x], udg_Player[a], bj_ALLIANCE_ALLIED_VISION )
                        endif
                    endif
                    set x = x+1
                endloop
            endif
            set b = b+1
        endloop
        set a = a+1
    endloop
call DisplaySelectCornerDialog()
endfunction
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
function DisplayPlayersPerTeamDialog takes player PlayerX returns nothing
    call DialogSetMessage( udg_Dialog_PlayersPerTeam, "Team Setup" )
    set udg_Clicked_PlayersPerTeam = false
    call DialogDisplay( PlayerX, udg_Dialog_PlayersPerTeam, true )
    call TriggerSleepAction( 20.00 )
    if ( udg_Clicked_PlayersPerTeam == false ) then
        call DialogDisplay( PlayerX, udg_Dialog_PlayersPerTeam, false )
        if ( udg_NumOfPlayersPlaying > 4 ) then
            set udg_PlayersPerTeam = 3
        else
            set udg_PlayersPerTeam = 1
        endif
        call PlayersPerTeam_Algorithm()
    endif
endfunction
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
function PlayerIsPlaying takes player PlayerX returns boolean
    return GetPlayerController(PlayerX) == MAP_CONTROL_USER and GetPlayerSlotState(PlayerX) == PLAYER_SLOT_STATE_PLAYING
endfunction
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
function GameSetup takes nothing returns nothing
    local integer a = 1
    local integer b = 1
    loop
        exitwhen a > 12
        if ( PlayerIsPlaying(ConvertedPlayer(a)) ) then
            call ForceAddPlayer( udg_PlayersPlaying, GetEnumPlayer() )
            set udg_Player[b] = ConvertedPlayer(a)
            set b = b+1
        endif
        set a = a+1
    endloop
    set udg_NumOfPlayersPlaying = b
    call Set_Buttons()
    call Set_Regions()
    call Set_Barracks()
    call DisplayPlayersPerTeamDialog(udg_Player[1])
endfunction
// ===========================================================================
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// = = =                  End of Game Setup Function                     = = =
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
// ===========================================================================

-darkz
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
Parental advisory: Non-helpfull post ahaid

> I really don't have the time to debug it, I'm actually moving out

I'd move too had I written that code... :p

> I was hoping someone could read through this for obvious bugs

10 pages code is rarely any "obvious".

Though, with any luck, phyrex might have nothing else to do...
 
D

dArKzEr0

Guest
>> I really don't have the time to debug it, I'm actually moving out
>I'd move too had I written that code... :p
Hah, ya, I've written it in pieces since he first posted his problem.

>> I was hoping someone could read through this for obvious bugs
>10 pages code is rarely any "obvious".
>Though, with any luck, phyrex might have nothing else to do...
I figured it would have to be someone like you, vex, or phyrex to read through it. I was hopeful when I saw (1 Viewing) next to the JASS forum and saw it was you :p


*Note that SetRegions() has no use yet in any of the written code, I was planning on using it later to grant ownership of the towers around each barracks on MrApples map and also to destroy unused barracks. Though I haven't really thought about how yet.*
I just want to get the posted code to work properly before continuing.
 

phyrex1an

Staff Member and irregular helper
Reaction score
447
>phyrex might have nothing else to do
:p

>Set_Buttons()
This needs some recoding if you always want even teams (IE no 3v3v1), else it looks fine

>FirstPriority() and co
I like second and third priority, pretty nice.
I think FirstPriority may fail, if it does you can use this.
Code:
function FirstPriority takes integer int1, integer int2, integer int3, integer int4 returns integer
    local integer loopX = 4
    local integer array corner
    local integer priority = 0  
    local integer max = -20	
    set corner[1] = int1
    set corner[2] = int2
    set corner[3] = int3
    set corner[4] = int4	
    set loopX = 4
    loop
        exitwhen loopX < 1
        if ( corner[loopX] > max ) then
            set priority = loopX
			set max = corner[loopX]
        endif
        set loopX = loopX-1
    endloop    
    return priority    
endfunction
You can do the same thing to LastPriority() as to FirstPriority(). Just init max with a huge value and change the > to <

>AssignLocation() and SelectCorner_Algorithm()
I do not have this much time ^^

>Dialog functions and co
You are calling both the Algorithm() functions way to often, they should only be called when all players voted or the time is up.

>GameSetup()
:) first error.
GetEnumPlayer() should be ConvertedPlayer(a)

To find the rest (if any) of the problems you may need a test map to spot them first ^^
 

emjlr3

Change can be a good thing
Reaction score
395
think ill let phyrex and u handle this

i dispise(sp) reading through pages of others messed up coding
 

MrApples

Ultra Cool Member
Reaction score
78
Would one of you people with more rep +rep DarkZer0 on my sake for still working on this :D .

I did rewrite it, using a simpler/much shorter method, which also doesn't happen to work in this thread.
 
D

dArKzEr0

Guest
>>Set_Buttons()
>This needs some recoding if you always want even teams (IE no 3v3v1),
>else it looks fine
I saw the flaw with this but it was how MrApples originally had it, so I assumed he was cool with having uneven teams.

>>FirstPriority() and co
>I like second and third priority, pretty nice.
>I think FirstPriority may fail, if it does you can use this.
>CODE.../CODE
Excellent! I had tested FirstPriority and it worked fine in my tests but this is much better coding. I knew there had to be a more efficient way but I didn't want to waste time thinking about it. Thanks!

>>AssignLocation() and SelectCorner_Algorithm()
>I do not have this much time ^^
I'm pretty sure that's where the problem lies too :(

>>Dialog functions and co
>You are calling both the Algorithm() functions way to often, they should only be
>called when all players voted or the time is up.
What do you mean? I thought that's how I had it.
DisplayPlayersPerTeamDialog waits 20 seconds after displaying and checks if it's been clicked, if it hasn't been then the default will be chosen. The trigger PlayersPerTeam_IsClicked will only run once because only udg_Player(1) is displayed the dialog. I added:
if ( udg_Clicked_PlayersPerTeam == false ) then
---whichdialogwasclicked?
endif
so it won't run that section if the 20 seconds run out.
Also, DisplaySelectCornerDialog will only call SelectCorner_Algorithm after 20 seconds and I'm pretty sure SelectCorner_IsClicked checks to make sure everyone has chosen before running the algorithm. Please correct me if I'm wrong.

>>GameSetup()
>:) first error.
>GetEnumPlayer() should be ConvertedPlayer(a)
Great job, thanks.

Slightly off-topic question:
When I compile the map, if I had closed it since my last successful compile I always get the script error "Expected a name" for every line in Set_Barracks. Then if I create a new trigger in GUI assigning each barracks to the same variable it's supposed to be with, the script will compile fine (even if I delete the new trigger). Why does this happen?

-darkz

Edit://
I've got some free time right now so I'm going to try debugging. I'm going to log the changes I make here.

GameSetup
set udg_NumOfPlayersPlaying = b
changed to
set udg_NumOfPlayersPlaying = b-1
 

MrApples

Ultra Cool Member
Reaction score
78
Did any of you take a look at my new setup, its alot simpler and shorter(Depends on how you look at it, theres no corner vote, but the team customizability is alot better). Still bugged but I think it may be a easy thing I just happened to pass up in the hours I checked it.

This is so confusing...
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top