GetPlayerCount: Difference between revisions
Jump to navigation
Jump to search
Line 31: | Line 31: | ||
local starttick | local starttick | ||
local currenttick | local currenttick | ||
function() | function fps () | ||
if not starttick then | if not starttick then | ||
starttick = getTickCount() | starttick = getTickCount() | ||
Line 39: | Line 39: | ||
currenttick = getTickCount() | currenttick = getTickCount() | ||
if currenttick - starttick >= 1000 then | if currenttick - starttick >= 1000 then | ||
outputChatBox ( "Your FPS is: "..counter.."", player) | |||
counter = 0 | counter = 0 | ||
starttick = false | starttick = false | ||
end | end | ||
end | end | ||
) | |||
function command () | |||
addEventHandler("onClientRender", root, fps) | |||
setTimer ( stop, 2000, 1) | |||
end | |||
addCommandHandler ( "myfps", command) | |||
function stop () | |||
removeEventHandler ("onClientRender", root, fps) | |||
end | |||
</syntaxhighlight> | </syntaxhighlight> | ||
</section> | </section> |
Revision as of 01:12, 17 April 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 )
Example 2
Click to collapse [-]
ClientThis example command show your FPS.
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
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