-- Stat Settings-- 0 - Kills-- 1 - Deaths-- 2 - Points--- [[ Global Variables ]] ----------g_arena = nil -- The global arena class, to avoid having to pass it around functionsg_bGameRunning = false -- Is the game running?g_redTeamPoints = 0 -- Red Team Pointsg_blueTeamPoints = 0 -- Blue Team Pointsg_winningTeam = "" -- Holds the winning team--- [[ Functions ]] -------function Arena_OnCreate(arena) g_arena = arena local cfg = GameSettings() cfg.minplayers = 2 cfg.gamedelay = 30 cfg.str_pregame = "Game starting in " cfg.str_noplayers = "Not Enough Players" cfg.bDesertedGameEnd = false cfg.bIngameTicker = true cfg.tckrUpdateSpacing = 1000 g_state = g_arena:Takeover_State(cfg) math.randomseed(os.time())endfunction CheckForVictory() if (g_redTeamPoints >= 25) then g_winningTeam = "Red Team" g_arena:message("!Red Team Wins!") g_state:Endgame() elseif (g_blueTeamPoints >= 25) then g_winningTeam = "Blue Team" g_arena:message("%Blue Team Wins!") g_state:Endgame() end return falseendfunction Player_OnDeath(killer, victim) if (g_bGameRunning == true) then -- If the game is running, we want to reward the killer local teamName = killer:getTeam().m_name if (teamName == "Red Team") then g_redTeamPoints = (g_redTeamPoints + 1) elseif (teamName == "Blue Team") then g_blueTeamPoints = (g_blueTeamPoints + 1) end CheckForVictory() endendfunction Vehicle_OnDeath(victim, killer, itemid) if (g_bGameRunning == true) then -- If the game is running, we want to reward the killer local vid = victim:vehicletypeid() if (vid == 400) then g_redTeamPoints = (g_redTeamPoints + 10) elseif (vid == 401) then g_blueTeamPoints = (g_blueTeamPoints + 10) end CheckForVictory() endendfunction Player_OnJoin(player) player:message("Welcome to Laser Tag, " .. player.m_name .."! Join the game by pressing F12")end-- when the game starts, it sets gameRunning to truefunction Arena_OnGameStart()g_arena:message("Game has started!") g_bGameRunning = true -- Let's change all of the players back to the normal vehicle if needed for x = 1, g_arena:num() do player = g_arena:get(x) if (player:getVehicle():vehicletypeid() == 104) then if (player:getTeam().m_name == "Blue Team") then player:setVehicle(100) elseif (player:getTeam().m_name == "Red Team") then player:setVehicle(101) else player:message("Don't abuse") player:spec() end end endendfunction Arena_OnGameEnd() g_bGameRunning = false g_redTeamPoints = 0 g_blueTeamPoints = 0 -- Let's go through all the players on the winning team and change them to the 'Celeb' vehicle (104) for x = 1, g_arena:num() do player = g_arena:get(x) if (player:getTeam().m_name == g_winningTeam) then player:setVehicle(104) end end -- Now let's scramble them -- Loop through all the players and randomly change their team for x = 1, g_arena:num() do local player = g_arena:get(x) -- Don't change the team of specced players if (player:spectator() == false) then local rand = math.random(0, 50) if (rand >= 25) then player:team_change("Blue Team", "") -- Blue Team elseif (rand < 25) then player:team_change("Red Team", "") -- Red Team end end end -- Balance teams if needed g_arena:message("Teams have been scrambled") local blueTeam = g_arena:getteam(1) local redTeam = g_arena:getteam(2) local numBlue = blueTeam:numplaying() local numRed = redTeam:numplaying() local difference = numRed - numBlue if (difference > 1) then while (difference > 1) do local redplayer = redTeam:getplayer(math.random(1, numRed)) redplayer:team_change("Blue Team", "") numRed = numRed - 1 numBlue = numBlue + 1 difference = numRed - numBlue end elseif (difference < -1) then while (difference < -1) do local blueplayer = blueTeam:getplayer(math.random(1, numBlue)) blueplayer:team_change("Red Team", "") numRed = numRed + 1 numBlue = numBlue - 1 difference = numRed - numBlue end endend--function IncreaseKill(killer)-- killer:setstat(0,(killer:getstat(0) + 1)) -- Increase the killer's kills--end--function IncreaseDeath(victim)-- victim:setstat(1,(victim:getstat(1) + 1)) -- Increase the victim's deaths--endfunction Arena_TickerUpdate() g_state:SetNotice(0, "Blue Team: " .. g_blueTeamPoints .. " - Red Team: " .. g_redTeamPoints .. "")end