-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsv_main.lua
48 lines (38 loc) · 2.13 KB
/
sv_main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
local print = print
local GetCurrentResourceName = GetCurrentResourceName
local GetConvarInt = GetConvarInt
local SetConvar = SetConvar
local startingSlots, slotIncrement, maxSlots = Config.startingSlots, Config.slotIncrement, Config.maxSlots
local defaultSlots = GetConvarInt("sv_playerSlots", 32)
local currentPlayerSlots = defaultSlots
local currentPlayerCount = 0
AddEventHandler("onResourceStart", function(resourceName)
if resourceName ~= GetCurrentResourceName() then return end
if defaultSlots == startingSlots then return end
defaultSlots = startingSlots
currentPlayerSlots = startingSlots
SetConvar("sv_maxClients", startingSlots)
print("The default amount of slots has been changed to " .. startingSlots .. " slots.")
end)
AddEventHandler("playerConnecting", function()
currentPlayerCount = currentPlayerCount + 1
if currentPlayerCount < currentPlayerSlots then return end
currentPlayerSlots = currentPlayerSlots + slotIncrement
if currentPlayerSlots > maxSlots then
currentPlayerSlots = maxSlots
print("The server has reached the maximum amount of slots defined in the configuration file, defaulting to " .. maxSlots .. " slots.")
end
SetConvar("sv_maxClients", currentPlayerSlots)
print("Player slots have been increased to " .. currentPlayerSlots .. " slots from " .. currentPlayerSlots - slotIncrement .. " slots, current player count: " .. currentPlayerCount)
end)
AddEventHandler("playerDropped", function()
currentPlayerCount = currentPlayerCount - 1
if currentPlayerCount > (currentPlayerSlots - slotIncrement) then return end
currentPlayerSlots = currentPlayerSlots - slotIncrement
if currentPlayerSlots < startingSlots then
currentPlayerSlots = startingSlots
print("The server has reached the minimum amount of slots defined in the configuration file, defaulting to " .. startingSlots .. " slots.")
end
SetConvar("sv_maxClients", currentPlayerSlots)
print("Player slots have been decreased to " .. currentPlayerSlots .. " slots from " .. currentPlayerSlots + slotIncrement .. " slots, current player count: " .. currentPlayerCount)
end)