gc_timeTillStart = 10
g_arena = nil --Arena Object
g_arenaCreated = false
g_gameRunning = false
g_arenaTicker = {}
g_arenaTicker[1] = "Too few players for game to start"
g_arenaTicker[2] = ""
g_gameStartTime = nil
g_timeTillStart = gc_timeTillStart
g_gameEvent = nil
g_bombVehicle = nil
g_BombActive = false
g_15seconds = nil
g_5seconds = nil
g_4seconds = nil
g_3seconds = nil
g_2seconds = nil
g_1seconds = nil
g_0seconds = nil
g_currentRound = "None"
g_firstRoundWinners = "None"
g_secondRoundWinners = "None"
g_thirdRoundWinners = "None"
g_firstRoundStartTime = nil
g_secondRoundStartTime = nil
g_thirdRoundStartTime = nil
function Arena_OnCreate(arena)
g_arena = arena
math.randomseed(os.time())
end
function Player_OnJoin(player)
player:message("!Welcome To The Total Domination Zone, " .. player.m_name)
player:setTicker(0,g_arenaTicker[1])
player:setTicker(1,g_arenaTicker[2])
if (g_arenaCreated == false) then -- start an event to check if the game can begin
g_arenaCreated = true
event_create(CanGameStart, -1000, g_arena)
end
end
function Player_OnWarpItem(user, itemid, target)
if (itemid == 333) then -- User is making a bomb
if (g_BombActive == true) then
user:message("Bomb has already been planted.")
else
g_BombActive = true
local c = user:coords()
g_bombVehicle = g_arena:vehicle_create(50, c.x, c.y, 0)
g_bombVehicle:setFrequency(user:getFrequency())
g_arena:message("Bomb has been planted.")
g_arena:message("30 seconds until explosion.")
g_15seconds = event_create( Bomb15Seconds, 15000, g_arena )
end
end
return true
end
function CanGameStart()
if (EnoughPlayers() == true) then
g_timeTillStart = gc_timeTillStart
event_create(GameCountdown, -1000, g_arena)
return true
else
return false
end
end
function EnoughPlayers()
if (g_arena:numPlaying() > 0) then
return true
else
return false
end
end
function GameCountdown()
if (EnoughPlayers() == true) then
if (g_timeTillStart > 0) then
SetArenaTicker("Game starting in " .. g_timeTillStart .. " seconds")
g_timeTillStart = g_timeTillStart - 1
return false
else
SetArenaTicker("Game starting in 0 seconds")
StartGame()
return true
end
else
AbortGame("Too few players")
return true
end
end
function StartGame()
g_arena:message("Game started")
g_gameRunning = true
g_gameStartTime = os.time()
g_gameEvent = event_create(GameEvent, -1000, g_arena)
end
function AbortGame(reason)
SetArenaTicker("Too few players for game to start")
g_arena:message("Game aborted: " .. reason)
g_gameRunning = false
g_currentRound = "None"
g_firstRoundWinners = "None"
g_secondRoundWinners = "None"
g_thirdRoundWinners = "None"
g_firstRoundStartTime = nil
g_secondRoundStartTime = nil
g_thirdRoundStartTime = nil
event_create(CanGameStart, -1000, g_arena)
end
function GameEvent() -- Runs every second once the game's started
if (EnoughPlayers() == true) then
TickerTimer()
if (g_currentRound == "None") then
--No round running
g_arena:message("First Round Starting")
g_currentRound = "First"
--Wipe them
elseif (g_currentRound == "First") then
--First round is running
if (g_firstRoundStartTime == nil) then
g_firstRoundStartTime = os.time()
-- Cash them
-- Warp them
-- Give bomb to one
end
local difference = os.time - g_firstRoundStartTime
RoundTimer("First", difference)
if (difference >= 900) then
g_currentRound = "Second"
g_arena:message("First round was one by the Counter-Terrorists by default")
g_firstRoundWinners = "Counter-Terrorist"
end
return false
else
AbortGame("Too few players")
return true
end
end
function TickerTimer()
local timer = os.time() - g_gameStartTime
if (timer >= 3600) then
AbortGame("Game took over an hour")
else
local minutes = math.floor(timer/60)
local seconds = math.floor(math.mod(timer,60))
if (minutes < 10) then
minutes = "0" .. minutes
end
if (seconds < 10) then
seconds = "0" .. seconds
end
SetArenaTicker(0, "Game time " .. minutes .. ":" .. seconds)
end
end
function RoundTimer(round, timer)
local minutes = math.floor(timer/60)
local seconds = math.floor(math.mod(timer,60))
if (minutes < 10) then
minutes = "0" .. minutes
end
if (seconds < 10) then
seconds = "0" .. seconds
end
SetArenaTicker(1, "Round " .. round .. " time " .. minutes .. ":" .. seconds)
end
function SetArenaTicker(idx, message)
g_arenaTicker[idx+1] = message
local num = 0
num = g_arena:numPlayers()
if (num ~= 0) then
for i = 1, num do
local player = g_arena:getPlayer(i)
player:setTicker(idx, message)
end
end
end
function Bomb15Seconds()
g_arena:message("15 seconds until explosion.")
g_5seconds = event_create( Bomb5Seconds, 10000, g_arena )
end
function Bomb5Seconds()
g_arena:message("5 seconds until explosion.")
g_4seconds = event_create( Bomb4Seconds, 1000, g_arena )
end
function Bomb4Seconds()
g_arena:message("4 seconds until explosion.")
g_3seconds = event_create( Bomb3Seconds, 1000, g_arena )
end
function Bomb3Seconds()
g_arena:message("3 seconds until explosion.")
g_2seconds = event_create( Bomb2Seconds, 1000, g_arena )
end
function Bomb2Seconds()
g_arena:message("2 seconds until explosion.")
g_1seconds = event_create( Bomb1Seconds, 1000, g_arena )
end
function Bomb1Seconds()
g_arena:message("1 seconds until explosion.")
g_0seconds = event_create( Bomb0Seconds, 1000, g_arena )
end
function Bomb0Seconds()
--Bomb blows up now
g_arena:message("BOOOOOOOOOOOM!")
if (g_currentRound == "First") then
g_firstRoundWinners = "Terrorist"
FinishFirstRound()
elseif (g_currentRound == "Second") then
g_secondRoundWinners = "Terrorist"
FinishSecondRound()
elseif (g_currentRound == "Second") then
g_thirdRoundWinners = "Terrorist"
FinishThirdRound()
end
end
end