A stripped down version of HolyLib's gameserver module to allow for a queue system.
This is the Lua API that is provided.
Returns the CGameClient at that player slot or nil
on failure.
Returns a table that contains all game clients. It will return nil
on failure.
This class represents a client.
Internally implemented and will set the values into the lua table.
Internally seaches first in the metatable table for the key.
If it fails to find it, it will search in the lua table before returning.
If you try to get multiple values from the lua table, just use CBaseClient:GetTable()
.
Returns the lua table of this object.
You can store variables into it.
Returns the slot of the client. Use this for sourcetv.GetClient
.
Returns the userid of the client.
Returns the name of the client.
Returns the steamid of the client.
Reconnects the client.
Prints the given message into the client's console.
Note
It won't add \n
to the end, you have to add it yourself.
Returns true
if the client is still valid.
Disconnects the client.
Sets the SignOnState for the given client.
Returns true
on success.
Note
This function does normally not directly set the SignOnState.
Instead it calls the responsible function for the given SignOnState like for SIGNONSTATE_PRESPAWN
it will call SpawnPlayer
on the client.
Set the rawSet
to true
if you want to directly set the SignOnState.
Note
This function was formerly known as HolyLib.SetSignOnState
This class inherits CBaseClient.
Returns the a formated string.
Format: CGameClient [%i][%s]
%i
-> UserID
%s
-> ClientName
Called when the engine is about to change the client's SignonState.
Return true
to stop the engine.
Called after a player was moved to a different slot.
This happens when a player on a player slot above 128 tries to spawn.
Why is this done? Because any player above 128 is utterly unstable and can only stabily exist as a CGameClient.
if a CBasePlayer entity is created on a slot above 128 expect stability issues!
Called when a client disconnects.
Using this module's functionality you can implement a player queue were players wait in the loading screen until they spawn when a slot gets free.
Example implementation:
playerQueue = playerQueue or {
count = 0
}
hook.Add("PlayerQueue:OnSetSignonState", "Example", function(cl, state, c)
print(cl, state, c)
local fullServer = #player.GetAll() >= 128 -- Can't exceed 128 players.
if fullServer and state == SIGNONSTATE_PRESPAWN then -- REQUIRED to be SIGNONSTATE_PRESPAWN
if not playerQueue[cl] then
playerQueue[cl] = true
playerQueue.count = playerQueue.count + 1
playerQueue[playerQueue.count] = cl
end
return true -- Stop the engine from continuing/spawning the player
end
end)
hook.Add("PlayerQueue:OnClientDisconnect", "Example", function(client)
timer.Simple(0, function() -- Just to be sure that the client was really disconnected.
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() -- Spawn the client, HolyLib handles the moving of the client.
end)
end)
hook.Add("PlayerQueue:OnPlayerChangedSlot", "Example", function(oldPlayerSlot, newPlayerSlot)
print("Client was moved from slot " .. oldPlayerSlot .. " to slot " .. newPlayerSlot)
end)