All pastes #332399 Raw Edit

Miscellany

public lua v1 · immutable
#332399 ·published 2007-01-29 23:25 UTC
rendered paste body
--- [[ Global Variables ]] ---------- g_arena = nil		-- The global arena class, to avoid having to pass it around functions-- Variables to control the baitboxg_BaitboxVid = 422-- Variables to control the HQg_HqRewardTime = -30000			-- how often in ms will the HQ reward be rewarded and calculatedg_hqrewardep = 0			-- The eventid for the reward from headquarter vehiclesg_HqTable = {}				-- Table that keeps track of all the HQ in the game.  I believe I made it 1 basedg_HqTableSize = 0			-- the g_HqTable size.  It is used for keeping track of how many entries are in the tableg_HqRewardInitialAmount = 5		-- initial seed for the HQ rewardg_HqRewardMax = 2000			-- maximum value for the HQ rewardg_HqItemMaker = 113			-- the warp item which creates the HQg_HqItemMakerName = "Headquarters Kit"	-- the warp item's name (this was a work around since I can't modify inventory based on item number from the .itm file)g_HqVid = 423				-- the HQ vehicle IDg_HqDestroyMultiplier = 2		-- the amount multiplied to the reward given to the destroying teamg_HqMaxAllowed = 1			-- the maximum amount of HQ you are allowed to have.  Technically you have have more if you steal one with a control itemfunction getteamfreq(teamname)	local myteam = team_fromname(g_arena, teamname)	if myteam:exists() then		local firstplayer = myteam:get(1)		g_arena:message("team frequency = " .. firstplayer:frequency())	else		g_arena:message("Team not found")	endendfunction t(teamfreq)	local x = oteam_fromfreq(g_arena, teamfreq)	if (x:exists()) then		g_arena:message(x.m_name)	else		g_arena:message("Team with frequency " .. teamfreq .. " does not exist")	endendfunction Arena_OnCreate(arena)	g_arena = arena	-- Install the event procedure to calculate the reward and award people for having an HQ        g_hqrewardep = event_create(hqreward, g_HqRewardTime, g_arena)endfunction Player_OnWarpItem(user, itemid, target)	-- check to see if the warp item was the item used to create an HQ	if (checkhqitemmaker(user, itemid, target)) then		return false	else		return true	endend--function Vehicle_OnCreate(vehicle)--	g_arena:message("Vehicle_OnCreate ran")--endfunction Vehicle_OnDeath(victim,killer)	-- remove this next line.  It is only for testing	g_arena:message("Vehicle_OnDeath ran")	-- If it is a baitbox, do this	checkbaitboxdeath(victim,killer)	-- if it is an headquarters, do this	checkhqdeath(victim,killer)	return trueendfunction checkhqitemmaker(user, itemid, target)	-- add code so there is a limit to the number of HQ	if (itemid == g_HqItemMaker) then		-- First loop through all the HQ and see if this team already possess one		for i = 1, g_HqTableSize do			local HqCheck = g_HqTable[i]			if (HqCheck:frequency() == user:frequency()) then				user:message("&Headquarters> Your team already has the maximum amount of headquarters in their possesion")				-- Give the guy his kit back				user:inventory_modify("Headquarters Kit", 1)				return false			end		end	        local pos = user:coords()	        local HQ = g_arena:vehicle_create(g_HqVid, pos.x, pos.y, pos.rotation)		HQ:setfrequency(user:frequency())		-- store the team name and the initial reward		HQ:setvar("OwnedBy", user:getTeam().m_name)		HQ:setvarint("reward", g_HqRewardInitialAmount)		-- Add code to add this HQ to the g_HqTable		g_HqTableSize = g_HqTableSize + 1		g_HqTable[g_HqTableSize] = HQ		return true	else		return false	endendfunction hqreward()	if (q_HqTableSize == 0) then		return false	end	for x = 1, g_HqTableSize do		local HQ = g_HqTable[x]		local TheTeam = oteam_fromfreq(g_arena, HQ:frequency())		if TheTeam:exists() then			local TheReward = HQ:getvarint("reward") * 10			if TheReward > g_HqRewardMax then				TheReward = g_HqRewardMax			end			-- Sloppy.  I will fix later			HQ:setvarint("reward", HQ:getvarint("reward") + g_HqRewardInitialAmount)			-- enum all the members			local numMembers = TheTeam:num()			for i = 1, numMembers do				local member = TheTeam:get(i)				if (member:spectator()) then 					member:message("&Headquarters> You missed out on the team reward of " .. TheReward .. " points " .. TheReward .. " cash and " .. TheReward .. " experience because you are in spec.")				else					member:modpoints(TheReward)					member:modcash(TheReward)					member:modexperience(TheReward)					member:message("&Headquarters> For defending your headquarters you have receieved " .. TheReward .. " points " .. TheReward .. " cash and " .. TheReward .. " experience.")				end			end							else			--destroy the HQ and remove it from the table			HQ:destroy()			table.remove(g_HqTable, x)			g_HqTableSize = g_HqTableSize - 1		end	end	return falseendfunction checkbaitboxdeath(victim, killer)	local vid = victim:vehicletypeid()	-- If it is a baitbox, do this	if (vid == g_BaitboxVid) then		local pos = victim:coords()		local pixeloffset = 70		g_arena:item_create("Money $1000", 1, pos.x, pos.y)		g_arena:item_create("Money $1000", 1, pos.x+pixeloffset, pos.y)		g_arena:item_create("Money $1000", 1, pos.x-pixeloffset, pos.y)		g_arena:item_create("Money $1000", 1, pos.x, pos.y+pixeloffset)		g_arena:item_create("Money $1000", 1, pos.x, pos.y-pixeloffset)		g_arena:item_create("Money $1000", 1, pos.x+pixeloffset, pos.y+pixeloffset)		g_arena:item_create("Money $1000", 1, pos.x+pixeloffset, pos.y-pixeloffset)		g_arena:item_create("Money $1000", 1, pos.x-pixeloffset, pos.y+pixeloffset)		g_arena:item_create("Money $1000", 1, pos.x-pixeloffset, pos.y-pixeloffset)	endendfunction checkhqdeath(victim, killer)	local vid = victim:vehicletypeid()	if (vid == g_HqVid) then		local HqOwnedBy = victim:getvar("OwnedBy")		local HqReward = victim:getvarint("reward")		-- Add code so you don't get a reward if you blow up your own HQ		if (killer:getTeam().m_name == HqOwnedBy) then			killer:message("&Headquarters> You don't get a reward for destroying your own headquarters")			-- message the team and tell them who the idiot was			local TheTeam = team_fromname(g_arena, killer:getTeam().m_name)			if TheTeam:exists() then				-- enum all the members				local numMembers = TheTeam:num()				for i = 1, numMembers do					local member = TheTeam:get(i)					member:message("&Headquarters> Your headquarters was destroyed by your teammate, " .. killer.m_name)				end			end		else						--reward the team which killed the HQ			local TheTeam = team_fromname(g_arena, killer:getTeam().m_name)			if TheTeam:exists() then				local TheReward = victim:getvarint("reward") * 10				if TheReward > g_HqRewardMax then					TheReward = g_HqRewardMax				end				-- Sloppy.  I will fix later				victim:setvarint("reward", victim:getvarint("reward") + g_HqRewardInitialAmount)				-- enum all the members				local numMembers = TheTeam:num()				for i = 1, numMembers do					local member = TheTeam:get(i)					if (member:spectator()) then 						member:message("&Headquarters> " .. killer.m_name .. " has finished off " .. HqOwnedBy .. "'s headquarters.  You missed out on the reward of " .. TheReward .. " points, " .. TheReward .. " cash, and " .. TheReward .. " experience because you are in spec.")					else						member:modpoints(TheReward)						member:modcash(TheReward)						member:modexperience(TheReward)						member:message("&Headquarters> " .. killer.m_name .. " has finished off " .. HqOwnedBy .. "'s headquarters.  Your team has been rewarded " .. TheReward .. " points, " .. TheReward .. " cash, and " .. TheReward .. " experience.")					end				end			end		end	-- remove the entry from the table	local y = 0	while y < g_HqTableSize do		y = y + 1		local HQ = g_HqTable[y]		if (HQ:vehicleid() == victim:vehicleid()) then			table.remove(g_HqTable, y)			y = 0			g_HqTableSize = g_HqTableSize - 1		end	end	endendfunction removehqfromtable(oHq, table)	local y = 0	while y < g_HqTableSize do		y = y + 1		local HQ = g_HqTable[y]		if (HQ:vehicleid() == victim:vehicleid()) then			table.remove(g_HqTable, y)			y = 0			g_HqTableSize = g_HqTableSize - 1		end	endend-- This function appears to be moot since there was an undocumented fuction team_fromname(arena, string) I discovered in rox' ZZ scriptfunction GetTeamIdByName(teamname)	-- Return the team id for a team by name.  If the team doesn't exist, return 0 which is a team that doesn't exist        local numteams = g_arena:numteam()        for i = 1,  numteams do		local xteam = g_arena:getteam(i) 		if (xteam.m_name == teamname) then			return i                 end        end	return 0 endfunction oteam_fromfreq(l_arena, teamfreq)	-- make sure that teamfreq is in number format	teamfreq = tonumber(teamfreq)        -- Cycle through the teams        local numteams = g_arena:numteam()	-- teamids are 1 based        for i = 1, numteams do               -- Get team structure                local cteam = g_arena:getteam(i)		-- since there is no team:frequency() method at the time of this writting of this script		-- we have to grab the first player and find his frequency		local firstplayer = cteam:get(1)		if (firstplayer:frequency() == teamfreq) then			return cteam		end	end	-- not sure what I should return if the team wasn't found, so return a team that doesn't exist	return team_fromname(l_arena, "somenamenoonewi11us3")	endfunction givebounty(playername, bounty)	local theplayer = g_arena:getPlayer(playername)	theplayer:message("Giving you " .. bounty .. " bounty")	theplayer:setbounty(true, bounty)end