All pastes #558868 Raw Edit

Skirmish Script

public lua v1 · immutable
·published 2007-06-11 15:08 UTC
rendered paste body
if (g_arena == nil) then	g_arena = nil	g_bGameRunning = false	g_statsEvent = 0 -- holds the event for displaying stats when the game ends	g_gameTime = nil -- holds the game timeend-- when the arena is first created, this function is called (whether it is public1 being created, or a private arena -it doesn't matter)function Arena_OnCreate(arena)            g_arena = arena    math.randomseed(os.time())end-- when someone joinsfunction Player_OnJoin(player)	player:message("Welcome to skirmish, " .. player.m_name)end-- when anyone dies in your zone, this function is called, it gives you two objects, the killer and the victimfunction Player_OnDeath(killer, victim)	-- get the victims coords	local pos = victim:coords()		-- these are the items we want to use	local weapon = {}	weapon[0] = "4.55mm Rifle FMJ"	weapon[1] = "10mm Pistol Cartridge"        weapon[2] = "Shotgun Shells"	weapon[3] = "Hand Grenade"	weapon[4] = "12.7mm Rifle FMJ"	weapon[5] = "Demo Charge"	weapon[6] = "Incinerator Grenade"	weapon[7] = "20mm HEAT"	weapon[8] = "40mm HE Cartridge"	weapon[9] = "LAW"		local amount = {}	for x = 0, 9 do		amount[x] = victim:inventory_find(weapon[x])		if (amount[x] > 0) then			victim:inventory_modify(weapon[x],-amount[x])			g_arena:item_create(weapon[x], math.ceil(amount[x]/2), (math.random(-200, 200) + pos.x), (math.random(-200, 200) + pos.y))		end	end		local vid = victim:getVehicle():vehicletypeid()	if (vid == 101) then -- Grenadier		victim:inventory_modify(weapon[8], 500)		victim:inventory_modify(weapon[2], 500)		victim:inventory_modify(weapon[3], 500)	elseif (vid == 106) then -- Light Machinegunner		victim:inventory_modify(weapon[0], 500)		victim:inventory_modify(weapon[3], 500)	elseif (vid == 100) then -- Marine		victim:inventory_modify(weapon[0], 500)		victim:inventory_modify(weapon[2], 500)		victim:inventory_modify(weapon[3], 500)		victim:inventory_modify(weapon[9], 500)	elseif (vid == 104) then -- Medic		victim:inventory_modify(weapon[1], 500)		victim:inventory_modify(weapon[3], 500)	elseif (vid == 105) then -- Ripper Gunner		victim:inventory_modify(weapon[7], 500)		victim:inventory_modify(weapon[3], 500)		victim:inventory_modify(weapon[9], 500)	elseif (vid == 102) then -- Sapper		victim:inventory_modify(weapon[2], 500)		victim:inventory_modify(weapon[3], 500)		victim:inventory_modify(weapon[5], 500)		victim:inventory_modify(weapon[6], 500)	elseif (vid == 103) then -- Sniper		victim:inventory_modify(weapon[4], 500)		victim:inventory_modify(weapon[1], 500)	else		g_arena:message("&" .. victim.m_name .. " is abusing by not using one of the normal classes!")	endend-- when the game starts, it sets gameRunning to truefunction Arena_OnGameStart()	g_bGameRunning = true	g_gameStartTime = os.time()end-- when the game finishes, it sets gameRunning to falsefunction Arena_OnGameEnd()	-- display the stats in 0.1 seconds	g_statsEvent = event_create(DisplayStats,100,g_arena)end	function DisplayStats(ev)	g_bGameRunning = false		local bestKiller = ""	local bestVictim = ""	local mostKills = 0	local mostDeaths = 0		for x = 1, g_arena:num() do   --This gets the person with most kills		local player = g_arena:get(x)				player:setstat(5,0) -- set it so the player doesn't have a crown in our database				if (player:getstat(0) > mostKills) then			mostKills = player:getstat(0)			bestKiller = player.m_name		elseif (player:getstat(0) == mostKills) then			bestKiller = ("" .. bestKiller .. ", " .. player.m_name .. "")		end				if (player:getstat(1) > mostDeaths) then			mostDeaths = player:getstat(1)			bestVictim = player.m_name		elseif (player:getstat(1) == mostDeaths) then			bestVictim = ("" .. bestVictim .. ", " .. player.m_name .. "")		end	end			--------------------------- GAME TIME STATISTICS --	if (g_gameTime ~= nil) then		local diff = (os.time() - g_gameTime)		local minutes = math.floor(diff / 60)		if (minutes == 1) then			local seconds = (diff-60*math.floor(diff/60))			g_arena:message("Total Game Time: " .. minutes .. " minute, " .. seconds .. " seconds")		elseif (minutes > 1) then			local seconds = (diff-60*math.floor(diff/60))			g_arena:message("Total Game Time: " .. minutes .. " minutes, " .. seconds .. " seconds")		else			g_arena:message("Total Game Time: " .. diff .. " seconds")		end	else		g_arena:message("The Game Is Not Running")	end		----------------------------- PLAYER STATISTICS ------------------	if (mostKills == 0) then		g_arena:message("!_    No one got any kills!")	else		g_arena:message("!_    Most Kills: " .. bestKiller .. "(" .. mostKills .. ")")	end		if (mostDeaths == 0) then		g_arena:message("!_    No one got any deaths!")	else		g_arena:message("!_    Most Deaths: " .. bestVictim .. "(" .. mostDeaths .. ")")	end		for x = 1, g_arena:num() do		local player = g_arena:get(x)		player:message("Your Score: " .. player:getstat(0) .. " Kills, " .. player:getstat(1) .. " Deaths")	end	------------------------------------------------------------------------	return falseend