--- [[ Global Variables ]] ----------
g_arena = nil -- The global arena class, to avoid having to pass it around functions
g_state = nil
g_bGameRunning = false -- Is the game running?
g_titan = nil
g_collie = nil
--- [[ Functions ]] -------
function Arena_OnCreate(arena)
-- Set our global value
g_arena = arena
-- Initialize random
math.randomseed(os.time())
-- Use our own game dynamic
--local cfg = GameSettings()
--cfg.minplayers = 2
--cfg.gamedelay = 15
--
-- cfg.str_pregame = "Game starting in "
-- cfg.str_noplayers = "Not Enough Players"
--
-- cfg.bDesertedGameEnd = false
--
-- cfg.bIngameTicker = true
-- cfg.tckrUpdateSpacing = 10000
--
-- g_state = g_arena:Takeover_State(cfg)
end
-- Code in this function is carried out when the player joins
function Player_OnJoin(player)
player:message("Welcome to Traffic Control, Lua is running.")
end
function Player_OnDeath(killer, victim) -- player, player
end
function Player_OnUnspec(plyr)
event_create(gameRunning, 100, g_arena)
end
-- when the game starts, it sets gameRunning to true
function Arena_OnGameStart()
end
-- when the game finishes, it sets gameRunning to false
function Arena_OnGameEnd()
g_bGameRunning = false
end
function CollieWin()
g_arena:message("Collective has destroyed Titan's tank factory. Game Over")
end
function TitanWin()
g_arena:message("Titan has destroyed Collective's tank factory. Game Over")
end
function gameRunning()
local good = true
local loser = ""
g_bGameRunning = true
local collie = g_arena:vehicle_create(402, 319, 4705, 0)
local titan = g_arena:vehicle_create(400, 4543, 390, 0)
titan:setfrequency(0)
collie:setfrequency(1)
for i=1, g_arena:numPlaying() do
local player = g_arena:getPlayer(i)
if (player ~= nil) and (player:valid()) then
if (player:getFrequency() == 0) then
player:warp(4543, 390, 100)
elseif (player:getFrequency() == 1) then
player:warp(319, 4705, 100)
end
end
end
do while (good ~= false) then
if (collie:getHealth() ~= 0 or collie:getHealth() ~= nil) then
good = false
loser = "Collective Military"
titan:destroy()
end
if (titan:getHealth() ~= 0 or titan:getHealth() ~= nil) then
good = false
loser = "Titan Militia"
collie:destroy()
end
end
g_arena:message("" .. loser .. " has lost their factory! 20 seconds till next game!")
event_create(gameEnded, 2000, g_arena)
end
function gameEnded()
event_create(gameRunning, 100, g_arena)
end