CountPlayersInTeam: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 1: Line 1:
__NOTOC__  
__NOTOC__  
{{Server client function}}
This function is for returning the number of players in the specified team.
This function is for returning the number of players in the specified team.


Line 14: Line 15:


==Example==
==Example==
'''Example 1:''' This example adds a command in the console to find out how many players are on your team.
<section name="Example 1" class="server">
This example adds a command in the console to find out how many players are on your team.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function outputTeamSize ( source, commandName )
function outputTeamSize ( source, commandName )
Line 29: Line 31:
addCommandHandler ( "teamsize", outputTeamSize )
addCommandHandler ( "teamsize", outputTeamSize )
</syntaxhighlight>
</syntaxhighlight>
'''Example 2:''' This example balances a gamemode, to ensure equal number of players between the "grove" and "ballas" teams.  This could be triggered when a player joins the server, or for all players currently in the server when the gamemode starts.
</section>
<section name="Example 2" class="client">
This example adds a command in the console to find out how many players are on your team, clientside
<syntaxhighlight lang="lua">
function outputTeamSize ( commandName )
-- Get player's team
local theTeam = getPlayerTeam ( getLocalPlayer() )
-- If the player is in any team
if team then
-- Tell the player how big his team is
outputChatBox ( "Your team has " .. countPlayersInTeam ( theTeam ) .. " players." )
else
outputChatBox ( "You're not in a team." )
end
end
addCommandHandler ( "teamsize", outputTeamSize )
</syntaxhighlight>
</section>
<section name="Example 3" class="server">
This example balances a gamemode, to ensure equal number of players between the "grove" and "ballas" teams.  This could be triggered when a player joins the server, or for all players currently in the server when the gamemode starts.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function balanceTeams ( thePlayer )
function balanceTeams ( thePlayer )
Line 46: Line 67:
end
end
end</syntaxhighlight>
end</syntaxhighlight>
</section>
==See Also==
==See Also==
{{Team functions}}
{{Team functions}}

Revision as of 16:23, 15 August 2007

This function is for returning the number of players in the specified team.

Syntax

int countPlayersInTeam ( team theTeam )

Optional Arguments

  • theTeam: The team you wish to retrieve the player count of.

Returns

Returns an integer containing the number of players in the team, false if it could not be retrived.

Example

Click to expand [+]
Example 1
Click to expand [+]
Example 2
Click to expand [+]
Example 3

See Also