All pastes #962665 Raw Edit

Miscellany

public lua v1 · immutable
#962665 ·published 2008-03-29 22:56 UTC
rendered paste body
-- Include our player extensionsdofile("lib/player.lua")-- 'Macros'NEW_TABLE = { }-- Global setup ---------------------------------------------------------------GameRunning = falseNextGameInProgress = falseNumPlaying = 0				-- Number of people currently playing the game-- Primary game configuration --------------------------------------------------NeededForGame = 6			-- Amount of people needed before a game can startDesertedEndGame = true		-- Should a game end if theres no longer enough players?NewGameDelay = 15			-- Delay in seconds between each gamefunction Player_OnVehicleChange(Player, FromVehicle, ToVehicle, Action)	-- Player has specced	if Action == 1 then		-- We will keep track of our own number of playing		NumPlaying = NumPlaying - 1		if NumPlaying < NeededForGame and DesertedEndGame then			GameRunning = false						if NextGameInProgress then				NextGameInProgress = false				destroyEvent(StartEvent)				destroyEvent(WarningEvent)			end						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		NumPlaying = NumPlaying + 1				if NumPlaying >= NeededForGame and (not GameRunning or not NextGameInProgress) then			PregamePreparation()		end	end		return trueendfunction Player_OnDeath(Killer, Victim)	if Killer:exists() then		Killer:increaseKills()	end	Victim:increaseDeaths()endfunction PregamePreparation()	GameRunning = false	NextGameInProgress = true	Arena:message("Next game will begin in " .. SecondsInWords(NewGameDelay, 2) .. ".")	Arena:message("~Press (F12) if you would like to participate!")		-- Start the client countdown ticker	Arena:setTicker(0, "Next game in ", (NewGameDelay * 100))	-- Setup our delayed start	StartEvent = createEvent(StartGame, (NewGameDelay * 1000), Arena)	-- Setup our 20 second warning	if NewGameDelay > 40 then		WarningEvent = createEvent(StartNotice, ((NewGameDelay - 20) * 1000), Arena)	endendfunction StartGame()	NextGameInProgress = false	GameRunning = true		for x = 1, Arena:numPlayers() do		local Player = Arena:getPlayer(x)				if Player:exists() then			-- Reset stuff used by the previous game			Player:reset()		end	end	PlayingOnStart = NumPlaying	StartTime = os.time()		-- Arena cleanup, reset spawns, hides, etc	Arena:restartGame()		-- It has begun!	Arena("Game started.")endfunction EndGame(WinningTeam)	local RunningTime =  os.time() - StartTime	Arena:message("After " .. SecondsInWords(RunningTime, 2) .. " the game has come to an end.")endfunction SecondsInWords(Seconds, Quanity)	local ReturnString = nil	local Time = 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 ReturnStringend