GetMaxPlayers: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
Line 14: Line 14:
function showPlayers()
function showPlayers()
local numPlayers = getPlayerCount()    -- get number of currently connected players
local numPlayers = getPlayerCount()    -- get number of currently connected players
local maxPlayers = getMaxPlayers()    -- get maximum number of players on the server
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
outputChatBox("There are " .. numPlayers .. "/" .. maxPlayers .. " players playing", source) -- output a message to the joining player
end
end

Revision as of 11:13, 16 December 2014

This function returns the maximum number of player slots on the server.

Syntax

int getMaxPlayers (50)

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()
	local numPlayers = getPlayerCount()    -- get number of currently connected 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
addEventHandler("onPlayerJoin", getRootElement(), showPlayers) -- add the function as a handler for the "onPlayerJoin" event

See Also