All pastes #593168 Raw Edit

Untitled

public lua v1 · immutable
#593168 ·published 2007-06-28 05:34 UTC
rendered paste body
g_teams = { { } }g_invite = { { } } function PlayerTeamCreate(player, command, payload, recipient, msg_type)	local currteam = { }	local found = false 	local position = 0	local ateam = nil			if (player:valid() == true and player:spectator() == false) then		if (string.find(player:getTeam().m_name, "Titan") ~= nil) then			local validteam = false			for x = 1, 15 do				ateam = team_fromname(g_arena, "Titan Rogue " .. x)				if (ateam:exists() == false) then					local teamname = "Titan Rogue " .. x					for index, value in pairs(g_teams) do 						currteam = g_teams[index]						if (currteam[1] == teamname) then							found = true							position = index 						end					end					if (found == true) then						table.remove(g_teams, position)                					end					table.insert(g_teams, {teamname, player.m_name})					player:team_change(teamname, "")					player:message("You joined " .. teamname)					validteam = true					break				end			end			if (validteam == false) then				player:message("No teams available")			end		elseif (string.find(player:getTeam().m_name, "Europa") ~= nil) then			local validteam = false			for x = 1, 15 do				ateam = team_fromname(g_arena, "Europa Rogue " .. x)				if (ateam:exists() == false) then					local teamname = "Europa Rogue " .. x					for index, value in pairs(g_teams) do 						currteam = g_teams[index]						if (currteam[1] == teamname) then							found = true							position = index 						end					end					 if (found == true) then						table.remove(g_teams, position)                					end					table.insert(g_teams, {teamname, player.m_name})					player:team_change(teamname, "")					player:message("You joined " .. teamname)					validteam = true					break				end			end			if (validteam == false) then				player:message("No teams available")			end		else			player:message("You need to be in a public Titan or Europa team to create a private team")		end	else		player:message("Spectators and invalid players are not able to make teams")	endend -- functionfunction PlayerInvite(player, command, payload, recipient, msg_type)    if (payload == "" and recipient == "") then        player:message("Incorrect syntax, use: ?invite <name> or send a private message with ?invite to the player you wish to invite")     else				local invitee = nil        local found = false        local position = 0        local playerTeam = player:getTeam().m_name				if (recipient ~= "") then			invitee = g_arena:getPlayer(recipient)		else			invitee = g_arena:getPlayer(payload)		end		        if (invitee ~= nil and player ~= nil) then            if (invitee:valid() == true and player:valid() == true and player:spectator() == false and invitee:spectator() == false) then				if (string.find(playerTeam, "Titan") ~= nil and string.find(invitee:getTeam().m_name, "Titan") ~= nil) or					(string.find(playerTeam, "Europa") ~= nil and string.find(invitee:getTeam().m_name, "Europa") ~= nil) then					invitee:message("You have been invited by " .. player.m_name .. " to " .. playerTeam .. ".  Type ?accept " .. player.m_name .. " to join the team.  Type ?reject " .. player.m_name .. " to decline the offer.") 	                for index, value in pairs(g_invite) do 	                local currteam = g_invite[index]		                if (currteam[1] == invitee.m_name) then		                    if (currteam[2] == playerTeam) then 		                        found = true		                        position = index		                    end		                end					end				else 					player:message("Unable to invite players from the other team")				end			else				player:message("Either the inviter or invitee is either invalid or in spec")            end            if (found == true) then                table.remove (g_invite, position)                            end            table.insert(g_invite, {invitee.m_name, playerTeam, player.m_name})        else            g_arena:message("Invalid player invited")        end    endendfunction PlayerAccept(player, command, payload, recipient, msg_type)    if (payload == "" and recipient == "") then		player:message("Incorrect syntax, use: ?accept <name> or send a private message with ?accept to the player that invited you")     else        local found = false        local position = 0		local inviteTeam = nil        local playerTeam = player:getTeam().m_name		local iTeam = nil 		local iPlayer = nil				if (recipient ~= "") then			iPlayer = g_arena:getPlayer(recipient)		else			iPlayer = g_arena:getPlayer(payload)		end						if (iPlayer ~= nil) and (iPlayer:valid() == true) then			iTeam = iPlayer:getTeam()		end				if (iTeam ~= nil) then			inviteTeam = iTeam.m_name	        if (player ~= nil and playerTeam ~= nil) then	            if (player:valid() == true and player:spectator() == false) then	                for index, value in pairs(g_invite) do 	                local currteam = g_invite[index]		                if (currteam[1] == player.m_name) then							if (currteam[2] == inviteTeam) then			                    if (string.find(currteam[2], "Titan") ~= nil and string.find(playerTeam, "Titan") ~= nil) or									(string.find(currteam[2], "Europa") ~= nil and string.find(playerTeam, "Europa") ~= nil) then 			                        found = true			                        position = index								end							end		                end					end					            end				local currteam = g_invite[position]				if (iTeam:num() < 6) then								if (found == true) then						table.remove (g_invite, position)						table.insert(g_teams, {inviteTeam, player.m_name})						player:team_change(inviteTeam, "")						player:message("You have accepted " .. currteam[3] .. "'s offer to join " .. currteam[2])					end				else					player:message("Too many players on " .. currteam[2] .. " to join")	            end			else				g_arena:message("Invalid player attempted to accept")			end		end    endendfunction PlayerReject(player, command, payload, recipient, msg_type)     if (payload == "" and recipient == "") then		player:message("Incorrect syntax, use: ?reject <name> or send a private message with ?reject to the player that invited you")     else		local found = false        local position = 0		local iTeam = nil 		local iPlayer = nil				if (recipient ~= "") then			iPlayer = g_arena:getPlayer(recipient)		else			iPlayer = g_arena:getPlayer(payload)		end						if (iPlayer ~= nil) and (iPlayer:valid() == true) then			iTeam = iPlayer:getTeam()		end				if (player ~= nil) and (iTeam ~= nil) then			if (player:valid() == true) and (iTeam:exists() == true) then				local inviteTeam = iTeam.m_name				local inviter = iPlayer.m_name				for index, value in pairs(g_invite) do 					local currteam = g_invite[index]					if (currteam[1] == player.m_name) then						if (currteam[2] == inviteTeam) then							table.remove (g_invite, position)							if (inviter ~= nil) then								if (inviter:valid() == true) then									inviter:message("" .. player.m_name .. " rejected your offer to join " .. currteam[2])								end							end							player:message("You rejected " .. currteam[3] .. "'s offer to join " .. currteam[2])						end					end				end			else				player:message("Invalid team to reject or team no longer exists")			end			player:message("Invalid team to reject")		end	endendfunction PlayerList(player, command, payload, recipient, msg_type)	local count = 0	if (player ~= nil) then		if (player:valid() == true) then			for index, value in pairs(g_invite) do 				local currteam = g_invite[index]				if (currteam[1] == player.m_name) then					if (currteam[2] == payload) then						player:message("You were invited to " .. currteam[2] .. " by " .. currteam[3])						count = count + 1					end				end			end			if (count == 0) then				player:message("You were not invited to any teams")			else				player:message("You were invited to a total of " .. count .. " teams")			end		end	end	end