GetPlayersInTeam

From Multi Theft Auto: Wiki
Revision as of 23:45, 16 July 2013 by Jaysds1 (talk | contribs) (→‎Returns: Reason for it to return false.)
Jump to navigation Jump to search

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 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