GetPlayerCount: Difference between revisions
Jump to navigation
Jump to search
UniOnDennis (talk | contribs) |
No edit summary |
||
Line 3: | Line 3: | ||
This function returns the number of players currently connected to the server. | 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.}} | {{Note|#getElementsByType("player") works the same as this function but also works client side unlike this function.}} | ||
==Syntax== | ==Syntax== | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> |
Revision as of 22:25, 30 June 2013
This function returns the number of players currently connected to the server.
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 )
Clientside Example (Doesn't user getPlayerCount!)
This example uses the getElementsByType function to display the player count, same result but also works clientside!
Click to collapse [-]
ClientaddEventHandler( "playercount", function () outputChatBox ( "There are now " .. #getElementsByType( "player" ) .. " players on this server!" ) end )
See Also
- getPlayerTeam
- getPlayerBlurLevel
- setPlayerBlurLevel
- getPlayerSerial
- forcePlayerMap
- getPlayerScriptDebugLevel
- getPlayerFromName
- getPlayerMoney
- getPlayerName
- getPlayerNametagColor
- getPlayerNametagText
- getPlayerPing
- getPlayerWantedLevel
- givePlayerMoney
- isPlayerMapForced
- isPlayerNametagShowing
- setPlayerHudComponentVisible
- setPlayerMoney
- setPlayerNametagColor
- setPlayerNametagShowing
- setPlayerNametagText
- takePlayerMoney
- countPlayersInTeam
- getPlayersInTeam
- isVoiceEnabled
- setControlState
- getControlState