dofile("../Resources/player.lua") -- Player Extension dofile("../Resources/team.lua") -- Team Extension g_NEW_TABLE = { } --Stats/Points-------------------------------------------------------------------------- g_Confederate = 0 g_KelMorian = 0 g_Stats = { } -- Global setup --------------------------------------------------------------- g_GameRunning = false g_NextGameInProgress = false g_NumPlaying = 0 -- Number of people currently playing the game g_arena = nil g_Fround = true -- Primary game configuration -------------------------------------------------- g_NeededForGame = 1 -- Amount of people needed before a game can start g_DesertedEndGame = true -- Should a game end if theres no longer enough players? g_NewGameDelay = 15 -- Delay in seconds between each game function Arena_OnCreate(arena) -- Set our global value g_arena = arena -- Initialize random math.randomseed(os.time()) end function Player_OnVehicleChange(Player, FromVehicle, ToVehicle, Action) -- Player has specced if Action == 1 then -- We will keep track of our own number of playing g_NumPlaying = g_NumPlaying - 1 if g_NumPlaying < g_NeededForGame and g_DesertedEndGame then g_GameRunning = false if g_NextGameInProgress then g_NextGameInProgress = false destroyEvent(g_StartEvent) destroyEvent(g_WarningEvent) end g_arena:message("Game aborted. Not enough players to continue.") end -- Player has unspecced elseif Action == 2 then -- We will keep track of our own number of playing g_NumPlaying = g_NumPlaying + 1 if ((g_NumPlaying >= g_NeededForGame) and (g_GameRunning == false) and (g_NextGameInProgress == false)) then PregamePreparation() end end return true end function PregamePreparation() g_GameRunning = false g_NextGameInProgress = true g_arena:message("Next game will begin in " .. SecondsInWords(g_NewGameDelay, 2) .. ".") g_arena:message("~Press (F12) if you would like to participate!") -- Start countdown ticker g_arena:setTicker(0, "Next game in ", (g_NewGameDelay * 100)) -- Setup our delayed start g_StartEvent = createEvent(StartGame, (g_NewGameDelay * 1000), g_arena) -- Setup our 20 second warning if g_NewGameDelay > 40 then g_WarningEvent = createEvent(StartNotice, ((g_NewGameDelay - 20) * 1000), g_arena) return false end end function StartGame() g_NextGameInProgress = false g_GameRunning = true g_PlayingOnStart = NumPlaying g_StartTime = os.time() for x = 1, g_arena:numPlaying() do local player = g_arena:getPlayer(x) g_Stats[player.name] = {} g_Stats[player.name]["Kills"] = 0 g_Stats[player.name]["Deaths"] = 0 end -- g_arena cleanup, reset spawns, hides, etc SetupGame() g_Fround = false -- It has begun! g_arena:message("Game started.") return false end function EndGame(WinningTeam) g_GameRunning = false g_NextGameInProgress = false local RunningTime = os.time() - g_StartTime g_arena:message("After " .. SecondsInWords(RunningTime, 2) .. " the game has come to an end.") g_arena:message("&!Ending Points!") g_arena:message("Confederate: " .. g_Confederate .. "") g_arena:message("Kel-Morian: " .. g_KelMorian .. "") local bestKiller = "" local bestVictim = "" local mostKills = 0 local mostDeaths = 0 g_arena:message("&!Individual Stats!") for x = 1, g_arena:numPlaying() do --This gets the person with most kills local player = g_arena:getPlayer(x) if (g_Stats[player.name]["Kills"] > mostKills) then mostKills = g_Stats[player.name]["Kills"] bestKiller = player.name elseif (g_Stats[player.name]["Kills"] == mostKills) then bestKiller = ("" .. bestKiller .. ", " .. player.name .. "") end if (g_Stats[player.name]["Deaths"] > mostDeaths) then mostDeaths = g_Stats[player.name]["Deaths"] bestVictim = player.name elseif (g_Stats[player.name]["Deaths"] == mostDeaths) then bestVictim = ("" .. bestVictim .. ", " .. player.name .. "") end end ------------------------------------------------------------------------ -- PLAYER STATISTICS -- for x = 1, g_arena:numPlaying() do --This gets the person with most kills local player = g_arena:getPlayer(x) if (mostKills == 0) then player:message("!_ No one got any kills!") else player:message("!_ Most Kills: " .. bestKiller .. "(" .. mostKills .. ")") end if (mostDeaths == 0) then player:message("!_ No one got any deaths!") else player:message("!_ Most Deaths: " .. bestVictim .. "(" .. mostDeaths .. ")") end if ((g_NumPlaying >= g_NeededForGame) and (g_GameRunning == false) and (g_NextGameInProgress == false)) then PregamePreparation() end return true end end function SecondsInWords(Seconds, Quanity) local ReturnString = nil local Time = g_NEW_TABLE Time["day"] = math.floor(Seconds / 86400) Seconds = Seconds % 86400 Time["hour"] = math.floor(Seconds / 3600) Seconds = Seconds % 3600 Time["minute"] = math.floor(Seconds / 60) Time["second"] = Seconds % 60 local Found = 0 for Index, Value in pairs(Time) do if Found >= Quanity then break elseif Value ~= 0 then -- minute becomes minutes, second becomes seconds, etc. if Value > 1 then Index = Index .. "s" end if ReturnString == nil then ReturnString = string.format("%d %s", Value, Index) else ReturnString = string.format("%s, %d %s", ReturnString, Value, Index) end Found = Found + 1 end end return ReturnString end function Player_OnDeath(Killer, Victim) local freq = Killer:frequency() --Add points to killer's team. if (freq == 0) then addPoints("Confederate") elseif (freq == 1) then addPoints("KelMorian") end --Set stats for killer and victim. if Killer:exists() then Killer:increaseKills() end Victim:increaseDeaths() end function Vehicle_OnDeath(victim, killer, itemID) local vid = victim:typeid() local c = victim:getCoords() local freq = victim:frequency() --CC death? if (vid == 401) then if (freq == 0) then EndGame("Kel-Morian") elseif (freq == 1) then EndGame("Confederate") end --Spawn Factories upon Bunker Death elseif (vid == 418) or (vid == 403) then local factory = g_arena:createVehicle(400, c.x, c.y, 0) factory:setFrequency(-1) end end function Player_OnJoin(player) player:message("Welcome to Zone Control, " .. player.name .. "") player:reset() end function StartNotice() g_arena:message("Game starting in 20 seconds.") return false end function SetupGame() if (g_Fround == true) then --Spawn the initial command centers and bunkers. CCA = g_arena:createVehicle(401, 480, 432, 0) CCB = g_arena:createVehicle(401, 2744, 2400, 0) CCA:setFrequency(0) CCB:setFrequency(1) bA = g_arena:createVehicle(418, 658, 565, 0) bB = g_arena:createVehicle(418, 2562, 2253, 0) bA:setFrequency(0) bB:setFrequency(1) else -- the very first round has already been played (this means destroy the old bunkers and crap) CCA:destroy() CCB:destroy() bA:destroy() bB:destroy() CCA = g_arena:createVehicle(401, 480, 432, 0) CCB = g_arena:createVehicle(401, 2744, 2400, 0) CCA:setFrequency(0) CCB:setFrequency(1) bA = g_arena:createVehicle(418, 658, 565, 0) bB = g_arena:createVehicle(418, 2562, 2253, 0) bA:setFrequency(0) bB:setFrequency(1) end ---Warp The Players for x = 1, g_arena:numPlaying() do local plyr = g_arena:getPlayer(x) plyr:setVehicle(100) if (plyr:frequency() == 0) then plyr:warp(658, 565, 0) elseif (plyr:frequency() == 1) then plyr:warp(2562, 2253, 0) return false end end end