/*
* CSB Weapon Restrict
* Copyright (C) 2026 counter-strike-boost.com
*
* Blocks selected weapons and equipment from being bought. The plugin hooks the
* direct buy alias commands (ak47, awp, hegren, vesthelm, ...) and returns
* PLUGIN_HANDLED for anything restricted, telling the player why. Admins can
* toggle restrictions live from a menu, and a per-map config is executed on map
* start.
*
* Inspired by the AMX Mod X "Restrict Weapons" plugin. This is an independent
* GPL re-implementation; no original code is reused.
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version. It is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See <https://www.gnu.org/licenses/> for details.
*/
#include <amxmodx>
#include <amxmisc>
new const PLUGIN[] = "CSB Weapon Restrict"
new const VERSION[] = "1.0.0"
new const AUTHOR[] = "counter-strike-boost.com"
/* Every buyable thing: the console command the client sends, plus a label. */
new const g_szAlias[][] =
{
"usp", "glock", "deagle", "p228", "elite", "fn57",
"galil", "ak47", "scout", "sg552", "awp", "g3sg1",
"famas", "m4a1", "aug", "sg550",
"m3", "xm1014",
"mac10", "tmp", "mp5", "ump45", "p90",
"m249",
"hegren", "flash", "sgren",
"vest", "vesthelm", "defuser", "nvgs"
}
new const g_szLabel[][] =
{
"USP", "Glock", "Desert Eagle", "P228", "Dual Elites", "Five-SeveN",
"Galil", "AK-47", "Scout", "SG-552", "AWP", "G3SG1",
"FAMAS", "M4A1", "AUG", "SG-550",
"M3 Super 90", "XM1014",
"MAC-10", "TMP", "MP5", "UMP-45", "P90",
"M249 Para",
"HE Grenade", "Flashbang", "Smoke Grenade",
"Kevlar", "Kevlar+Helmet", "Defuse Kit", "Night Vision"
}
new bool:g_bRestricted[sizeof(g_szAlias)]
new g_pEnabled
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
g_pEnabled = register_cvar("csb_restrict_enabled", "1")
for (new i = 0; i < sizeof(g_szAlias); i++)
register_clcmd(g_szAlias[i], "cmdBuy")
register_clcmd("say /restrictmenu", "cmdMenu", ADMIN_CVAR)
register_clcmd("say_team /restrictmenu", "cmdMenu", ADMIN_CVAR)
register_concmd("amx_restrict", "cmdRestrict", ADMIN_CVAR, "<alias> - restrict a weapon/equipment")
register_concmd("amx_unrestrict", "cmdUnrestrict", ADMIN_CVAR, "<alias> - allow a weapon/equipment again")
register_concmd("amx_restrictlist", "cmdList", ADMIN_CVAR, "- list currently restricted items")
}
public plugin_cfg()
{
/* Per-map override: configs/csb_restrict/<map>.cfg */
new mapname[32], configsDir[128], path[192]
get_mapname(mapname, charsmax(mapname))
get_configsdir(configsDir, charsmax(configsDir))
formatex(path, charsmax(path), "%s/csb_restrict/%s.cfg", configsDir, mapname)
if (file_exists(path))
server_cmd("exec %s", path)
}
findAlias(const alias[])
{
for (new i = 0; i < sizeof(g_szAlias); i++)
{
if (equali(alias, g_szAlias[i]))
return i
}
return -1
}
public cmdBuy(id)
{
if (!get_pcvar_num(g_pEnabled))
return PLUGIN_CONTINUE
new cmd[24]
read_argv(0, cmd, charsmax(cmd))
new idx = findAlias(cmd)
if (idx == -1 || !g_bRestricted[idx])
return PLUGIN_CONTINUE
client_print(id, print_center, "%s is restricted on this server", g_szLabel[idx])
client_print(id, print_chat, "[CSB] %s is restricted and cannot be bought.", g_szLabel[idx])
return PLUGIN_HANDLED
}
public cmdMenu(id)
{
new menu = menu_create("\yCSB Weapon Restrict^n\wClick to toggle", "menuHandler")
new info[8], line[64]
for (new i = 0; i < sizeof(g_szAlias); i++)
{
num_to_str(i, info, charsmax(info))
formatex(line, charsmax(line), "%s %s", g_bRestricted[i] ? "\r[BLOCKED]\w" : "\d[ allowed ]\w", g_szLabel[i])
menu_additem(menu, line, info)
}
menu_setprop(menu, MPROP_EXITNAME, "Close")
menu_setprop(menu, MPROP_PERPAGE, 7)
menu_display(id, menu)
return PLUGIN_HANDLED
}
public menuHandler(id, menu, item)
{
if (item == MENU_EXIT)
{
menu_destroy(menu)
return PLUGIN_HANDLED
}
new info[8], name[32], access, callback
menu_item_getinfo(menu, item, access, info, charsmax(info), name, charsmax(name), callback)
menu_destroy(menu)
new idx = str_to_num(info)
if (idx < 0 || idx >= sizeof(g_szAlias))
return PLUGIN_HANDLED
g_bRestricted[idx] = !g_bRestricted[idx]
new aname[32]
get_user_name(id, aname, charsmax(aname))
log_amx("[CSB Restrict] %s set %s to %s", aname, g_szLabel[idx], g_bRestricted[idx] ? "BLOCKED" : "allowed")
client_print(id, print_chat, "[CSB] %s is now %s.", g_szLabel[idx], g_bRestricted[idx] ? "restricted" : "allowed")
cmdMenu(id)
return PLUGIN_HANDLED
}
public cmdRestrict(id, level, cid)
{
if (!cmd_access(id, level, cid, 2))
return PLUGIN_HANDLED
new alias[24]
read_argv(1, alias, charsmax(alias))
new idx = findAlias(alias)
if (idx == -1)
{
console_print(id, "[CSB] Unknown item '%s'. Use amx_restrictlist for names.", alias)
return PLUGIN_HANDLED
}
g_bRestricted[idx] = true
console_print(id, "[CSB] %s is now restricted.", g_szLabel[idx])
return PLUGIN_HANDLED
}
public cmdUnrestrict(id, level, cid)
{
if (!cmd_access(id, level, cid, 2))
return PLUGIN_HANDLED
new alias[24]
read_argv(1, alias, charsmax(alias))
new idx = findAlias(alias)
if (idx == -1)
{
console_print(id, "[CSB] Unknown item '%s'.", alias)
return PLUGIN_HANDLED
}
g_bRestricted[idx] = false
console_print(id, "[CSB] %s is allowed again.", g_szLabel[idx])
return PLUGIN_HANDLED
}
public cmdList(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED
console_print(id, "[CSB] Restricted items:")
new any = 0
for (new i = 0; i < sizeof(g_szAlias); i++)
{
if (g_bRestricted[i])
{
console_print(id, " %-16s (%s)", g_szAlias[i], g_szLabel[i])
any++
}
}
if (!any)
console_print(id, " (none)")
return PLUGIN_HANDLED
}