Skip to content
View in the app

A better way to browse. Learn more.

Learn more

burst-and-silencer-switch-block/addons/amxmodx/scripting/olds_modeblock.sma

olds_modeblock.sma
142 lines · 4.5 KB · Pawn (AMX Mod X)
Raw
/*
 * Burst and Silencer Switch Block (olds.ro workshop card LIB-0140)
 *
 * Players cannot switch the Glock-18 or FAMAS to burst fire, or put on or
 * take off the silencer of the USP or M4A1, when the server rules forbid
 * it. A short text tells them why.
 *
 * Commands: none.
 *
 * Cvars (in configs/plugins/olds_modeblock.cfg, which ships with the plugin;
 * if the file is missing, the plugin writes it with these defaults the first
 * time it starts):
 *   olds_bs_burst  1  1 = the Glock-18 and FAMAS burst switch is blocked.
 *   olds_bs_sil    1  1 = the USP and M4A1 silencer switch is blocked.
 *   olds_bs_msg    1  1 = a short text in the middle of the screen says
 *                     the switch is not allowed (at most once a second).
 *
 * Rules:
 *   - The weapon keeps the mode it has; only the switch is blocked. A
 *     weapon picked up with a silencer on keeps it.
 *   - The USP and Glock with a tactical shield still raise and lower the
 *     shield: that is not a mode switch.
 *   - Other weapons are not touched: the AWP and the other scopes still
 *     zoom, the knife still stabs.
 *   - Holding the button sends many attempts; the text shows at most once
 *     a second.
 *
 * How it works, as the card asks: Ham_Weapon_SecondaryAttack (pre) on
 * weapon_glock18, weapon_famas, weapon_usp and weapon_m4a1 returns
 * HAM_SUPERCEDE when the cvar blocks that switch.
 *
 * Requires AMX Mod X 1.10 with ReAPI (ReGameDLL_CS) and the hamsandwich
 * module. Written for AMX Mod X 1.10.0.5490, ReAPI 5.29.0.358 and
 * ReGameDLL_CS 5.30.0.814.
 *
 * Copyright (C) 2026 alexit (olds.ro workshop)
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 * 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.
 *
 * This program 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 the GNU General Public License for
 * more details: <https://www.gnu.org/licenses/>.
 */

#include <amxmodx>
#include <hamsandwich>
#include <reapi>

#pragma semicolon 1

new const PLUGIN_NAME[] = "Burst and Silencer Switch Block";
new const PLUGIN_VERSION[] = "1.0.0";
new const PLUGIN_AUTHOR[] = "alexit (olds.ro)";

const Float:MESSAGE_EVERY = 1.0;

new g_blockBurst;      // olds_bs_burst
new g_blockSilencer;   // olds_bs_sil
new g_message;         // olds_bs_msg

new Float:g_nextMessage[MAX_PLAYERS + 1];

public plugin_init()
{
	register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);

	// The weapon members come from ReGameDLL_CS.
	if (!is_regamedll())
		set_fail_state("ReGameDLL_CS is not running. This plugin needs ReGameDLL_CS and ReAPI.");

	register_dictionary("olds_modeblock.txt");

	bind_pcvar_num(create_cvar("olds_bs_burst", "1", FCVAR_NONE,
		"1 = the Glock-18 and FAMAS burst switch is blocked",
		true, 0.0, true, 1.0), g_blockBurst);

	bind_pcvar_num(create_cvar("olds_bs_sil", "1", FCVAR_NONE,
		"1 = the USP and M4A1 silencer switch is blocked",
		true, 0.0, true, 1.0), g_blockSilencer);

	bind_pcvar_num(create_cvar("olds_bs_msg", "1", FCVAR_NONE,
		"1 = a short text says the switch is not allowed (at most once a second)",
		true, 0.0, true, 1.0), g_message);

	AutoExecConfig(true, "olds_modeblock");

	RegisterHam(Ham_Weapon_SecondaryAttack, "weapon_glock18", "on_burst_switch_pre", false);
	RegisterHam(Ham_Weapon_SecondaryAttack, "weapon_famas", "on_burst_switch_pre", false);
	RegisterHam(Ham_Weapon_SecondaryAttack, "weapon_usp", "on_silencer_switch_pre", false);
	RegisterHam(Ham_Weapon_SecondaryAttack, "weapon_m4a1", "on_silencer_switch_pre", false);
}

public client_putinserver(id)
{
	g_nextMessage[id] = 0.0;
}

public on_burst_switch_pre(weapon)
{
	if (!g_blockBurst)
		return HAM_IGNORED;

	return block_switch(weapon, "BS_NO_BURST");
}

public on_silencer_switch_pre(weapon)
{
	if (!g_blockSilencer)
		return HAM_IGNORED;

	return block_switch(weapon, "BS_NO_SILENCER");
}

block_switch(weapon, const key[])
{
	new id = get_member(weapon, m_pPlayer);

	if (id < 1 || id > MaxClients || !is_user_connected(id))
		return HAM_IGNORED;

	// With a shield the button raises or lowers the shield instead.
	if (get_member(id, m_bOwnsShield))
		return HAM_IGNORED;

	if (g_message)
	{
		new Float:now = get_gametime();

		if (now >= g_nextMessage[id])
		{
			g_nextMessage[id] = now + MESSAGE_EVERY;
			client_print(id, print_center, "%L", id, key);
		}
	}

	return HAM_SUPERCEDE;
}

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.