GetMaxPlayers: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 9: Line 9:


==Example==
==Example==
This example gets the maximum number of players for the server and outputs it as part of a message in the chat box.
This example outputs the current number of players together with the maximum number of players when a player joins.
<syntaxhighlight lang="lua">playermax = getMaxPlayers ()
<syntaxhighlight lang="lua">
outputChatBox ( "There are currently " .. playermax .. " player slots in this server." )</syntaxhighlight>
function showPlayers()
local maxPlayers = getMaxPlayers() -- get maximum number of players on the server
local players = getElementsByType("player") -- get a table of all current players
outputChatBox("There are "..#players.."/"..maxPlayers.." players playing",source) -- output a message to the joining player
end
addEventHandler("onPlayerJoin",getRootElement(),showPlayers) -- add the Event for "onPlayerJoin" that will call the "showPlayers" function
</syntaxhighlight>


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

Revision as of 20:37, 28 July 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

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

function showPlayers()
	local maxPlayers = getMaxPlayers() -- get maximum number of players on the server
	local players = getElementsByType("player") -- get a table of all current players
	outputChatBox("There are "..#players.."/"..maxPlayers.." players playing",source) -- output a message to the joining player
end
addEventHandler("onPlayerJoin",getRootElement(),showPlayers) -- add the Event for "onPlayerJoin" that will call the "showPlayers" function

See Also