All pastes #370742 Raw Edit

Miscellany

public lua v1 · immutable
#370742 ·published 2007-02-24 20:52 UTC
rendered paste body
--Bughunt script--- [[ Global Variables ]] ----------g_arena = nil      -- The global arena class, to avoid having to pass it around functionsg_bGameRunning = false  -- Is the game running?g_statsEvent = 0 -- holds the event for displaying stats when the game endsg_gameTime = nil -- holds the game timeg_startTime = nil -- for timer stuff--- Science Object A ---g_personA = nil -- the person currently holding Ag_startTimeA = nil -- the start time of when the flag has first entered the drop areag_currentDiffA = nilg_eventA = nilg_wonA = false----------------------------Flag spawnsg_x5 = 10776g_y5 = 1336g_x6 = 9400g_y6 = 10708--- Science Object B ---g_personB = nil -- the person currently holding Bg_startTimeB = nil -- the start time of when the flag has first entered the drop areag_currentDiffB = nilg_eventB = nilg_wonB = false------------------------------ first drop area --g_x1 = 13227g_y1 = 247g_x2 = 13774g_y2 = 447 ------------------------ and the other area --g_x3 = 5676g_y3 = 2740g_x4 = 6152g_y4 = 2996------------------------dofile("bhstats.lua")function Arena_OnCreate(arena)            g_arena = arena		local cfg = GameSettings()	cfg.minplayers = 1	cfg.gamedelay = 20		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())end-- when a player kills another player drop some body parts for the killerfunction Player_OnDeath(killer, victim)		if (victim:inventory_find("Science Object A") >= 1) then			g_arena:item_create("Science Object A", 1, 10776, 1336)			Removeobjects(victim)			event_destroy(g_eventA)			g_eventA = nil		end		if (victim:inventory_find("Science Object B") >= 1) then			g_arena:item_create("Science Object B", 1, 9400, 10708)			Removeobjects(victim)			event_destroy(g_eventB)			g_eventB = nil		end		local pos = victim:coords()	--lets refill each marine's ammo, first heavy		if (victim:getVehicle():vehicletypeid() == 104) then			victim:inventory_modify("Ammo",400)				killer:inventory_modify("Cash",2)				g_arena:item_create("Ammo", 150, pos.x, pos.y)			g_arena:item_create("Marine Heart", 1, pos.x, pos.y)		return true	--then for marine		elseif (victim:getVehicle():vehicletypeid() == 100) then			victim:inventory_modify("Ammo",400)				killer:inventory_modify("Cash",2)				g_arena:item_create("Ammo", 150, pos.x, pos.y)			g_arena:item_create("Marine Heart", 1, pos.x, pos.y)		return true	--then for the medic		elseif (victim:getVehicle():vehicletypeid() == 102) then			victim:inventory_modify("Ammo",400)				killer:inventory_modify("Cash",2)				g_arena:item_create("Ammo", 150, pos.x, pos.y)			g_arena:item_create("Marine Heart", 1, pos.x, pos.y)		return true	--and finally,for the sergeant		elseif (victim:getVehicle():vehicletypeid() == 101) then			victim:inventory_modify("Ammo",400)				killer:inventory_modify("Cash",2)				g_arena:item_create("Ammo", 150, pos.x, pos.y)			g_arena:item_create("Marine Heart", 1, pos.x, pos.y)		return true	end		if (g_bGameRunning == false) then -- if the game isn't running, don't record stats			return			elseif (killer:valid() == false) then -- if the killer was a turret/terrain we just increase the death count			IncreaseDeath(victim) 			return			elseif (killer.m_name == victim.m_name) then -- if the player killed themself we just increase the death count			IncreaseDeath(victim)		return	end	-- else one player killed another player, so we increase the kill count and death count respectively			IncreaseKill(killer)			IncreaseDeath(victim)endfunction FlagEventA(eventA)	if (g_personA:valid() == false) then		event_destroy(g_eventA)		g_eventA = nil		return	elseif (g_personA:spectator() == true) then		g_personA:inventory_modify("Science Object A", -1000)		g_arena:item_create("Science Object A", 1, 10776, 1336)		event_destroy(g_eventA)		g_eventA = nil		return	elseif (g_personA:inventory_find("Science Object A") == 0) then -- Is the player still alive? (if he dies this item will be removed)		event_destroy(g_eventA)						    -- This should never be called		g_eventA = nil		return	end   	if (g_startTimeA ~= nil) then		g_currentDiffA = (os.time() - g_startTimeA)	end		local coords = g_personA:coords()	if ( ((coords.x > g_x1) and (coords.x < g_x2) and (coords.y > g_y1) and (coords.y < g_y2)) or ((coords.x > g_x3) and (coords.x < g_x4) and (coords.y > g_y3) and (coords.y < g_y4)) == true )	then -- are they in a position to drop the flag?				if (g_startTimeA == nil) then			g_startTimeA = os.time()			g_personA:message("Dropping flag A in 20 seconds")				elseif (g_currentDiffA == 5) then			g_personA:message("Dropping flag A in 15 seconds")				elseif (g_currentDiffA == 10) then			g_personA:message("Dropping flag A in 10 seconds")				elseif (g_currentDiffA == 15) then			g_personA:message("Dropping flag A in 5 seconds")				elseif (g_currentDiffA >= 20) then			g_personA:message("Flag A Dropped")			g_personA:inventory_modify("Science Object A", -100)			g_arena:item_create("Science Object A Captured", 1, coords.x, coords.y)			g_wonA = true			event_destroy(g_eventA)			g_eventA = nil			if (g_wonB == true) then				g_arena:message("&The Marines have Captured the Science Objectives! Game Over")				g_state:Endgame()			end		end	elseif (g_startTimeA ~= nil) then --they have the flag, but have now stepped out the area!! omg, lets reset their timer		g_startTimeA = nil		g_personA:message("You exited the flag drop area, timer has been reset")	endendfunction FlagEventB(eventB)	if (g_personB:valid() == false) then		event_destroy(g_eventB)		g_eventB = nil		return	elseif (g_personB:spectator() == true) then		g_personB:inventory_modify("Science Object B", -1000)		g_arena:item_create("Science Object B", 1, 10776, 1336)		event_destroy(g_eventB)		g_eventB = nil		return	elseif (g_personB:inventory_find("Science Object B") == 0) then -- Is the player still alive? (if he dies this item will be removed)		event_destroy(g_eventB)						    -- This should never be called		g_eventB = nil		return	end   	if (g_startTimeB ~= nil) then		g_currentDiffB = (os.time() - g_startTimeB)	end		local coords = g_personB:coords()	if ( ((coords.x > g_x1) and (coords.x < g_x2) and (coords.y > g_y1) and (coords.y < g_y2)) or ((coords.x > g_x3) and (coords.x < g_x4) and (coords.y > g_y3) and (coords.y < g_y4)) == true )	then -- are they in a position to drop the flag?				if (g_startTimeB == nil) then			g_startTimeB = os.time()			g_personB:message("Dropping flag B in 20 seconds")				elseif (g_currentDiffB == 5) then			g_personB:message("Dropping flag B in 15 seconds")				elseif (g_currentDiffB == 10) then			g_personB:message("Dropping flag B in 10 seconds")				elseif (g_currentDiffB == 15) then			g_personB:message("Dropping flag B in 5 seconds")				elseif (g_currentDiffB >= 20) then			g_personB:message("Flag B Dropped")			g_personB:inventory_modify("Science Object B", -100)			g_arena:item_create("Science Object B Captured", 1, coords.x, coords.y)			g_wonB = true			event_destroy(g_eventB)			g_eventB = nil			if (g_wonA == true) then				g_arena:message("&The Marines have Captured the Science Objectives! Game Over")				g_state:Endgame()			end		end	elseif (g_startTimeB ~= nil) then --they have the flag, but have now stepped out the area!! omg, lets reset their timer		g_startTimeB = nil		g_personB:message("You exited the flag drop area, timer has been reset")	endendfunction Item_OnPickUp(looter, loot, loot_type, amounttopickup)	if (loot_type.m_name == "Science Object A") then        -- Dont't let skrall or any other class besides sergeant pick it up		if (looter:getVehicle():vehicletypeid() >= 200) then			looter:message("You can't eat the science objects!")       			 return false		elseif (looter:getVehicle():vehicletypeid() ~= 101) then			looter:message("Only the Sergeant may capture the Science objects!")			 return false		elseif (looter:getVehicle():vehicletypeid() == 101) then			g_personA = looter			g_startTimeA = nil			if (g_eventA == nil) then				g_eventA = event_create(FlagEventA, -1000, g_arena)			end			return true		else			return false		end	elseif (loot_type.m_name == "Science Object A Captured") then		looter:message("This objective has already been captured!")		return false		elseif (loot_type.m_name == "Science Object B") then        -- Dont't let skrall or any other class besides sergeant pick it up		if (looter:getVehicle():vehicletypeid() >= 200) then			looter:message("You can't eat the science objects!")       			 return false		elseif (looter:getVehicle():vehicletypeid() ~= 101) then			looter:message("Only the Sergeant may capture the Science objects!")			 return false		elseif (looter:getVehicle():vehicletypeid() == 101) then			g_personB = looter			g_startTimeB = nil			if (g_eventB == nil) then				g_eventB = event_create(FlagEventB, -1000, g_arena)-- whatever				end			return true		else			return false		end	elseif (loot_type.m_name == "Science Object B Captured") then		looter:message("This objective has already been captured!")		return false	end	return trueend   -- when a player enters the zone, it gives them this messagefunction Player_OnJoin(player)    player:message("&Note: Welcome to Bughunt, Check out Skrallistan at www.skrallistan.co.nr! Post any Ideas/Suggestions you have on there!")	WipePlayerStats(player)	Removeobjects(player)end-- when the game starts, it sets gameRunning to truefunction Arena_OnGameStart()	g_arena:item_create("Science Object A", 1, 10776, 1336)	g_arena:item_create("Science Object B", 1, 9400, 10708)	g_startTime = os.time()	g_bGameRunning = true	g_gameTime = os.time()	for x = 1, g_arena:num() do		local player = g_arena:get(x)		WipePlayerStats(player)		Removeobjects(player)	end		--- Lets clear all the crap for the next game ---	g_wonA = false	g_wonB = false	end-- when the game finishes, it sets gameRunning to falsefunction Arena_OnGameEnd()	DisplayStats()	--stop all events that are still running	event_flush(g_arena)	g_eventA = nil	g_eventB = nil	g_bGameRunning = false	if ((g_wonA == false) or (g_wonB == false)) then		g_arena:message("Skrall is Victorious!")	endendfunction DisplayCoords()	h = g_arena:getPlayer("HellSpawn"):coords()	g_arena:message("x = " .. h.x .. " y = " .. h.y .. "")endfunction Arena_TickerUpdate()	-- Set some locals	if g_startTime ~= nil then		local currentTime = (600 - (os.time() - g_startTime))	if (currentTime == 0) then		g_state:Endgame()	end	-- Show the timer		g_state:SetNotice(0, "Game Time = " .. currentTime .. "")	endendfunction Removeobjects(player)	player:inventory_modify("Science Object A", -1000)	player:inventory_modify("Science Object B", -1000)end