GetPlayerCount: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 11: Line 11:


==Example==
==Example==
This example displays a chat message with the number of players connected to the server.
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">
-- Retrieve the number of players connected to the server and store the number in the playercount variable
function playerCount()
playercount = getPlayerCount ()
outputChatBox("There are now "..getPlayerCount().." players on this server!")
-- Display a chat message informing everyone on the server how many people are playing.
end
outputChatBox ( "There are currently ", playercount, " players playing in the server" )
addEventHandler("onPlayerJoin",getRootElement(),playerCount)
addEventHandler("onPlayerQuit",getRootElement(),playerCount)
</syntaxhighlight>
</syntaxhighlight>


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

Revision as of 22:08, 29 July 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