Posting this on behalf of my friend who can't at the moment:
[quote]My friend is setting up an RP server, and he wants a script that reserves server slots: If someone that didn't buy a reserved slot join the server, in what would be a reserved slot, he gets automatically kicked. For instance: A server has 13 slots, one of them is reserved, and there's 12/13 players connected on it. If a player joins the server and his steam ID doesn't match the reserved slot buyer's Steam ID, he gets automatically kicked.[/quote]
So, I guess he wants a script that enables that option of automatically kicking people that don't have a matching Steam ID to the slot that was currently reserved (bought, somehow). Maybe something where they put that player's Steam ID on the script and now he can join the server with no problems if it's full or something.
I'm sure you could make a table of allowed SteamID's and check in the PlayerAuth hook
[lua]local Allowed = {"STEAM_0:0:3556565","STEAM_0:0:3556565","STEAM_0:0:3556565","STEAM_0:0:3556565"}
hook.Add("PlayerAuthed",function (ply, sid, uid)
if #player.GetAll() >= 12 then
if (table.HasValue(Allowed, ply:SteamID())) or (ply:IsAdmin()) then
return true
else
ply:Kick("You Are Trying To Join A Reserved Slot - Please Wait Till A Free Slot Is Open")
end
end
end)
[/lua]
[code]if SinglePlayer( ) or MaxPlayers( ) == 1 or CLIENT then
return
end
require( "gatekeeper" )
local RESERVED_SLOTS = 5 --How many reserved slots there are
local RESERVED_IDS = { } --Don't mess with this
local MAX_PLAYERS = 1 --No point in changing this as the server does it once it starts
local ALLOW_FORCE_OPEN = true --Set this to true to force kick a person if the server is full ( for real )
local KICK_MESSAGE = "Sorry, no open public slots" --Message to kick people with
local EJECT_MESSAGE = "Sorry, you were kicked to make space for a VIP" --Message to give people who are kicked by the script ( if ALLOW_FORCE_OPEN is true )
local FAIL_MESSAGE = "Sorry, there were no non-vip clients to kick" --Message to give vips who can't fit in the server
function AddReservedID( id )
table.insert( RESERVED_IDS, id )
end
local function Think( )
MAX_PLAYERS = MaxPlayers( ) - RESERVED_SLOTS
game.ConsoleCommand( string.format( "sv_visiblemaxplayers %d\n", MAX_PLAYERS ) )
--Doing this in Initialize or InitPostEntity seemed to throw off the value. MaxPlayers would return 6 regardless of what sv_maxplayers happened to be when the game started.
--This, although a little out there, fixes that problem
hook.Remove( "Think", "Reserved Slots.Think" )
end
local function ccSlots( pl, _, args )
if not pl:IsAdmin( ) then return end
MAX_PLAYERS = math.Clamp( tonumber( args[ 1 ] ) or MaxPlayers( ) - RESERVED_SLOTS, 1, MaxPlayers( ) )
game.ConsoleCommand( string.format( "sv_visiblemaxplayers %d\n", MAX_PLAYERS ) )
end
local function PlayerPasswordAuth( pl, password, id, ip )
local i, k, v, fair
i = 0
fair = { }
for k, v in ipairs( player.GetAll( ) ) do
if not table.HasValue( RESERVED_IDS, v:SteamID( ) ) then
--If the player doesn't exist in the reservation list, they take up a player slot
i = i + 1
table.insert( fair, v )
end
end
if ALLOW_FORCE_OPEN then
if #player.GetAll( ) == MaxPlayers( ) then
--Server is full, can we open a slot?
if i == 0 then
return { false, FAIL_MESSAGE }
end
k = table.Random( fair )
PrintMessage( HUD_PRINTTALK, string.format( "%s was kicked to make room for %s", k:Nick( ), pl ) )
gatekeeper.Drop( k:UserID( ), EJECT_MESSAGE )
return nil
end
end
if i >= MAX_PLAYERS and not table.HasValue( RESERVED_IDS, id ) then
return { false, KICK_MESSAGE }
end
end
hook.Add( "Think", "Reserved Slots.Think", Think )
hook.Add( "PlayerPasswordAuth", "Reserved Slots.PlayerPasswordAuth", PlayerPasswordAuth )
concommand.Add( "?openslots", ccSlots )
--Add reserved steam ids here
--Example: AddReservedID( "STEAM:0:555555" )[/code]
You'll need to install gmsv_gatekeeper for it.
Wow, thank you very much, Kogitsune! You're a true genius.
Sending it to my friend right now.
Sorry, you need to Log In to post a reply to this thread.