SetMaxPlayers: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
m (Needs Checking: Example Wrong)
(new stupid example (:)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Needs Checking|Example wrong. Can't increase slots since the maximum you can set is what is defined in the mtaserver.conf. --[[User:OpenIDUser28|Sniper]] 23:48, 3 September 2011 (CEST)}}
{{Server function}}
{{Server function}}
This function set the maximum number of player slots on the server. Note: the maximum this function can set is what is defined in mtaserver.conf
This function set the maximum number of player slots on the server. Note: the maximum this function can set is what is defined in mtaserver.conf
Line 16: Line 15:


==Example==
==Example==
This example increases server slots count if server is full.
This example set server slots count to half value from current value.
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
addEventHandler( "onPlayerJoin", root,
local curMaxPlayers = getMaxPlayers()
    function()
local newMaxPlayers = math.ceil( curMaxPlayers / 2 )
        local nowPlayers = getPlayerCount()
        local maxPlayers = getMaxPlayers()


        if nowPlayers and maxPlayers and nowPlayers >= maxPlayers then
setMaxPlayers( newMaxPlayers )
            setMaxPlayers( maxPlayers + 1 )
</syntaxhighlight>
        end
    end
)</syntaxhighlight>


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

Revision as of 05:29, 4 September 2011

This function set the maximum number of player slots on the server. Note: the maximum this function can set is what is defined in mtaserver.conf

Syntax

bool setMaxPlayers ( int slots )

Required Arguments

  • slots: Maximum number of player slots on the server.

Returns

Returns true if number of player slots was successfully changed, false or nil otherwise.

Example

This example set server slots count to half value from current value.

local curMaxPlayers = getMaxPlayers()
local newMaxPlayers = math.ceil( curMaxPlayers / 2 )

setMaxPlayers( newMaxPlayers )

See Also