GetPlayersInTeam: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(OOP syntax added)
 
(8 intermediate revisions by 5 users not shown)
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
This function is for retrieving all the players in the specified team.
{{Server client function}}
This function retrieves all the players of the specified team.


==Syntax==  
==Syntax==  
Line 6: Line 7:
table getPlayersInTeam ( team theTeam )
table getPlayersInTeam ( team theTeam )
</syntaxhighlight>  
</syntaxhighlight>  
 
{{OOP||[[team]]:getPlayers|players|}}
===Optional Arguments===  
===Arguments===  
*'''theTeam:''' The team you wish to retrieve all the players from.
*'''theTeam:''' The team you wish to retrieve all the players from.


===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 else false if invalid arguments are passed.


==Example==
==Example==
<section name="Server" class="server" show="true">
Find and kill all the players in the specified team (for example 'killTeam Red').
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
-- Find and kill all the players in a team called "red"
function killTeamFunction ( thePlayer, command, teamName )
redTeam = getTeamFromName ( "red" )
-- Find and kill all the players in the team that was specified with the console command
if ( redTeam ) then
local theTeam = getTeamFromName ( teamName )
  players = getPlayersInTeam ( redTeam )
if ( theTeam ) then
  -- Loop through the player table
local players = getPlayersInTeam ( theTeam )
  for playerKey, playerValue in ipairs(players) do
-- Loop through the player table
    -- kill the player
for playerKey, playerValue in ipairs ( players ) do
    killPlayer ( playerValue )
-- kill the player
  end
killPlayer ( playerValue )
end
end
end
end
addCommandHandler ( "killTeam", killTeamFunction )
</syntaxhighlight>
</section>
<section name="Client" class="client" show="true">
This example will show all players in a team when a player types the 'showTeam TeamName' command.
<syntaxhighlight lang="lua">
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 )
</syntaxhighlight>
</syntaxhighlight>
</section>


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

Latest revision as of 06:46, 12 July 2014

This function retrieves all the players of the specified team.

Syntax

table getPlayersInTeam ( team theTeam )

OOP Syntax Help! I don't understand this!

Method: team:getPlayers(...)
Variable: .players


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 else false if invalid arguments are passed.

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

Shared