/*
* Bullet Ricochet Blocker (olds.ro workshop card LIB-0136)
*
* Removes the bullet ricochet effects the server sends: the sparks and
* gunshot puffs of a bullet, and the ricochet whine, so shots do not seem to
* bounce. Bullet holes (decals) and blood stay.
*
* Commands: none.
*
* Cvars (in configs/plugins/olds_noricochet.cfg, which ships with the
* plugin; if the file is missing, the plugin writes it with these defaults
* the first time it starts):
* olds_nr_sparks 1 1 = no sparks or gunshot puffs from bullets.
* olds_nr_sound 1 1 = no ricochet sound (weapons/ric*.wav).
*
* Rules:
* - Sparks and gunshot puffs are removed only while a bullet is being
* fired, so explosions, grenade spark showers and sparking map objects
* keep theirs.
* - Bullet holes (decals), blood and every other effect stay.
* - Counter-Strike 1.6 draws most bullet impacts (the hole, its dust and
* sparks) on each player's own computer, from the shot itself; a server
* plugin cannot change those. This plugin removes what the server sends,
* for example the sparks and the whine of a bullet hitting a shield.
*
* How it works, as the card asks: register_message(SVC_TEMPENTITY) drops
* TE_SPARKS (9) and TE_GUNSHOT (2) while a bullet is fired (ReAPI
* RG_CBaseEntity_FireBullets3, FireBullets and FireBuckshots, pre to post),
* and FM_EmitSound drops the weapons/ric*.wav samples.
*
* Requires AMX Mod X 1.10 with ReAPI (ReGameDLL_CS) and the fakemeta 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 <fakemeta>
#include <reapi>
#pragma semicolon 1
new const PLUGIN_NAME[] = "Bullet Ricochet Blocker";
new const PLUGIN_VERSION[] = "1.0.0";
new const PLUGIN_AUTHOR[] = "alexit (olds.ro)";
new const RICOCHET_PREFIX[] = "weapons/ric";
new g_noSparks; // olds_nr_sparks
new g_noSound; // olds_nr_sound
// How many bullet functions are running right now (they can nest).
new g_bulletDepth;
public plugin_init()
{
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
if (!is_regamedll())
set_fail_state("ReGameDLL_CS is not running. This plugin needs ReGameDLL_CS and ReAPI.");
bind_pcvar_num(create_cvar("olds_nr_sparks", "1", FCVAR_NONE,
"1 = no sparks or gunshot puffs from bullets",
true, 0.0, true, 1.0), g_noSparks);
bind_pcvar_num(create_cvar("olds_nr_sound", "1", FCVAR_NONE,
"1 = no ricochet sound (weapons/ric*.wav)",
true, 0.0, true, 1.0), g_noSound);
AutoExecConfig(true, "olds_noricochet");
register_message(SVC_TEMPENTITY, "on_temp_entity");
register_forward(FM_EmitSound, "on_emit_sound");
RegisterHookChain(RG_CBaseEntity_FireBullets3, "on_bullet_start", false);
RegisterHookChain(RG_CBaseEntity_FireBullets3, "on_bullet_end", true);
RegisterHookChain(RG_CBaseEntity_FireBullets, "on_bullet_start", false);
RegisterHookChain(RG_CBaseEntity_FireBullets, "on_bullet_end", true);
RegisterHookChain(RG_CBaseEntity_FireBuckshots, "on_bullet_start", false);
RegisterHookChain(RG_CBaseEntity_FireBuckshots, "on_bullet_end", true);
RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round", true);
}
public on_bullet_start()
{
g_bulletDepth++;
return HC_CONTINUE;
}
public on_bullet_end()
{
if (g_bulletDepth > 0)
g_bulletDepth--;
return HC_CONTINUE;
}
/**
* A safety net: no bullet is in flight between rounds.
*/
public on_restart_round()
{
g_bulletDepth = 0;
}
public on_temp_entity(msgId, msgDest, msgEntity)
{
if (!g_noSparks || !g_bulletDepth)
return PLUGIN_CONTINUE;
new type = get_msg_arg_int(1);
if (type == TE_SPARKS || type == TE_GUNSHOT)
return PLUGIN_HANDLED;
return PLUGIN_CONTINUE;
}
public on_emit_sound(entity, channel, const sample[], Float:volume, Float:attenuation, flags, pitch)
{
if (g_noSound && equal(sample, RICOCHET_PREFIX, charsmax(RICOCHET_PREFIX)))
return FMRES_SUPERCEDE;
return FMRES_IGNORED;
}