scope Mode
globals
dialog mode_window = DialogCreate()
button no_meteorites
button normal
button hard
button nightmare
button hell
button test
private integer players = 0
private integer players_total = 0
private integer array votes
private timer t = CreateTimer()
endglobals
function ModeMsg takes integer i returns nothing
if i == 0 then
call EnableTrigger( gg_trg_test_commands )
call DisplayTextToForce( GetPlayersAll(), "Test mode enabled! You can use commands like: \"-time\"; \"-time ##\"; \"-mode #\"; \"-arena\"; \"-kill\"; \"-gtt\"; \"-rush\"; \"-itemo order (#)\"; \"-build\"; \"-upgrade all\"; \"-gold ##\"; \"-lumber ##\"" )
loop
exitwhen i > 11
call SetPlayerState( Player(i), PLAYER_STATE_RESOURCE_LUMBER, 3500 )
call SetPlayerState( Player(i), PLAYER_STATE_RESOURCE_GOLD, 5000 )
set i = i + 1
endloop
return
elseif i == 1 then
call DisplayTextToForce( GetPlayersAll(), "TRIGSTR_463" )
elseif i == 2 then
call DisplayTextToForce( GetPlayersAll(), "Normal Mode - Normal amount of meteorites." )
elseif i == 3 then
call DisplayTextToForce( GetPlayersAll(), "TRIGSTR_464" )
elseif i == 4 then
call DisplayTextToForce( GetPlayersAll(), "TRIGSTR_465" )
elseif i == 5 then
call DisplayTextToForce( GetPlayersAll(), "TRIGSTR_466" )
endif
call SetConcLvl()
endfunction
private function ShowMsg takes nothing returns nothing
local timer t = GetExpiredTimer()
if players > 0 then
call DisplayTextToForce(GetPlayersAll(), I2S(players))
set players = players - 1
else
call DisplayTextToForce(GetPlayersAll(), "BEGIN!")
call RecTimer(t)
call PauseAllUnits(false)
endif
set t = null
endfunction
function GameWillStartIn takes nothing returns nothing
local timer t = GetFreeTimer()
set players = 2
call DisplayTextToForce(GetPlayersAll(), "Game will start in:")
call DisplayTextToForce(GetPlayersAll(), "3")
call TimerStart(t, 1.00, true, function ShowMsg)
set t = null
endfunction
function OnButtonClick takes nothing returns boolean
local button b = GetClickedButton()
local integer i
local integer temp
if b == no_meteorites then
set votes[1] = votes[1] + 1
elseif b == normal then
set votes[2] = votes[2] + 1
elseif b == hard then
set votes[3] = votes[3] + 1
elseif b == nightmare then
set votes[4] = votes[4] + 1
elseif b == hell then
set votes[5] = votes[5] + 1
else
set votes[2] = votes[2] + 1
set votes[0] = votes[0] + 1
endif
set players = players - 1
if players == 0 then
if votes[0] > players_total/2 then
call ModeMsg(0)
endif
set i = 1
set temp = 0
loop
exitwhen i > 5
if votes[i] > temp then
set temp = votes[i]
set udg_mode = i
endif
set i = i + 1
endloop
call ModeMsg(udg_mode)
call GameWillStartIn()
call RecTimer(t)
call DialogDestroy(mode_window)
set mode_window = null
set t = null
endif
return false
endfunction
private function OnExpire takes nothing returns nothing
local integer i = 0
local integer temp
call RecTimer(GetExpiredTimer())
set t = null
loop
exitwhen i > 11
call DialogDisplay(Player(i), mode_window, false)
set i = i + 1
endloop
call DialogDestroy(mode_window)
set votes[2] = votes[2] + players
if votes[0] > players_total/2 then
call ModeMsg(0)
endif
set i = 1
set temp = 0
loop
exitwhen i > 5
if votes[i] > temp then
set temp = votes[i]
set udg_mode = i
endif
set i = i + 1
endloop
call ModeMsg(udg_mode)
call GameWillStartIn()
endfunction
function Trig_Dialog_Actions takes nothing returns boolean
local integer i = 0
local trigger tr = CreateTrigger()
call TimerStart(t, 20.00, false, function OnExpire)
call DisplayTextToForce(GetPlayersAll(), "You have 20 seconds to choose mode")
call DialogSetMessage( mode_window, "Choose mode:" )
set no_meteorites = DialogAddButton( mode_window, "No Meteorites", 1 )
set normal = DialogAddButton( mode_window, "Normal", 2 )
set hard = DialogAddButton( mode_window, "Hard", 3 )
set nightmare = DialogAddButton( mode_window, "Nightmare", 4 )
set hell = DialogAddButton( mode_window, "Hell", 5 )
set test = DialogAddButton( mode_window, "Test", 0 )
loop
exitwhen i > 11
if GetPlayerController(Player(i)) == MAP_CONTROL_USER and GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING then
set players = players + 1
set players_total = players_total + 1
call DialogDisplay( Player(i), mode_window, true )
endif
set i = i + 1
endloop
call TriggerRegisterDialogEventBJ( tr, mode_window )
call TriggerAddCondition( tr, Condition( function OnButtonClick ) )
set tr = null
call PauseAllUnits(true)
return false
endfunction
//===========================================================================
function InitTrig_Mode takes nothing returns nothing
set gg_trg_Mode = CreateTrigger( )
call TriggerRegisterTimerEventSingle( gg_trg_Mode, 0.00 )
call TriggerAddCondition( gg_trg_Mode, Condition(function Trig_Dialog_Actions) )
set votes[0] = 0
set votes[1] = 0
set votes[2] = 0
set votes[3] = 0
set votes[4] = 0
set votes[5] = 0
endfunction
endscope