Skip to content
View in the app

A better way to browse. Learn more.

Learn more

bomb-carrier-explosion/addons/amxmodx/scripting/olds_carrierblast.sma

olds_carrierblast.sma
201 lines · 6.3 KB · Pawn (AMX Mod X)
Raw
/*
 * Bomb Carrier Explosion (olds.ro workshop card LIB-0108)
 *
 * When the bomb carrier dies with the bomb on him, the bomb goes off where
 * he falls: an explosion hurts the players around him. The bomb is used up,
 * and the round goes on.
 *
 * Commands: none.
 *
 * Cvars (in configs/plugins/olds_carrierblast.cfg, which ships with the
 * plugin; if the file is missing, the plugin writes it with these defaults
 * the first time it starts):
 *   olds_bce_damage  150  Damage at the centre of the blast; it falls to 0
 *                         at the edge. 0 = the blast is only shown.
 *   olds_bce_radius  250  Radius of the blast, in units.
 *   olds_bce_tonly   0    1 = only Terrorists are hurt by the blast.
 *
 * Rules:
 *   - Only a carrier who still holds the bomb when he dies explodes. A bomb
 *     dropped or planted before does nothing.
 *   - The bomb is destroyed with him: it is not dropped, so the Terrorists
 *     have no bomb for the rest of that round.
 *   - The blast is not the bomb's detonation: the round does not end and
 *     nobody wins by it, even inside a bomb site.
 *   - Walls stop the blast, as with grenades. Deaths it causes count as
 *     deaths by the world (nobody gets a frag for them); the kill
 *     feed shows the C4 icon.
 *
 * How it works, as the card asks: RG_CBasePlayer_Killed (pre) checks
 * m_bHasC4 on the victim and takes the weapon_c4 away; right after the
 * death (Killed post) a TE_EXPLOSION with the stock sprites/fexplo.spr and
 * the stock weapons/c4_explode1.wav are played there, and rg_dmg_radius
 * deals the damage (RG_CBasePlayer_TakeDamage leaves out the dead carrier
 * and, with olds_bce_tonly 1, the Counter-Terrorists).
 *
 * 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[] = "Bomb Carrier Explosion";
new const PLUGIN_VERSION[] = "1.0.0";
new const PLUGIN_AUTHOR[] = "alexit (olds.ro)";

new const BLAST_SPRITE[] = "sprites/fexplo.spr";
new const BLAST_SOUND[] = "weapons/c4_explode1.wav";

new Float:g_damage;    // olds_bce_damage
new Float:g_radius;    // olds_bce_radius
new g_terroristsOnly;  // olds_bce_tonly

new g_blastSprite;

// The carrier who is dying with the bomb, and where.
new g_carrier;
new Float:g_carrierOrigin[3];

// True while the blast deals its damage.
new bool:g_inBlast;

public plugin_precache()
{
	g_blastSprite = precache_model(BLAST_SPRITE);
	precache_sound(BLAST_SOUND);
}

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_float(create_cvar("olds_bce_damage", "150", FCVAR_NONE,
		"Damage at the centre of the bomb carrier's blast (0 = the blast is only shown)",
		true, 0.0, true, 1000.0), g_damage);

	bind_pcvar_float(create_cvar("olds_bce_radius", "250", FCVAR_NONE,
		"Radius of the bomb carrier's blast, in units",
		true, 1.0, true, 2000.0), g_radius);

	bind_pcvar_num(create_cvar("olds_bce_tonly", "0", FCVAR_NONE,
		"1 = only Terrorists are hurt by the bomb carrier's blast",
		true, 0.0, true, 1.0), g_terroristsOnly);

	AutoExecConfig(true, "olds_carrierblast");

	RegisterHookChain(RG_CBasePlayer_Killed, "on_player_killed_pre", false);
	RegisterHookChain(RG_CBasePlayer_Killed, "on_player_killed_post", true);
	RegisterHookChain(RG_CBasePlayer_TakeDamage, "on_take_damage_pre", false);
}

/**
 * The carrier dies with the bomb: it is taken away so it is not dropped.
 */
public on_player_killed_pre(victim, killer, gib)
{
	if (g_inBlast || !get_member(victim, m_bHasC4))
		return HC_CONTINUE;

	g_carrier = victim;
	get_entvar(victim, var_origin, g_carrierOrigin);

	rg_remove_item(victim, "weapon_c4");
	set_member(victim, m_bHasC4, false);
	return HC_CONTINUE;
}

/**
 * After the death: the blast.
 */
public on_player_killed_post(victim, killer, gib)
{
	if (victim != g_carrier || g_inBlast)
		return HC_CONTINUE;

	new Float:origin[3];
	origin = g_carrierOrigin;

	message_begin_f(MSG_PVS, SVC_TEMPENTITY, origin);
	write_byte(TE_EXPLOSION);
	write_coord_f(origin[0]);
	write_coord_f(origin[1]);
	write_coord_f(origin[2] + 20.0);
	write_short(g_blastSprite);
	write_byte(30);                    // scale 3.0
	write_byte(15);                    // frame rate
	write_byte(TE_EXPLFLAG_NOSOUND);
	message_end();

	engfunc(EngFunc_EmitAmbientSound, 0, origin, BLAST_SOUND, VOL_NORM, ATTN_NORM, 0, PITCH_NORM);

	if (g_damage > 0.0)
		deal_blast_damage(origin);

	g_carrier = 0;
	return HC_CONTINUE;
}

/**
 * The damage comes from a short-lived entity at the blast, so it counts as
 * a death by the world. Its class name makes the kill feed show the C4
 * icon (the game strips "func_" and the client knows "c4").
 */
deal_blast_damage(const Float:origin[3])
{
	new blast = rg_create_entity("info_target");

	if (blast <= 0)
		return;

	set_entvar(blast, var_classname, "func_c4");
	engfunc(EngFunc_SetOrigin, blast, origin);

	new Float:source[3];
	source = origin;

	g_inBlast = true;
	rg_dmg_radius(source, blast, blast, g_damage, g_radius, 0, DMG_BLAST);
	g_inBlast = false;

	engfunc(EngFunc_RemoveEntity, blast);
}

/**
 * During the blast: never the dead carrier, and only Terrorists with
 * olds_bce_tonly 1.
 */
public on_take_damage_pre(victim, inflictor, attacker, Float:damage, damageBits)
{
	if (!g_inBlast)
		return HC_CONTINUE;

	if (victim == g_carrier || !is_user_alive(victim)
		|| (g_terroristsOnly && get_member(victim, m_iTeam) != TEAM_TERRORIST))
	{
		SetHookChainReturn(ATYPE_INTEGER, 0);
		return HC_SUPERCEDE;
	}

	return HC_CONTINUE;
}

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.