2014-08-04 12:12:15 +00:00
|
|
|
// vim: set ts=4 sw=4 tw=99 noet:
|
|
|
|
//
|
|
|
|
// AMX Mod X, based on AMX Mod by Aleksander Naszko ("OLO").
|
|
|
|
// Copyright (C) The AMX Mod X Development Team.
|
|
|
|
//
|
|
|
|
// This software is licensed under the GNU General Public License, version 3 or higher.
|
|
|
|
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
|
|
|
// https://alliedmods.net/amxmodx-license
|
|
|
|
|
|
|
|
//
|
|
|
|
// Slots Reservation Plugin
|
|
|
|
//
|
2004-01-31 20:56:22 +00:00
|
|
|
|
2004-03-05 19:35:38 +00:00
|
|
|
#include <amxmodx>
|
2004-03-07 14:30:53 +00:00
|
|
|
#include <amxmisc>
|
2004-01-31 20:56:22 +00:00
|
|
|
|
2020-06-03 21:52:47 +00:00
|
|
|
new CvarReservation;
|
|
|
|
new CvarHideSlots;
|
|
|
|
|
|
|
|
new CvarHandleMaxVisiblePlayers;
|
2004-01-31 20:56:22 +00:00
|
|
|
|
2005-09-12 21:06:24 +00:00
|
|
|
public plugin_init()
|
|
|
|
{
|
2020-06-03 21:52:47 +00:00
|
|
|
register_plugin("Slots Reservation", AMXX_VERSION_STR, "AMXX Dev Team");
|
|
|
|
|
|
|
|
register_dictionary("adminslots.txt");
|
|
|
|
register_dictionary("common.txt");
|
|
|
|
|
|
|
|
hook_cvar_change(create_cvar("amx_reservation", "0", FCVAR_PROTECTED, fmt("%L", LANG_SERVER, "CVAR_RESERVATION"), .has_min = true, .min_val = 0.0, .has_max = true, .max_val = float(MaxClients - 1)), "@OnReservationChange");
|
|
|
|
hook_cvar_change(create_cvar("amx_hideslots" , "0", FCVAR_NONE , fmt("%L", LANG_SERVER, "CVAR_HIDESLOTS") , .has_min = true, .min_val = 0.0, .has_max = true, .max_val = 1.0), "@OnHideSlotsChange");
|
|
|
|
|
|
|
|
CvarHandleMaxVisiblePlayers = get_cvar_pointer("sv_visiblemaxplayers");
|
2006-02-27 09:22:03 +00:00
|
|
|
}
|
2004-03-27 22:13:41 +00:00
|
|
|
|
2020-06-03 21:52:47 +00:00
|
|
|
@OnReservationChange(const handle, const oldValue[], const newValue[])
|
2006-09-01 01:40:37 +00:00
|
|
|
{
|
2020-06-03 21:52:47 +00:00
|
|
|
CvarReservation = strtol(newValue);
|
|
|
|
|
|
|
|
setVisibleSlots();
|
2006-09-01 01:40:37 +00:00
|
|
|
}
|
|
|
|
|
2020-06-03 21:52:47 +00:00
|
|
|
@OnHideSlotsChange(const handle, const oldValue[], const newValue[])
|
2006-02-27 09:22:03 +00:00
|
|
|
{
|
2020-06-03 21:52:47 +00:00
|
|
|
CvarHideSlots = strtol(newValue);
|
|
|
|
|
|
|
|
setVisibleSlots();
|
2004-08-03 20:11:16 +00:00
|
|
|
}
|
2004-01-31 20:56:22 +00:00
|
|
|
|
2006-03-19 21:25:18 +00:00
|
|
|
public client_authorized(id)
|
|
|
|
{
|
2020-06-03 21:52:47 +00:00
|
|
|
setVisibleSlots(id);
|
2006-03-19 21:25:18 +00:00
|
|
|
}
|
|
|
|
|
2017-02-25 10:50:52 +00:00
|
|
|
public client_remove(id)
|
2006-03-19 21:25:18 +00:00
|
|
|
{
|
2020-06-03 21:52:47 +00:00
|
|
|
setVisibleSlots();
|
|
|
|
}
|
|
|
|
|
|
|
|
setVisibleSlots(const playerId = 0)
|
|
|
|
{
|
|
|
|
if ((playerId == 0 && !CvarHideSlots) || !CvarReservation)
|
|
|
|
{
|
|
|
|
if (get_pcvar_num(CvarHandleMaxVisiblePlayers) > 0)
|
|
|
|
{
|
|
|
|
resetVisibleSlots(MaxClients);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
new const playersCount = get_playersnum_ex(GetPlayers_IncludeConnecting);
|
|
|
|
new const freeVisibleSlots = MaxClients - CvarReservation;
|
|
|
|
|
|
|
|
if (playerId != 0)
|
2013-08-05 16:26:57 +00:00
|
|
|
{
|
2020-06-03 21:52:47 +00:00
|
|
|
if (playersCount > freeVisibleSlots && !access(playerId, ADMIN_RESERVATION))
|
|
|
|
{
|
|
|
|
server_cmd("kick #%d ^"%L^"", get_user_userid(playerId), playerId, "DROPPED_RES");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!CvarHideSlots)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2013-08-05 16:26:57 +00:00
|
|
|
}
|
2020-06-03 21:52:47 +00:00
|
|
|
|
|
|
|
new maxVisiblePlayers = playersCount + 1;
|
|
|
|
|
|
|
|
if (playersCount == MaxClients)
|
|
|
|
{
|
|
|
|
maxVisiblePlayers = MaxClients;
|
|
|
|
}
|
|
|
|
else if (playersCount < freeVisibleSlots)
|
|
|
|
{
|
|
|
|
maxVisiblePlayers = freeVisibleSlots;
|
|
|
|
}
|
|
|
|
|
|
|
|
resetVisibleSlots(maxVisiblePlayers);
|
2006-03-19 21:25:18 +00:00
|
|
|
}
|
|
|
|
|
2020-06-03 21:52:47 +00:00
|
|
|
resetVisibleSlots(value)
|
2006-03-19 21:25:18 +00:00
|
|
|
{
|
2020-06-03 21:52:47 +00:00
|
|
|
if (value == MaxClients)
|
|
|
|
{
|
|
|
|
value = -1; // Default sv_visiblemaxplayers value.
|
|
|
|
}
|
|
|
|
|
|
|
|
set_pcvar_num(CvarHandleMaxVisiblePlayers, value);
|
2006-03-19 21:25:18 +00:00
|
|
|
}
|