GetMaxPlayers: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(6 intermediate revisions by 3 users not shown)
Line 4: Line 4:


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">int getMaxPlayers (50)</syntaxhighlight>
<syntaxhighlight lang="lua">int getMaxPlayers ()</syntaxhighlight>


===Returns===
===Returns===
Line 11: Line 11:
==Example==
==Example==
This example outputs the current number of players together with the maximum number of players when a player joins.
This example outputs the current number of players together with the maximum number of players when a player joins.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
function showPlayers()
function showPlayers()
local numPlayers = getPlayerCount()    -- get number of currently connected players
outputChatBox("There are "..getPlayerCount().."/"..getMaxPlayers().." players playing.",source) --output a message to the joined player informing the player count and max players.
local maxPlayers = getMaxPlayers(50)    -- get maximum number of players on the server
outputChatBox("There are " .. numPlayers .. "/" .. maxPlayers .. " players playing", source) -- output a message to the joining player
end
end
addEventHandler("onPlayerJoin", getRootElement(), showPlayers) -- add the function as a handler for the "onPlayerJoin" event
addEventHandler("onPlayerJoin",root,showPlayers) --Add an event handler to call the function when a player joins.
</syntaxhighlight>
</syntaxhighlight>


==See Also==
==See Also==
{{Server functions}}
{{Server functions}}

Latest revision as of 18:52, 18 February 2016

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

This example outputs the current number of players together with the maximum number of players when a player joins.

function showPlayers()
	outputChatBox("There are "..getPlayerCount().."/"..getMaxPlayers().." players playing.",source) --output a message to the joined player informing the player count and max players.
end
addEventHandler("onPlayerJoin",root,showPlayers) --Add an event handler to call the function when a player joins.

See Also