Skip to content
View in the app

A better way to browse. Learn more.

Learn more

headshot-frag-value/addons/amxmodx/scripting/olds_hsfrag.sma

olds_hsfrag.sma
121 lines · 3.9 KB · Pawn (AMX Mod X)
Raw
/*
 * Headshot Frag Value (olds.ro workshop card LIB-2105)
 *
 * A headshot kill on an enemy is worth more frags: on top of the normal
 * frag the killer gets olds_hsf_extra extra frags, and the scoreboard is
 * updated at once (ScoreInfo message).
 *
 *   - Team kills, suicides, kills by the world and grenade or bomb kills
 *     never give extra frags.
 *   - Knife headshots count only with olds_hsf_knife 1.
 *   - With olds_hsf_notify 1 the killer gets a short chat line.
 *
 * Cvars (configs/plugins/olds_hsfrag.cfg; AutoExecConfig writes that file
 * with these defaults if it is missing):
 *   olds_hsf_extra  1  Extra frags for a headshot kill (0 - 10).
 *   olds_hsf_knife  0  1 = knife headshots also give the extra frags.
 *   olds_hsf_notify 1  1 = tell the killer in chat.
 *
 * Every text players read comes from data/lang/olds_hsfrag.txt (English).
 *
 * Requires AMX Mod X 1.10 or newer and ReAPI with ReGameDLL_CS. Written for
 * AMX Mod X 1.10.0.5490, ReAPI 5.29.0.358, 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 <fun>
#include <reapi>

#pragma semicolon 1

new const PLUGIN_NAME[] = "Headshot Frag Value";
new const PLUGIN_VERSION[] = "1.0.0";
new const PLUGIN_AUTHOR[] = "alexit (olds.ro)";

new const DICTIONARY[] = "olds_hsfrag.txt";

new g_extra;            // olds_hsf_extra
new g_knife;            // olds_hsf_knife
new g_notify;           // olds_hsf_notify

new g_msgScoreInfo;

public plugin_init()
{
	register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
	register_dictionary(DICTIONARY);

	bind_pcvar_num(create_cvar("olds_hsf_extra", "1", FCVAR_NONE,
		"Extra frags for a headshot kill on an enemy (0 - 10)",
		true, 0.0, true, 10.0), g_extra);

	bind_pcvar_num(create_cvar("olds_hsf_knife", "0", FCVAR_NONE,
		"1 = knife headshots also give the extra frags, 0 = not",
		true, 0.0, true, 1.0), g_knife);

	bind_pcvar_num(create_cvar("olds_hsf_notify", "1", FCVAR_NONE,
		"1 = tell the killer in chat about the extra frags, 0 = silent",
		true, 0.0, true, 1.0), g_notify);

	AutoExecConfig(true, "olds_hsfrag");

	g_msgScoreInfo = get_user_msgid("ScoreInfo");

	RegisterHookChain(RG_CBasePlayer_Killed, "OnPlayerKilled_Post", true);
}

public OnPlayerKilled_Post(victim, killer)
{
	if (g_extra < 1 || killer < 1 || killer > MaxClients || killer == victim || !is_user_connected(killer))
		return HC_CONTINUE;

	if (!get_member(victim, m_bHeadshotKilled))
		return HC_CONTINUE;

	// A grenade or the bomb is never a headshot.
	if (get_member(victim, m_bKilledByGrenade) || get_member(victim, m_bKilledByBomb))
		return HC_CONTINUE;

	new killerTeam = get_member(killer, m_iTeam);

	if (killerTeam == get_member(victim, m_iTeam))
		return HC_CONTINUE;

	if (!g_knife && is_user_alive(killer) && get_user_weapon(killer) == CSW_KNIFE)
		return HC_CONTINUE;

	new frags = get_user_frags(killer) + g_extra;
	set_user_frags(killer, frags);

	// Update the scoreboard of every player.
	emessage_begin(MSG_ALL, g_msgScoreInfo);
	ewrite_byte(killer);
	ewrite_short(frags);
	ewrite_short(get_member(killer, m_iDeaths));
	ewrite_short(0);
	ewrite_short(killerTeam);
	emessage_end();

	if (g_notify && !is_user_bot(killer))
	{
		if (g_extra == 1)
			client_print_color(killer, print_team_default, "^4*^1 %L", killer, "OLDS_HSF_ONE");
		else
			client_print_color(killer, print_team_default, "^4*^1 %L", killer, "OLDS_HSF_MANY", g_extra);
	}

	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.