Skip to content
View in the app

A better way to browse. Learn more.

Learn more

headshot-only-practice/addons/amxmodx/scripting/olds_hsonly.sma

olds_hsonly.sma
134 lines · 4.6 KB · Pawn (AMX Mod X)
Raw
/*
 * Headshot-Only Practice (olds.ro workshop card LIB-1349)
 *
 * Practice: while on, only headshots between players deal damage, so players
 * train head-level aim. A body hit does no harm and the shooter sees a short
 * "Headshots only" hint in the centre of the screen.
 *   amx_hsonly <0|1>     turns it off or on (ADMIN_CVAR); no argument shows it
 *
 * Cvars
 *   olds_hsp_enabled 0     the mode is on
 *   olds_hsp_knife 1       knife hits deal normal damage anywhere
 *   olds_hsp_hint 1        show the hint to the shooter on a body hit
 *   olds_hsp_hegrenade 0   1 = HE grenades deal normal damage, 0 = none
 *
 * RG_CBasePlayer_TakeDamage (pre): when the attacker is a player, the hit
 * group the game stored for the victim (m_LastHitGroup, offset 75) decides:
 * HIT_HEAD keeps the damage, any other group sets it to 0
 * (SetHookChainArg(4, ATYPE_FLOAT, 0.0)). Falls and map damage are untouched.
 *
 * Copyright (C) 2026 daemon (olds.ro)
 * SPDX-License-Identifier: GPL-3.0-or-later
 */
#include <amxmodx>
#include <amxmisc>
#include <reapi>

#define PLUGIN  "Headshot-Only Practice"
#define VERSION "1.0.0"
#define AUTHOR  "olds.ro"

const Float:HINT_EVERY = 0.5

new g_enabledCvar
new g_enabled, g_knife, g_hint, g_grenade
new Float:g_nextHint[MAX_PLAYERS + 1]
new g_blocked, g_passed

public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
    register_dictionary("olds_hsonly.txt")
    g_enabledCvar = create_cvar("olds_hsp_enabled", "0", FCVAR_NONE,
        "1 = only headshots deal damage.", true, 0.0, true, 1.0)
    bind_pcvar_num(g_enabledCvar, g_enabled)
    bind_pcvar_num(create_cvar("olds_hsp_knife", "1", FCVAR_NONE,
        "1 = knife hits deal normal damage anywhere.", true, 0.0, true, 1.0), g_knife)
    bind_pcvar_num(create_cvar("olds_hsp_hint", "1", FCVAR_NONE,
        "1 = show a hint to the shooter on a body hit.", true, 0.0, true, 1.0), g_hint)
    bind_pcvar_num(create_cvar("olds_hsp_hegrenade", "0", FCVAR_NONE,
        "1 = HE grenades deal normal damage, 0 = none.", true, 0.0, true, 1.0), g_grenade)
    AutoExecConfig(true, "olds_hsonly")

    RegisterHookChain(RG_CBasePlayer_TakeDamage, "on_take_damage_pre", false)
    register_concmd("amx_hsonly", "cmd_hsonly", ADMIN_CVAR, "<0|1> - headshot-only practice off or on")
}

public client_disconnected(id)
{
    g_nextHint[id] = 0.0
}

bool:is_grenade(inflictor, bits)
{
    if (bits & DMG_GRENADE)
        return true
    if (inflictor > MaxClients && !is_nullent(inflictor))
    {
        new classname[16]
        get_entvar(inflictor, var_classname, classname, charsmax(classname))
        return equal(classname, "grenade")
    }
    return false
}

public on_take_damage_pre(victim, inflictor, attacker, Float:damage, bits)
{
    if (!g_enabled || !(1 <= attacker <= MaxClients) || attacker == victim || !is_user_connected(attacker))
        return HC_CONTINUE
    if (is_grenade(inflictor, bits))
    {
        if (!g_grenade)
        {
            SetHookChainArg(4, ATYPE_FLOAT, 0.0)
            g_blocked++
        }
        return HC_CONTINUE
    }
    if (inflictor == attacker && g_knife && get_user_weapon(attacker) == CSW_KNIFE)
        return HC_CONTINUE
    if (get_member(victim, m_LastHitGroup) == HIT_HEAD)
    {
        g_passed++
        return HC_CONTINUE
    }
    SetHookChainArg(4, ATYPE_FLOAT, 0.0)
    g_blocked++
    if (g_hint && !is_user_bot(attacker))
    {
        new Float:now = get_gametime()
        if (now >= g_nextHint[attacker])
        {
            g_nextHint[attacker] = now + HINT_EVERY
            client_print(attacker, print_center, "%L", attacker, "HSP_HINT")
        }
    }
    return HC_CONTINUE
}

public cmd_hsonly(id, level, cid)
{
    if (!cmd_access(id, level, cid, 1))
        return PLUGIN_HANDLED
    new arg[4]
    read_argv(1, arg, charsmax(arg))
    if (arg[0] == '0' || arg[0] == '1')
    {
        set_pcvar_num(g_enabledCvar, arg[0] - '0')
        if (arg[0] == '1')
            client_print_color(0, print_team_default, "^4[Practice]^1 %L", LANG_PLAYER, "HSP_ON")
        else
            client_print_color(0, print_team_default, "^4[Practice]^1 %L", LANG_PLAYER, "HSP_OFF")
        new name[MAX_NAME_LENGTH]
        get_user_name(id, name, charsmax(name))
        log_amx("%s set headshot-only practice %c", name, arg[0])
    }
    else if (arg[0])
    {
        console_print(id, "[Practice] usage: amx_hsonly <0|1>")
        return PLUGIN_HANDLED
    }
    console_print(id, "[Practice] headshot only %d, knife free %d, hint %d, HE grenade damage %d; %d hit(s) blocked, %d headshot(s) passed",
        g_enabled, g_knife, g_hint, g_grenade, g_blocked, g_passed)
    return PLUGIN_HANDLED
}

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.