PHP Code:
#include <amxmodx>
// Here is the name of all "buy weapons" commands of CS, took from CS Weapons Information (AM Wiki).
// Is a tridimensional array because I'm going to use it in a loop, but actually this is not necessary,
// you can register all commands separately, but I think this is the easier & clean way to do it.
new gBuyCommands[][] =
{
"usp", "glock", "deagle", "p228", "elites", "fn57", "m3", "xm1014", "mp5", "tmp", "p90", "mac10", "ump45", "ak47",
"galil", "famas", "sg552", "m4a1", "aug", "scout", "awp", "g3sg1", "sg550", "m249", "vest", "vesthelm", "flash", "hegren",
"sgren", "defuser", "nvgs", "shield", "primammo", "secammo", "km45", "9x19mm", "nighthawk", "228compact", "12gauge",
"autoshotgun", "smg", "mp", "c90", "cv47", "defender", "clarion", "krieg552", "bullpup", "magnum", "d3au1", "krieg550",
"buyammo1", "buyammo2"
}
// Variable that I'm going to use to register the pCVAR.
new gCvarPluginToggle
public plugin_init()
{
// I think there is no need for explain this.
register_plugin("Block Buy Example", "0.1.0", "fezh")
// Toggle CVAR
gCvarPluginToggle = register_cvar("amx_block_buy", "1")
// Registering commands. As I said before, there is no need for creating a loop, but I like it anyways :P
for (new i; i < sizeof gBuyCommands; i++)
register_clcmd(gBuyCommands[i], "BlockBuyCommands")
}
public BlockBuyCommands(id)
{
// If the plugin don't get the CVAR, it makes you buy normally.
if (!get_pcvar_num(gCvarPluginToggle))
return PLUGIN_CONTINUE;
// Block the buy commands.
return PLUGIN_HANDLED;
}
// Final comments: I did the "tutorial" since I saw that there are some weirds (and not actually functional) ways to do it,
// like in the plugin called "Block Commands".