GetMaxPlayers: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 14: | Line 14: | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
function showPlayers() | function showPlayers() | ||
local | local numPlayers = getPlayerCount() -- get number of currently connected players | ||
local | local maxPlayers = getMaxPlayers() -- get maximum number of players on the server | ||
outputChatBox("There are ".. | outputChatBox("There are " .. numPlayers .. "/" .. maxPlayers .. " players playing", source) -- output a message to the joining player | ||
end | end | ||
addEventHandler("onPlayerJoin",getRootElement(),showPlayers) -- add the | addEventHandler("onPlayerJoin", getRootElement(), showPlayers) -- add the function as a handler for the "onPlayerJoin" event | ||
</syntaxhighlight> </section> | </syntaxhighlight> | ||
</section> | |||
==See Also== | ==See Also== | ||
{{Server functions}} | {{Server functions}} |
Revision as of 18:04, 19 August 2007
This function returns the maximum number of player slots on the server.
Syntax
int getMaxPlayers ()
Returns
Returns the maximum number of players allowed on the server.
Example
Click to collapse [-]
ServerThis example outputs the current number of players together with the maximum number of players when a player joins.
function showPlayers() local numPlayers = getPlayerCount() -- get number of currently connected players local maxPlayers = getMaxPlayers() -- get maximum number of players on the server outputChatBox("There are " .. numPlayers .. "/" .. maxPlayers .. " players playing", source) -- output a message to the joining player end addEventHandler("onPlayerJoin", getRootElement(), showPlayers) -- add the function as a handler for the "onPlayerJoin" event
See Also
- getMaxPlayers
- getServerConfigSetting
- getServerHttpPort
- getServerName
- getServerPassword
- getServerPort
- isGlitchEnabled
- setGlitchEnabled
- setMaxPlayers
- setServerConfigSetting
- setServerPassword
- shutdown