GetPlayerCount: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Example 2 doesn't use the getPlayerCount function!)
Line 22: Line 22:
</syntaxhighlight>
</syntaxhighlight>


==Example 2==
<section name="Client" class="client" show="true">
This example command show your FPS.
<syntaxhighlight lang="lua">
local root = getRootElement()
local player = getLocalPlayer()
local counter = 0
local starttick
local currenttick
function fps ()
if not starttick then
starttick = getTickCount()
end
counter = counter + 1
currenttick = getTickCount()
if currenttick - starttick >= 1000 then
outputChatBox ( "Your FPS is: "..counter.."", player)
counter = 0
starttick = false
end
end
function command ()
addEventHandler("onClientRender", root, fps)
setTimer ( stop, 2000, 1)
end
addCommandHandler ( "myfps", command)
function stop ()
removeEventHandler ("onClientRender", root, fps)
end
</syntaxhighlight>
</section>


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

Revision as of 05:52, 17 April 2013

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

[[{{{image}}}|link=|]] 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