/*
* Juggernaut Exposed Back (olds.ro workshop card IDEA-72C828BF7EE751EF)
*
* The juggernaut's armour covers only the front. Damage that reaches the
* juggernaut from behind is multiplied, the shooter sees a short BACK HIT
* marker, and the juggernaut sees an arrow for one second that points to the
* side the hit came from. Hunters gain by flanking, and the juggernaut has
* to keep turning instead of walking straight down a corridor.
*
* This is an add-on for a juggernaut game mode. The mode's core plugin must
* provide this native, true while the player is the juggernaut:
*
* native olds_is_juggernaut(id);
*
* Without such a core the plugin still loads, logs one line and changes
* nothing.
*
* Console command (server console, or admins with the rcon flag "l"):
* olds_jback_status back hits since the map started, and the damage of
* the last one (after the multiplier, before armour)
*
* Cvars (in configs/plugins/olds_jback.cfg, written with the defaults on the
* first start if the file is missing):
* olds_jback_enable 1 1 = on, 0 = off.
* olds_jback_arc 120 Width of the armoured front, in degrees (0 - 360).
* 120 = 60 degrees to each side of where the
* juggernaut looks.
* olds_jback_mult 2.0 Damage multiplier for hits from behind (1 - 10).
* olds_jback_nades 0 1 = grenades count too, judged from the spot where
* the grenade went off; 0 = they never do.
* olds_jback_sound 1 1 = the shooter also hears a short ricochet.
*
* How it works, as the card asks: RG_CBasePlayer_TakeDamage (pre). The
* direction from the juggernaut to the attacker (to the grenade for
* DMG_GRENADE) is compared with the yaw of the juggernaut's view
* (var_v_angle). Outside the front arc the damage argument is multiplied
* with SetHookChainArg, before the game applies armour and health.
*
* Requires AMX Mod X 1.10 with ReAPI (ReGameDLL_CS). Written and tested on
* 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 <amxmisc>
#include <reapi>
#pragma semicolon 1
new const PLUGIN_NAME[] = "Juggernaut Exposed Back";
new const PLUGIN_VERSION[] = "1.0.0";
new const PLUGIN_AUTHOR[] = "alexit (olds.ro)";
new const DICTIONARY[] = "olds_jback.txt";
new const CORE_NATIVE[] = "olds_is_juggernaut";
// Stock Half-Life sound, played on the shooter's own client.
new const HIT_SOUND_COMMAND[] = "spk weapons/ric1";
// The shooter's marker and the juggernaut's arrow are shown at most this
// often per player, so automatic fire does not pile up DHUD messages.
const Float:SHOOTER_MARKER_TIME = 0.5;
const Float:ARROW_TIME = 1.0;
// Provided by the juggernaut core.
native olds_is_juggernaut(id);
new bool:g_noCore;
new g_enable; // olds_jback_enable
new Float:g_arc; // olds_jback_arc
new Float:g_mult; // olds_jback_mult
new g_nades; // olds_jback_nades
new g_sound; // olds_jback_sound
new g_backHits;
new g_lastDamage;
new Float:g_nextMarker[MAX_PLAYERS + 1];
new Float:g_nextArrow[MAX_PLAYERS + 1];
public plugin_natives()
{
set_native_filter("native_filter");
}
/**
* Lets the plugin load when no core provides olds_is_juggernaut. The native
* is then never called.
*/
public native_filter(const name[], index, trap)
{
if (!trap && equal(name, CORE_NATIVE))
{
g_noCore = true;
return PLUGIN_HANDLED;
}
return PLUGIN_CONTINUE;
}
public plugin_init()
{
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
register_dictionary(DICTIONARY);
bind_pcvar_num(create_cvar("olds_jback_enable", "1", FCVAR_NONE,
"1 = hits on the juggernaut's back deal extra damage, 0 = off",
true, 0.0, true, 1.0), g_enable);
bind_pcvar_float(create_cvar("olds_jback_arc", "120", FCVAR_NONE,
"Width of the juggernaut's armoured front in degrees (0 - 360)",
true, 0.0, true, 360.0), g_arc);
bind_pcvar_float(create_cvar("olds_jback_mult", "2.0", FCVAR_NONE,
"Damage multiplier for hits from behind (1 - 10)",
true, 1.0, true, 10.0), g_mult);
bind_pcvar_num(create_cvar("olds_jback_nades", "0", FCVAR_NONE,
"1 = grenades count too, judged from where they went off, 0 = never",
true, 0.0, true, 1.0), g_nades);
bind_pcvar_num(create_cvar("olds_jback_sound", "1", FCVAR_NONE,
"1 = the shooter hears a short ricochet on a back hit, 0 = no sound",
true, 0.0, true, 1.0), g_sound);
AutoExecConfig(true, "olds_jback");
register_concmd("olds_jback_status", "cmd_status", ADMIN_RCON,
"- back hits on the juggernaut since the map started");
if (g_noCore)
{
log_amx("No plugin provides the native %s (the juggernaut core), so back hits are not counted.", CORE_NATIVE);
return;
}
RegisterHookChain(RG_CBasePlayer_TakeDamage, "on_take_damage_pre", false);
}
public client_disconnected(id)
{
g_nextMarker[id] = 0.0;
g_nextArrow[id] = 0.0;
}
public cmd_status(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED;
console_print(id, "%L", id, "JBACK_STATUS", g_backHits, g_lastDamage);
if (g_noCore)
console_print(id, "%L", id, "JBACK_NO_CORE");
return PLUGIN_HANDLED;
}
public on_take_damage_pre(victim, inflictor, attacker, Float:damage, damageBits)
{
if (!g_enable || attacker == victim || !(1 <= attacker <= MaxClients) || !is_user_connected(attacker))
return HC_CONTINUE;
if (!is_user_alive(victim) || !olds_is_juggernaut(victim))
return HC_CONTINUE;
// A teammate with friendly fire off deals no damage: no marker either.
if (!rg_is_player_can_takedamage(victim, attacker))
return HC_CONTINUE;
new source = attacker;
if (damageBits & DMG_GRENADE)
{
if (!g_nades)
return HC_CONTINUE;
// The grenade, when it still exists; otherwise its thrower.
if (inflictor != attacker && !is_nullent(inflictor))
source = inflictor;
}
new Float:offset = direction_from_view(victim, source);
if (floatabs(offset) <= g_arc / 2.0)
return HC_CONTINUE;
new Float:backDamage = damage * g_mult;
SetHookChainArg(4, ATYPE_FLOAT, backDamage);
g_backHits++;
g_lastDamage = floatround(backDamage);
show_markers(victim, attacker, offset);
return HC_CONTINUE;
}
/**
* Where the source is, seen from the player: degrees from the middle of the
* player's view, -180 to 180. Positive is to the left, negative to the right
* and 180 straight behind.
*/
Float:direction_from_view(id, source)
{
new Float:from[3], Float:to[3], Float:view[3];
get_entvar(id, var_origin, from);
get_entvar(source, var_origin, to);
get_entvar(id, var_v_angle, view);
new Float:dx = to[0] - from[0];
new Float:dy = to[1] - from[1];
// On top of the player: no side to tell, so it counts as the front.
if (floatabs(dx) < 1.0 && floatabs(dy) < 1.0)
return 0.0;
return wrap_degrees(floatatan2(dy, dx, degrees) - view[1]);
}
Float:wrap_degrees(Float:angle)
{
while (angle > 180.0)
angle -= 360.0;
while (angle <= -180.0)
angle += 360.0;
return angle;
}
show_markers(victim, attacker, Float:offset)
{
new Float:now = get_gametime();
if (now >= g_nextMarker[attacker])
{
g_nextMarker[attacker] = now + SHOOTER_MARKER_TIME;
set_dhudmessage(255, 90, 40, -1.0, 0.56, 0, 0.0, SHOOTER_MARKER_TIME, 0.05, 0.15);
show_dhudmessage(attacker, "%L", attacker, "JBACK_BACK_HIT");
if (g_sound && !is_user_bot(attacker))
client_cmd(attacker, HIT_SOUND_COMMAND);
}
if (now >= g_nextArrow[victim])
{
g_nextArrow[victim] = now + ARROW_TIME;
// Below the crosshair when the hit came from straight behind,
// otherwise beside it on the side it came from.
if (floatabs(offset) >= 150.0)
{
set_dhudmessage(255, 40, 40, -1.0, 0.62, 0, 0.0, ARROW_TIME, 0.05, 0.2);
show_dhudmessage(victim, "vvv");
}
else if (offset > 0.0)
{
set_dhudmessage(255, 40, 40, 0.40, -1.0, 0, 0.0, ARROW_TIME, 0.05, 0.2);
show_dhudmessage(victim, "<<<");
}
else
{
set_dhudmessage(255, 40, 40, 0.57, -1.0, 0, 0.0, ARROW_TIME, 0.05, 0.2);
show_dhudmessage(victim, ">>>");
}
}
}