All pastes #335828 Raw Edit

Stuff

public lua v1 · immutable
·published 2007-02-01 17:00 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_CashCrateVid = 422g_CashCrateDropItemName = "Money $1000"-- Variables to control the HQg_HqRewardTime = -120000				-- 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_HqRewardExponent = 1					-- the exponent to raise the HQ reward to each time it is calculatedg_HqRewardMultiplier = 1.05				-- after raising to the exponent, the multiply this to the HQ reward to each time it is calculatedg_HqRewardAdd = 1						-- after all that, add this to the amountg_HqRewardMax = 1000					-- maximum value for the HQ rewardg_HqRewardPointsMultiplier = 1			-- multiply the base reward by this for pointsg_HqRewardExpMultiplier = 1				-- multiply the base reward by this for experienceg_HqRewardCashMultiplier = 2			-- multiply the base reward by this for cashg_HqRewardDestroyMultiplier = 1			-- multiply this by the last reward to calculate the reward given to the team which destroyed the HQg_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_HqMaxAllowed = 1						-- the maximum amount of HQ you are allowed to have.  Technically you have have more if you steal one with a control item-- This runs when a player types a ? command such as ?mynewcommandfunction Msg_OnCommand(player, command, payload, recipient, msg_type)	cmd = string.lower(command)	if (cmd == "?effect") then		HqDropEffect(player:coords(), player:frequency())	elseif(cmd == "?create") then		CreateHq(player:coords(), player:frequency())	elseif(cmd == "?givebounty") then		givebounty(player.m_name, payload)	elseif(cmd == "?30k") then		if(giveabsbounty(payload, 30000) == false) then			player:message("Unable to give the player 30K bounty.  Most likely you typed the name wrong or the player is in spec")		end	elseif(cmd == "?coord" or cmd == "?coords" ) then		local pos = player:coords()		player:message("Your coordinates are x= " .. pos.x .. ", y= " .. pos.y .. ", z= " .. pos.z .. ", rotation= " ..pos.rotation)	elseif(cmd == "?testdummy") then		local theplayer = g_arena:getPlayer(payload)		if (theplayer:valid() and not theplayer:spectator() ) then			theplayer:setVehicle(131)			return true		else		return false		end		elseif(cmd == "?untestdummy") then		local theplayer = g_arena:getPlayer(payload)		if (theplayer:valid() and not theplayer:spectator() ) then			theplayer:setVehicle(1)			return true		else		return false		end		elseif(cmd == "?stas") then		g_arena:message("STAS is so cool")	elseif (cmd == "?n") then		n(payload)	elseif(cmd == "?f") then		f(payload)	elseif(cmd == "?t") then		t(payload)	elseif(cmd == "?ec") then		something = event_create(ec, payload, g_arena)			elseif(cmd == "?x") then		local tid = team_getid(g_arena, payload)		g_arena:message("tid = " .. tid)	endend-- Runs when the arena is createdfunction 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(RewardHq, g_HqRewardTime, arena)end-- Runs when a player uses a warp itemfunction Player_OnWarpItem(user, itemid, target)	g_arena:message("Player_OnWarpItem ran with itemid = " .. itemid)	-- check to see if the warp item was the item used to create an HQ	if (HqItemMaker(user, itemid, target)) then		return false	else		if (itemid == 119) then			WarpToHQ(user)			return false		end		return true	endend-- Why does this crash my server?!?function Vehicle_OnCreate(vehicle)--	print("Vehicle_OnCreate ran")	--g_arena:message("Vehicle_OnCreate ran")end-- Runs when a computer vehicle is destroyedfunction Vehicle_OnDeath(victim,killer)	-- If it is a baitbox, do this	CheckCashCrateDeath(victim,killer)	-- if it is an headquarters, do this	CheckHqDeath(victim,killer)	return trueend-- place a call to this function in the Vehicle_OnDeath event.-- This function checks to see if a headquarters item maker was launched-- The headquarters item maker is nothing but a warp item in the .itm filefunction HqItemMaker(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		CreateHq(user:coords(), user:frequency())		return true	else		return false	endendfunction HqDropEffect(pos, freq)	g_arena:message("HqDropEffect Ran")	g_arena:explosion_create("Headquarters Drop Effect", pos.x, pos.y , pos.rotation, 0)	HqDropEp = event_createarg(CreateHq, 1000, g_arena, {pos, freq})endfunction CreateHqWrapper(arguments)	g_arena:message("CreateHqWrapper ran. Freq = " .. arguments[1])	CreateHq(arguments[0], tonumber(arguments[1]))end-- Function to create an HQfunction CreateHq(pos, freq)		g_arena:message("CreateHq Ran")		g_arena:message("freq = " .. freq)		g_arena:message("pos.x = " .. pos.x)		local HQ = g_arena:vehicle_create(g_HqVid, pos.x, pos.y, pos.rotation)		HQ:setfrequency(freq)		-- store the initial reward		HQ:setvarint("reward", g_HqRewardInitialAmount)		-- This will eventually start the event procedure for the HQ--		HQ:setvarint("ep", RewardHq())		-- Add code to add this HQ to the g_HqTable		g_HqTableSize = g_HqTableSize + 1		g_HqTable[g_HqTableSize] = HQend-- The event procedure which runs and rewards people for having headquarters-- add this line to the function Arena_OnCreate(arena)-- g_hqrewardep = event_create(RewardHq, g_HqRewardTime, arena)function RewardHq()	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")			-- 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 * g_HqRewardPointsMultiplier) .. " points " .. (TheReward * g_HqRewardExpMultiplier) .. " experience and " .. (TheReward * g_HqRewardCashMultiplier) .. " cash because you are in spec.")				else					member:modpoints(TheReward * g_HqRewardPointsMultiplier)					member:modexperience(TheReward * g_HqRewardExpMultiplier)					member:modcash(TheReward * g_HqRewardCashMultiplier)					member:message("&Headquarters> For defending your headquarters you have receieved " .. (TheReward * g_HqRewardPointsMultiplier) .. " points " .. (TheReward * g_HqRewardExpMultiplier).. " experience and " .. (TheReward * g_HqRewardCashMultiplier) .. " cash.")				end			end								-- calculate the next reward			TheReward = HqCalcReward(TheReward, g_HqRewardExponent, g_HqRewardMultiplier, g_HqRewardAdd)			HQ:setvarint("reward", TheReward)		else			-- destroy the HQ and remove it from the table			-- I should add some kind of neat effect when this happens			HQ:destroy()			table.remove(g_HqTable, x)			g_HqTableSize = g_HqTableSize - 1		end	end	return falseend-- This is for the Warp to HQ item.  It will warp a person to their HQ.  Right now, if they have more than one HQ, it choses one at random.function WarpToHQ(user)	local teamfreq = user:frequency()	local teamHQ = {}	local teamHQsize = 0	for x = 1, g_HqTableSize do		local HQ = g_HqTable[x]		if (HQ:frequency() == teamfreq) then			table.insert(teamHQ, HQ)			teamHQsize = teamHQsize + 1		end	end	if (teamHQsize == 0) then		user:message("&Headquarters> Your team does not have a headquarters you can warp to")		return false	else		local rNum = math.random(1, teamHQsize)		local HQ = teamHQ[rNum]		local pos = HQ:coords()		user:warp(pos.x, pos.y, 0)		return true	endend-- place a call to this function in the Vehicle_OnDeath event.-- This function checks to see if the headquarters vehicle was the one that was destroyed-- then does the rewards and suchfunction CheckHqDeath(victim, killer)	local vid = victim:vehicletypeid()	if (vid == g_HqVid) then		local HqOwnedBy = teamnamefromfreq(victim:frequency())		local TheReward = victim:getvarint("reward")		-- Add code so you don't get a reward if you blow up your own HQ		if (killer:frequency() == victim:frequency()) 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			-- I need to fix this part later				local TheReward = victim:getvarint("reward") * g_HqRewardDestroyMultiplier				if (TheReward > g_HqRewardMax) then					TheReward = g_HqRewardMax				end				-- 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	endend-- function to calulate the HQ rewardfunction HqCalcReward(seed, power, multiplier, addition)	local Reward = math.ceil((math.pow(seed, power) * multiplier) + addition)	if (Reward > g_HqRewardMax) then		Reward = g_HqRewardMax	end	return Rewardend-- place a call to this function in the Vehicle_OnDeath event.-- This function checks to see if a batibox was destroyed and then drops money-- I need to add checks to see if the item will be dropped inside of physics.  If the item drops there-- it disappears.  I think I would also like to make the distance slightly random but all in good timefunction CheckCashCrateDeath(victim, killer)	local vid = victim:vehicletypeid()	-- If it is a baitbox, do this	if (vid == g_CashCrateVid) then		local pos = victim:coords()		local pixeloffset = 70		g_arena:item_create(g_CashCrateDropItemName, 1, pos.x, pos.y)		g_arena:item_create(g_CashCrateDropItemName, 1, pos.x+pixeloffset, pos.y)		g_arena:item_create(g_CashCrateDropItemName, 1, pos.x-pixeloffset, pos.y)		g_arena:item_create(g_CashCrateDropItemName, 1, pos.x, pos.y+pixeloffset)		g_arena:item_create(g_CashCrateDropItemName, 1, pos.x, pos.y-pixeloffset)		g_arena:item_create(g_CashCrateDropItemName, 1, pos.x+pixeloffset, pos.y+pixeloffset)		g_arena:item_create(g_CashCrateDropItemName, 1, pos.x+pixeloffset, pos.y-pixeloffset)		g_arena:item_create(g_CashCrateDropItemName, 1, pos.x-pixeloffset, pos.y+pixeloffset)		g_arena:item_create(g_CashCrateDropItemName, 1, pos.x-pixeloffset, pos.y-pixeloffset)	endend-- This function appears to be moot since there was an undocumented fuction team_fromname(arena, string) I discovered in rox' ZZ script-- This function doesn't even work how it is supposed to now that rox showed me what the return value was from the team_getid() fuction-- Sigh, the team_getid() function only returns the value 4294967295 which demoship says is -1.  Just plain wierd-- Ok, rox added a function team_fromID.  I'll play with this later.function 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 end-- This function returns a team object based on a frequency.  It had to be written since there was no native way to get-- a team object based on its frequencyfunction 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 teamnamefromfreq(freq)	local myteam = oteam_fromfreq(g_arena, freq)	if (myteam:exists()) then		return myteam.m_name	else		return "Non-existant team"	endend-- Sigh, this doesn't work on all serversfunction givebounty(playername, bounty)	local theplayer = g_arena:getPlayer(playername)	if (theplayer:valid() and not theplayer:spectator() ) then		theplayer:message("&Autobounty> Adding " .. bounty .. " bounty to your current bounty.  This will not display on your screen until your next kill.")		theplayer:setbounty(false, tonumber(bounty))		return true	else		return false	endend-- Sigh, this doesn't work on all servers.  If it does, the player does not see that his bounty has risen until after his first kill.function giveabsbounty(playername, bounty)	local theplayer = g_arena:getPlayer(playername)	if (theplayer:valid() and not theplayer:spectator() ) then		theplayer:message("&Autobounty> Setting your bounty at " .. bounty .. ".  This will not display on your screen until your next kill.")		theplayer:setbounty(true, tonumber(bounty))		return true	else		return false	endend-- Just a test function.  I will remove this laterfunction t(teamfreq)	local x = team_getid(g_arena, teamfreq)	g_arena:message("x = " .. x)--	if (x:exists()) then--		g_arena:message(x.m_name)--	else--		g_arena:message("Team with frequency " .. teamfreq .. " does not exist")--	endend-- another test functionfunction n(teamname)	local x = GetTeamIdByName(teamname)	g_arena:message("x = " .. x)end-- another test functionfunction f(teamname)        -- 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)		if (cteam.m_name == teamname) then			local firstplayer = cteam:get(1)			g_arena:message("Freq = " .. firstplayer:frequency())		end	endend-- A simple function to display a messagefunction ec()	g_arena:message("EC ran")	return falseend