Player Queue System
Player Queue
Using the gameserver
module, you can create a player queue system.
By default, HolyLib will stop any player from spawning if there is no player slot below 128 available.
This is because any player slot above 128 is utterly unstable.
to solve this, any player using a slot above 128 is moved into an empty slot that is below 128, if none is available they won't be allowed to spawn.
Example code
playerQueue = playerQueue
or {
count = 0
}
hook.
Add(
"HolyLib:OnSetSignonState",
"Example",
function(cl, state, c)
print(cl, state, c)
local maxSlots = 128
local fullServer = player.GetCount() >= maxSlots
if fullServer
and state == SIGNONSTATE_PRESPAWN
then if not playerQueue[cl]
then
playerQueue[cl] =
true
playerQueue.count = playerQueue.count + 1
playerQueue[playerQueue.count] = cl
end
return true end
end)
hook.
Add(
"HolyLib:OnClientDisconnect",
"Example",
function(client)
timer.
Simple(0,
function()
if playerQueue.count <= 0
then return end
if client:
IsValid()
then
print(
"Client isn't empty?!? client: " .. client)
return
end
local nextPlayer = playerQueue[1]
playerQueue[nextPlayer] =
nil
table.
remove(playerQueue, 1)
playerQueue.count = playerQueue.count - 1
nextPlayer:SpawnPlayer()
end)
end)
hook.
Add(
"HolyLib:OnPlayerChangedSlot",
"Example",
function(oldPlayerSlot, newPlayerSlot)
print(
"Client was moved from slot " .. oldPlayerSlot ..
" to slot " .. newPlayerSlot)
end)