GetPlayersInTeam: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(I assume the team isn't an optional argument?)
No edit summary
Line 15: Line 15:


==Example==
==Example==
<section name="Server" class="server" show="true">
Find and kill all the players in the specified team (for example 'killTeam Red').
Find and kill all the players in the specified team (for example 'killTeam Red').
<section name="Server" class="server" show="true">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function killTeamFunction(player,command,teamName)
function killTeamFunction ( thePlayer, command, teamName )
-- Find and kill all the players in a team called "red"
-- Find and kill all the players in the team that was specified with the console command
local team = getTeamFromName ( teamName )
local theTeam = getTeamFromName ( teamName )
if ( team ) then
if ( theTeam ) then
local players = getPlayersInTeam ( team )
local players = getPlayersInTeam ( theteam )
-- Loop through the player table
-- Loop through the player table
for playerKey, playerValue in ipairs(players) do
for playerKey, playerValue in ipairs ( players ) do
-- kill the player
-- kill the player
killPlayer ( playerValue )
killPlayer ( playerValue )
Line 31: Line 31:
end
end


addCommandHandler("killTeam",killTeamFunction)
addCommandHandler ( "killTeam", killTeamFunction )
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>


This example will show all players in a team, when a player types the 'showTeam TeamName' command.
<section name="Client" class="client" show="true">
<section name="Client" class="client">
This example will show all players in a team when a player types the 'showTeam TeamName' command.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function showTeamFunction(command,teamName)
function showTeamFunction ( command, teamName )
 
         -- Find and show all the players in the team that was specified with the console command
         -- Find and kill all the players in a team called "red"
         local theTeam = getTeamFromName ( teamName )
         local team = getTeamFromName ( teamName )
         if ( theTeam ) then
         if ( team ) then
                 local players = getPlayersInTeam ( theTeam )  
                 local players = getPlayersInTeam ( team )  
                 -- Loop through the player table
                 -- Loop through the player table
                 for playerKey, playerValue in ipairs(players) do
                 for playerKey, playerValue in ipairs ( players ) do
                         outputChatBox ( getPlayerName(playerValue) )
                         outputChatBox ( getPlayerName(playerValue) )
                 end
                 end
Line 51: Line 50:
end
end


addCommandHandler("showTeam",showTeamFunction)
addCommandHandler ( "showTeam", showTeamFunction )
</syntaxhighlight>
</syntaxhighlight>
</section>
</section>

Revision as of 14:57, 19 August 2007

This function retrieves all the players of the specified team.

Syntax

table getPlayersInTeam ( team theTeam )

Arguments

  • theTeam: The team you wish to retrieve all the players from.

Returns

Returns a table of all the players in the team, or an empty one if there are none.

Example

Click to collapse [-]
Server

Find and kill all the players in the specified team (for example 'killTeam Red').

function killTeamFunction ( thePlayer, command, teamName )
	-- Find and kill all the players in the team that was specified with the console command
	local theTeam = getTeamFromName ( teamName )
	if ( theTeam ) then
		local players = getPlayersInTeam ( theteam )
		-- Loop through the player table
		for playerKey, playerValue in ipairs ( players ) do
			-- kill the player
			killPlayer ( playerValue )
		end
	end
end

addCommandHandler ( "killTeam", killTeamFunction )
Click to collapse [-]
Client

This example will show all players in a team when a player types the 'showTeam TeamName' command.

function showTeamFunction ( command, teamName )
        -- Find and show all the players in the team that was specified with the console command
        local theTeam = getTeamFromName ( teamName )
        if ( theTeam ) then
                local players = getPlayersInTeam ( theTeam ) 
                -- Loop through the player table
                for playerKey, playerValue in ipairs ( players ) do
                        outputChatBox ( getPlayerName(playerValue) )
                end
        end
end

addCommandHandler ( "showTeam", showTeamFunction )

See Also