GetPlayerCount: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
{{Server function}}
__NOTOC__
__NOTOC__
This function returns the number of players currently connected to the server.
This function returns the number of players currently connected to the server.
Line 4: Line 5:
==Syntax==
==Syntax==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
int getPlayerCount ()
int getPlayerCount ( )
</syntaxhighlight>
</syntaxhighlight>


Line 13: Line 14:
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">
function playerCount()
function playerCount ( )
outputChatBox("There are now "..getPlayerCount().." players on this server!")
outputChatBox ( "There are now " .. getPlayerCount() .. " players on this server!" )
end
end
addEventHandler("onPlayerJoin",getRootElement(),playerCount)
addEventHandler ( "onPlayerJoin", getRootElement(), playerCount )
addEventHandler("onPlayerQuit",getRootElement(),playerCount)
addEventHandler ( "onPlayerQuit", getRootElement(), playerCount )
</syntaxhighlight>
</syntaxhighlight>


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

Revision as of 16:00, 19 August 2007

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 )

See Also