2014-08-04 16:12:15 +04: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 23:56:22 +03:00
|
|
|
|
2004-03-05 22:35:38 +03:00
|
|
|
#include <amxmodx>
|
2004-03-07 17:30:53 +03:00
|
|
|
#include <amxmisc>
|
2004-01-31 23:56:22 +03:00
|
|
|
|
2020-06-04 00:52:47 +03:00
|
|
|
new CvarReservation;
|
|
|
|
new CvarHideSlots;
|
|
|
|
|
|
|
|
new CvarHandleMaxVisiblePlayers;
|
2004-01-31 23:56:22 +03:00
|
|
|
|
2005-09-13 01:06:24 +04:00
|
|
|
public plugin_init()
|
|
|
|
{
|
2020-06-04 00:52:47 +03: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 12:22:03 +03:00
|
|
|
}
|
2004-03-28 01:13:41 +03:00
|
|
|
|
2020-06-04 00:52:47 +03:00
|
|
|
@OnReservationChange(const handle, const oldValue[], const newValue[])
|
2006-09-01 05:40:37 +04:00
|
|
|
{
|
2020-06-04 00:52:47 +03:00
|
|
|
CvarReservation = strtol(newValue);
|
|
|
|
|
|
|
|
setVisibleSlots();
|
2006-09-01 05:40:37 +04:00
|
|
|
}
|
|
|
|
|
2020-06-04 00:52:47 +03:00
|
|
|
@OnHideSlotsChange(const handle, const oldValue[], const newValue[])
|
2006-02-27 12:22:03 +03:00
|
|
|
{
|
2020-06-04 00:52:47 +03:00
|
|
|
CvarHideSlots = strtol(newValue);
|
|
|
|
|
|
|
|
setVisibleSlots();
|
2004-08-04 00:11:16 +04:00
|
|
|
}
|
2004-01-31 23:56:22 +03:00
|
|
|
|
2006-03-20 00:25:18 +03:00
|
|
|
public client_authorized(id)
|
|
|
|
{
|
2020-06-04 00:52:47 +03:00
|
|
|
setVisibleSlots(id);
|
2006-03-20 00:25:18 +03:00
|
|
|
}
|
|
|
|
|
2017-02-25 13:50:52 +03:00
|
|
|
public client_remove(id)
|
2006-03-20 00:25:18 +03:00
|
|
|
{
|
2020-06-04 00:52:47 +03: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 20:26:57 +04:00
|
|
|
{
|
2020-06-04 00:52:47 +03: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 20:26:57 +04:00
|
|
|
}
|
2020-06-04 00:52:47 +03:00
|
|
|
|
|
|
|
new maxVisiblePlayers = playersCount + 1;
|
|
|
|
|
|
|
|
if (playersCount == MaxClients)
|
|
|
|
{
|
|
|
|
maxVisiblePlayers = MaxClients;
|
|
|
|
}
|
|
|
|
else if (playersCount < freeVisibleSlots)
|
|
|
|
{
|
|
|
|
maxVisiblePlayers = freeVisibleSlots;
|
|
|
|
}
|
|
|
|
|
|
|
|
resetVisibleSlots(maxVisiblePlayers);
|
2006-03-20 00:25:18 +03:00
|
|
|
}
|
|
|
|
|
2020-06-04 00:52:47 +03:00
|
|
|
resetVisibleSlots(value)
|
2006-03-20 00:25:18 +03:00
|
|
|
{
|
2020-06-04 00:52:47 +03:00
|
|
|
if (value == MaxClients)
|
|
|
|
{
|
|
|
|
value = -1; // Default sv_visiblemaxplayers value.
|
|
|
|
}
|
|
|
|
|
|
|
|
set_pcvar_num(CvarHandleMaxVisiblePlayers, value);
|
2006-03-20 00:25:18 +03:00
|
|
|
}
|