Skip to content
View in the app

A better way to browse. Learn more.

Learn more

early-kill-hp-bonus/addons/amxmodx/scripting/olds_rushhp.sma

olds_rushhp.sma
172 lines · 6 KB · Pawn (AMX Mod X)
Raw
/*
 * Early Kill HP Bonus (olds.ro workshop card LIB-0243)
 *
 * Kills made in the first seconds of a round, counted from the end of the
 * freeze time, give the killer extra health. A headshot gives more. This
 * rewards an early push.
 *
 * Commands: none.
 *
 * Cvars (in configs/plugins/olds_rushhp.cfg, which ships with the plugin;
 * if the file is missing, the plugin writes it with these defaults the first
 * time it starts):
 *   olds_rush_window  15.0  Seconds after the freeze time during which a
 *                           kill gives the bonus.
 *   olds_rush_hp      25    Health given for an early kill.
 *   olds_rush_hsmult  2     The bonus is multiplied by this for a headshot
 *                           (1 = no extra).
 *   olds_rush_max     150   Health never goes above this (1 - 255). A player
 *                           who already has more keeps it.
 *
 * Rules:
 *   - The window opens when the freeze time ends and stays open for
 *     olds_rush_window seconds. A kill during the freeze time gives nothing.
 *   - Only kills on an enemy by a living killer count: no bonus for team
 *     kills, suicides or deaths caused by the map.
 *   - With mp_freeforall 1 (ReGameDLL_CS) every other player is an enemy.
 *
 * How it works, as the card asks: RG_CSGameRules_OnRoundFreezeEnd (post)
 * records the time the round really starts; RG_CSGameRules_RestartRound
 * (post) closes the window until then. An RG_CBasePlayer_Killed post hook
 * compares get_gametime() with that time and adds the health with
 * set_user_health. The headshot is the game's own m_bHeadshotKilled, the
 * one the kill feed shows. The chat line is in data/lang/olds_rushhp.txt;
 * the heal cue is the stock items/smallmedkit1.wav, played with "spk" for
 * the killer only, so nothing has to be downloaded.
 *
 * Requires AMX Mod X 1.10 with ReAPI (ReGameDLL_CS) and the fun 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 <fun>
#include <reapi>

#pragma semicolon 1

new const PLUGIN_NAME[] = "Early Kill HP Bonus";
new const PLUGIN_VERSION[] = "1.0.0";
new const PLUGIN_AUTHOR[] = "alexit (olds.ro)";

// Stock sound, played on the killer's client with "spk" (no download).
new const HEAL_SOUND[] = "items/smallmedkit1";

new Float:g_window;    // olds_rush_window
new g_bonus;           // olds_rush_hp
new g_headshotMult;    // olds_rush_hsmult
new g_maxHealth;       // olds_rush_max

new g_freeForAllCvar;  // mp_freeforall, 0 if the server has none

// Time the freeze time ended in this round; the window is shut until then.
new Float:g_roundStart;
new bool:g_windowOpen;

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

	// The round and death hooks come from ReGameDLL_CS.
	if (!is_regamedll())
		set_fail_state("ReGameDLL_CS is not running. This plugin needs ReGameDLL_CS and ReAPI.");

	register_dictionary("olds_rushhp.txt");

	bind_pcvar_float(create_cvar("olds_rush_window", "15.0", FCVAR_NONE,
		"Seconds after the freeze time during which a kill gives the health bonus",
		true, 0.0), g_window);

	bind_pcvar_num(create_cvar("olds_rush_hp", "25", FCVAR_NONE,
		"Health given for an early kill",
		true, 0.0, true, 255.0), g_bonus);

	bind_pcvar_num(create_cvar("olds_rush_hsmult", "2", FCVAR_NONE,
		"The bonus is multiplied by this for a headshot (1 = no extra)",
		true, 1.0, true, 10.0), g_headshotMult);

	bind_pcvar_num(create_cvar("olds_rush_max", "150", FCVAR_NONE,
		"Health never goes above this; a player who already has more keeps it",
		true, 1.0, true, 255.0), g_maxHealth);

	AutoExecConfig(true, "olds_rushhp");

	g_freeForAllCvar = get_cvar_pointer("mp_freeforall");

	RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round_post", true);
	RegisterHookChain(RG_CSGameRules_OnRoundFreezeEnd, "on_freeze_end_post", true);
	RegisterHookChain(RG_CBasePlayer_Killed, "on_killed_post", true);
}

/**
 * A new round starts with its freeze time: the window is shut.
 */
public on_restart_round_post()
{
	g_windowOpen = false;
	return HC_CONTINUE;
}

/**
 * The freeze time is over and the round really starts: the window opens.
 */
public on_freeze_end_post()
{
	g_roundStart = get_gametime();
	g_windowOpen = true;
	return HC_CONTINUE;
}

public on_killed_post(victim, killer, gib)
{
	if (!g_windowOpen || get_gametime() - g_roundStart >= g_window)
		return HC_CONTINUE;

	if (!is_enemy_kill(victim, killer) || !is_user_alive(killer))
		return HC_CONTINUE;

	new bool:headshot = bool:get_member(victim, m_bHeadshotKilled);
	new bonus = g_bonus * (headshot ? g_headshotMult : 1);
	new health = get_user_health(killer);
	new newHealth = min(health + bonus, g_maxHealth);

	// Already at the limit (or above it): nothing to add, nothing to say.
	if (newHealth <= health)
		return HC_CONTINUE;

	set_user_health(killer, newHealth);

	client_print_color(killer, print_team_default, "%L", killer, headshot ? "RUSH_BONUS_HS" : "RUSH_BONUS",
		newHealth - health, newHealth);
	client_cmd(killer, "spk %s", HEAL_SOUND);

	return HC_CONTINUE;
}

/**
 * True when a player killed someone of the other team. Suicides, team kills
 * and deaths caused by the map are not enemy kills.
 */
bool:is_enemy_kill(victim, killer)
{
	if (killer == victim || !is_user_connected(killer))
		return false;

	if (g_freeForAllCvar && get_pcvar_num(g_freeForAllCvar))
		return true;

	return get_member(killer, m_iTeam) != get_member(victim, m_iTeam);
}

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.