GetPlayersInTeam: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
This function is for retrieving all the players in the specified team.
This function retrieves all the players of the specified team.


==Syntax==  
==Syntax==  
Line 11: Line 11:


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


==Example==
==Example==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- Find and kill all the players in a team called "red"
-- Find and kill all the players in the specified team (for example 'killTeam Red').
redTeam = getTeamFromName ( "red" )
function killTeamFunction(player,command,teamName)
if ( redTeam ) then
-- Find and kill all the players in a team called "red"
  players = getPlayersInTeam ( redTeam )   
local team = getTeamFromName ( teamName )
  -- Loop through the player table
if ( team ) then
  for playerKey, playerValue in ipairs(players) do
local players = getPlayersInTeam ( team )   
    -- kill the player
-- Loop through the player table
    killPlayer ( playerValue )
for playerKey, playerValue in ipairs(players) do
  end
-- kill the player
killPlayer ( playerValue )
end
end
end
end
addCommandHandler("killTeam",killTeamFunction)
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Team functions}}
{{Team functions}}

Revision as of 14:08, 27 July 2007

This function retrieves all the players of the specified team.

Syntax

table getPlayersInTeam ( team theTeam )

Optional 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

-- Find and kill all the players in the specified team (for example 'killTeam Red').
function killTeamFunction(player,command,teamName)
	-- Find and kill all the players in a team called "red"
	local team = getTeamFromName ( teamName )
	if ( team ) then
		local players = getPlayersInTeam ( team )  
		-- Loop through the player table
		for playerKey, playerValue in ipairs(players) do
			-- kill the player
			killPlayer ( playerValue )
		end
	end
end

addCommandHandler("killTeam",killTeamFunction)

See Also