GetPlayerCount: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Syntax section)
(Undo revision 27850 by The Kid (talk))
Line 6: Line 6:


==Syntax==
==Syntax==
<section show="true" name="Server" class="server">
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
int getPlayerCount ( )
int getPlayerCount ( )
Line 13: Line 12:
===Returns===
===Returns===
Returns the number of players connected to the server as an [[int]].
Returns the number of players connected to the server as an [[int]].
</section>


==Example==
==Example==
<section show="true" name="Server" class="server">
This example displays a chat message with the number of players connected to the server when a player joins or quits.
This example displays a chat message with the number of players connected to the server when a player joins or quits.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
Line 25: Line 22:
addEventHandler ( "onPlayerQuit", getRootElement(), playerCount )
addEventHandler ( "onPlayerQuit", getRootElement(), playerCount )
</syntaxhighlight>
</syntaxhighlight>
</section>


==See Also==
==See Also==
{{Player functions}}
{{Player functions}}

Revision as of 10:54, 15 November 2011

This function returns the number of players currently connected to the server.

Note: #getElementsByType("player") works the same as this function but also works client side unlike this function.

Syntax

int getPlayerCount ( )

Returns

Returns the number of players connected to the server as an int.

Example

This example displays a chat message with the number of players connected to the server when a player joins or quits.

function playerCount ( )
	outputChatBox ( "There are now " .. getPlayerCount() .. " players on this server!" )
end
addEventHandler ( "onPlayerJoin", getRootElement(), playerCount )
addEventHandler ( "onPlayerQuit", getRootElement(), playerCount )

See Also