/*
* AWP One-Shot Kill (olds.ro workshop card LIB-0094)
*
* A bullet from the AWP kills on any body hit, not only on the head or the
* chest. A cvar limits it to some hit groups, armor can be ignored or not,
* and the Scout can be made to work the same way.
*
* Commands: none.
*
* Cvars (in configs/plugins/olds_awponeshot.cfg, which ships with the
* plugin; if the file is missing, the plugin writes it with these defaults
* the first time it starts):
* olds_ao_groups 255 Hit groups where one bullet kills, added up:
* head 1, chest 2, stomach 4, arms 8, legs 16
* (31 or more = all of them). 3 = head and chest.
* olds_ao_armor 1 1 = armor does not save the victim; 0 = the game's
* armor reduction still applies to the lethal hit.
* olds_ao_scout 0 1 = the Scout kills in one hit too.
*
* Rules:
* - Only bullets count, fired by a player holding the AWP (or the Scout
* with olds_ao_scout 1). Grenades, the knife and other guns are not
* touched.
* - A bullet through a wall still kills when the hit group is allowed.
* - The game still decides whether the hit may hurt at all: with friendly
* fire off a teammate takes no damage, as before.
* - Hit groups outside olds_ao_groups take the game's normal damage.
*
* How it works, as the card asks: RG_CBasePlayer_TraceAttack (pre) stores
* the hit group of the bullet; RG_CBasePlayer_TakeDamage (pre) then sets
* the damage to the victim's health + 1 for an allowed AWP hit. To ignore
* armor, the victim's armor is set to 0 for that one hit and given back in
* the post hook if he is still alive (for example a teammate the game did
* not let the bullet hurt). The plugin shows no text, so it has no language
* file.
*
* 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[] = "AWP One-Shot Kill";
new const PLUGIN_VERSION[] = "1.0.0";
new const PLUGIN_AUTHOR[] = "alexit (olds.ro)";
// Bits of olds_ao_groups.
const GROUP_HEAD = 1;
const GROUP_CHEST = 2;
const GROUP_STOMACH = 4;
const GROUP_ARMS = 8;
const GROUP_LEGS = 16;
const GROUP_ALL = GROUP_HEAD | GROUP_CHEST | GROUP_STOMACH | GROUP_ARMS | GROUP_LEGS;
new g_groups; // olds_ao_groups
new g_ignoreArmor; // olds_ao_armor
new g_scout; // olds_ao_scout
// Hit group of the bullet that just hit each player, plus 1 (0 = none).
new g_hitGroup[MAX_PLAYERS + 1];
// Armor taken away for one lethal hit, -1.0 = none.
new Float:g_savedArmor[MAX_PLAYERS + 1] = { -1.0, ... };
public plugin_init()
{
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
// The damage hooks come from ReGameDLL_CS.
if (!is_regamedll())
set_fail_state("ReGameDLL_CS is not running. This plugin needs ReGameDLL_CS and ReAPI.");
bind_pcvar_num(create_cvar("olds_ao_groups", "255", FCVAR_NONE,
"Hit groups where one AWP bullet kills, added up: head 1, chest 2, stomach 4, arms 8, legs 16 (31 or more = all)",
true, 0.0, true, 255.0), g_groups);
bind_pcvar_num(create_cvar("olds_ao_armor", "1", FCVAR_NONE,
"1 = armor does not save the victim; 0 = the game's armor reduction still applies",
true, 0.0, true, 1.0), g_ignoreArmor);
bind_pcvar_num(create_cvar("olds_ao_scout", "0", FCVAR_NONE,
"1 = the Scout kills in one hit too",
true, 0.0, true, 1.0), g_scout);
AutoExecConfig(true, "olds_awponeshot");
RegisterHookChain(RG_CBasePlayer_TraceAttack, "on_trace_attack_pre", false);
RegisterHookChain(RG_CBasePlayer_TakeDamage, "on_take_damage_pre", false);
RegisterHookChain(RG_CBasePlayer_TakeDamage, "on_take_damage_post", true);
}
/**
* A bullet hits a player: its hit group is kept for the damage that follows.
*/
public on_trace_attack_pre(victim, attacker, Float:damage, Float:direction[3], trace, damageBits)
{
g_hitGroup[victim] = get_tr2(trace, TR_iHitgroup) + 1;
return HC_CONTINUE;
}
public on_take_damage_pre(victim, inflictor, attacker, Float:damage, damageBits)
{
new group = g_hitGroup[victim] - 1;
g_hitGroup[victim] = 0;
// Only a bullet that went through TraceAttack, fired by another player.
if (group < 0 || !(damageBits & DMG_BULLET) || attacker == victim || inflictor != attacker
|| attacker < 1 || attacker > MaxClients || !is_user_connected(attacker))
return HC_CONTINUE;
if (!holds_one_shot_weapon(attacker) || !group_allowed(group))
return HC_CONTINUE;
new Float:health = Float:get_entvar(victim, var_health);
SetHookChainArg(4, ATYPE_FLOAT, health + 1.0);
if (g_ignoreArmor)
{
// No armor for this one hit, so the game cannot reduce the damage.
g_savedArmor[victim] = Float:get_entvar(victim, var_armorvalue);
set_entvar(victim, var_armorvalue, 0.0);
}
return HC_CONTINUE;
}
/**
* Gives the armor back when the victim survived (the game refused the hit).
*/
public on_take_damage_post(victim, inflictor, attacker, Float:damage, damageBits)
{
if (g_savedArmor[victim] < 0.0)
return HC_CONTINUE;
if (is_user_alive(victim))
set_entvar(victim, var_armorvalue, g_savedArmor[victim]);
g_savedArmor[victim] = -1.0;
return HC_CONTINUE;
}
public client_disconnected(id)
{
g_hitGroup[id] = 0;
g_savedArmor[id] = -1.0;
}
bool:holds_one_shot_weapon(id)
{
new weapon = get_member(id, m_pActiveItem);
if (weapon <= 0)
return false;
new weaponId = get_member(weapon, m_iId);
return weaponId == CSW_AWP || (g_scout && weaponId == CSW_SCOUT);
}
/**
* True when olds_ao_groups covers this hit group. A hit without a group
* (generic) counts only when every group is allowed.
*/
bool:group_allowed(group)
{
switch (group)
{
case HIT_HEAD:
return bool:(g_groups & GROUP_HEAD);
case HIT_CHEST:
return bool:(g_groups & GROUP_CHEST);
case HIT_STOMACH:
return bool:(g_groups & GROUP_STOMACH);
case HIT_LEFTARM, HIT_RIGHTARM:
return bool:(g_groups & GROUP_ARMS);
case HIT_LEFTLEG, HIT_RIGHTLEG:
return bool:(g_groups & GROUP_LEGS);
case HIT_GENERIC:
return (g_groups & GROUP_ALL) == GROUP_ALL;
}
// The shield, or anything unknown.
return false;
}