2016-12-15 20:40:07 +08:00
|
|
|
local playerCount = 0
|
|
|
|
local list = {}
|
|
|
|
|
|
|
|
RegisterServerEvent('hardcap:playerActivated')
|
|
|
|
|
|
|
|
AddEventHandler('hardcap:playerActivated', function()
|
|
|
|
if not list[source] then
|
|
|
|
playerCount = playerCount + 1
|
|
|
|
list[source] = true
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
AddEventHandler('playerDropped', function()
|
|
|
|
if list[source] then
|
|
|
|
playerCount = playerCount - 1
|
|
|
|
list[source] = nil
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
AddEventHandler('playerConnecting', function(name, setReason)
|
2017-06-14 18:54:25 +08:00
|
|
|
local cv = GetConvarInt('sv_maxclients', 32)
|
|
|
|
|
2016-12-15 20:40:07 +08:00
|
|
|
print('Connecting: ' .. name)
|
|
|
|
|
2017-06-14 18:54:25 +08:00
|
|
|
if playerCount >= cv then
|
2016-12-15 20:40:07 +08:00
|
|
|
print('Full. :(')
|
|
|
|
|
2017-06-14 18:54:25 +08:00
|
|
|
setReason('This server is full (past ' .. tostring(cv) .. ' players).')
|
2016-12-15 20:40:07 +08:00
|
|
|
CancelEvent()
|
|
|
|
end
|
|
|
|
end)
|