Skip to content
View in the app

A better way to browse. Learn more.

Learn more

double-kill-reward/addons/amxmodx/scripting/olds_doublekill.sma

olds_doublekill.sma
284 lines · 8.2 KB · Pawn (AMX Mod X)
Raw
/*
 * Double Kill Reward (olds.ro workshop card LIB-0222)
 *
 * For a short window in each round every kill counts double: the killer
 * gets one extra frag and some extra money on top of the game's own reward.
 * The window opens when the round starts or with the round's first kill,
 * and a HUD line shows everyone how many seconds are left.
 *
 * Commands: none.
 *
 * Cvars (in configs/plugins/olds_doublekill.cfg, which ships with the
 * plugin; if the file is missing, the plugin writes it with these defaults
 * the first time it starts):
 *   olds_dk_start     1     1 = the window opens when the round starts (the
 *                           end of the freeze time); 2 = it opens with the
 *                           round's first kill (that kill itself counts
 *                           once).
 *   olds_dk_time      20    Seconds the window stays open.
 *   olds_dk_money     300   Extra money for a kill in the window.
 *   olds_dk_headshot  0     1 = only headshot kills count double.
 *
 * Rules:
 *   - Only kills on an enemy count double. A team kill gets no bonus and
 *     the game's own team-kill penalty applies as usual.
 *   - The window opens at most once per round. A new round shuts it and
 *     clears the HUD; it then opens again as olds_dk_start says.
 *   - Money never goes above mp_maxmoney (16000 by default).
 *   - With mp_freeforall 1 (ReGameDLL_CS) every other player is an enemy.
 *
 * How it works, as the card asks: an RG_CBasePlayer_Killed post hook adds
 * the frag with set_user_frags (and refreshes the scoreboard with the
 * game's ScoreInfo message) and the money with cs_set_user_money. The
 * window is reset in RG_CSGameRules_RestartRound and, with olds_dk_start 1,
 * opened in RG_CSGameRules_OnRoundFreezeEnd. The timer is a set_hudmessage
 * line on HUD channel 2, redrawn every second. The bonus cue is the stock
 * buttons/bell1.wav, played with emit_sound from the killer. The texts are
 * in data/lang/olds_doublekill.txt.
 *
 * Requires AMX Mod X 1.10 with ReAPI (ReGameDLL_CS) and the cstrike and fun
 * modules. 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 <cstrike>
#include <fun>
#include <reapi>

#pragma semicolon 1

new const PLUGIN_NAME[] = "Double Kill Reward";
new const PLUGIN_VERSION[] = "1.0.0";
new const PLUGIN_AUTHOR[] = "alexit (olds.ro)";

// Stock Half-Life sound, already on every client.
new const BONUS_SOUND[] = "buttons/bell1.wav";

// The timer line uses HUD channel 2, as the card asks.
const HUD_CHANNEL = 2;

const TASK_TIMER = 22200;

// Money limit when the server has no mp_maxmoney cvar.
const DEFAULT_MAX_MONEY = 16000;

// Values of olds_dk_start.
enum
{
	START_AT_ROUND_START = 1,
	START_AT_FIRST_KILL
};

new g_start;           // olds_dk_start
new g_windowTime;      // olds_dk_time
new g_money;           // olds_dk_money
new g_headshotOnly;    // olds_dk_headshot

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

new bool:g_windowOpen;
new bool:g_windowUsed;   // the window already opened this round
new Float:g_windowEnd;

public plugin_precache()
{
	precache_sound(BONUS_SOUND);
}

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

	// The death and round 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_doublekill.txt");

	bind_pcvar_num(create_cvar("olds_dk_start", "1", FCVAR_NONE,
		"1 = the window opens when the round starts; 2 = it opens with the round's first kill",
		true, 1.0, true, 2.0), g_start);

	bind_pcvar_num(create_cvar("olds_dk_time", "20", FCVAR_NONE,
		"Seconds the double kill window stays open",
		true, 1.0, true, 600.0), g_windowTime);

	bind_pcvar_num(create_cvar("olds_dk_money", "300", FCVAR_NONE,
		"Extra money for a kill in the window",
		true, 0.0), g_money);

	bind_pcvar_num(create_cvar("olds_dk_headshot", "0", FCVAR_NONE,
		"1 = only headshot kills count double",
		true, 0.0, true, 1.0), g_headshotOnly);

	AutoExecConfig(true, "olds_doublekill");

	g_maxMoneyCvar = get_cvar_pointer("mp_maxmoney");
	g_freeForAllCvar = get_cvar_pointer("mp_freeforall");
	g_msgScoreInfo = get_user_msgid("ScoreInfo");

	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: the window is shut and its HUD line cleared.
 */
public on_restart_round_post()
{
	close_window();
	g_windowUsed = false;
	return HC_CONTINUE;
}

/**
 * The freeze time is over: with olds_dk_start 1 the window opens now.
 */
public on_freeze_end_post()
{
	if (g_start == START_AT_ROUND_START && !g_windowUsed)
		open_window();

	return HC_CONTINUE;
}

public on_killed_post(victim, killer, gib)
{
	if (!is_enemy_kill(victim, killer))
		return HC_CONTINUE;

	if (!g_windowOpen)
	{
		// The round's first kill opens the window; it counts once itself.
		if (g_start == START_AT_FIRST_KILL && !g_windowUsed)
			open_window();

		return HC_CONTINUE;
	}

	if (get_gametime() >= g_windowEnd)
		return HC_CONTINUE;

	new bool:headshot = bool:get_member(victim, m_bHeadshotKilled);

	if (g_headshotOnly && !headshot)
		return HC_CONTINUE;

	// The game has already counted the kill once; this is the second frag.
	set_user_frags(killer, get_user_frags(killer) + 1);
	update_scoreboard(killer);

	if (g_money > 0)
	{
		// Capped at mp_maxmoney, but money that is already higher is never
		// lowered.
		new money = cs_get_user_money(killer);
		cs_set_user_money(killer, max(money, min(money + g_money, max_money())));
	}

	emit_sound(killer, CHAN_ITEM, BONUS_SOUND, VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
	client_print_color(killer, print_team_default, "%L", killer, headshot ? "DK_BONUS_HS" : "DK_BONUS", g_money);

	return HC_CONTINUE;
}

open_window()
{
	g_windowOpen = true;
	g_windowUsed = true;
	g_windowEnd = get_gametime() + float(g_windowTime);

	client_print_color(0, print_team_default, "%L", LANG_PLAYER, "DK_OPEN", g_windowTime);

	remove_task(TASK_TIMER);
	set_task(1.0, "task_timer", TASK_TIMER, _, _, "b");
	show_timer(g_windowTime);
}

close_window()
{
	remove_task(TASK_TIMER);

	if (g_windowOpen)
	{
		g_windowOpen = false;

		// An empty message on the same channel wipes the timer line.
		set_hudmessage(0, 0, 0, -1.0, 0.20, 0, 0.0, 0.1, 0.0, 0.0, HUD_CHANNEL);
		show_hudmessage(0, "");
	}
}

public task_timer()
{
	new left = floatround(g_windowEnd - get_gametime(), floatround_ceil);

	if (left <= 0)
	{
		close_window();
		return;
	}

	show_timer(left);
}

show_timer(seconds)
{
	set_hudmessage(255, 160, 0, -1.0, 0.20, 0, 0.0, 1.1, 0.0, 0.0, HUD_CHANNEL);
	show_hudmessage(0, "%L", LANG_PLAYER, "DK_HUD", seconds);
}

/**
 * Sends the killer's new score to every client, as the game does after a
 * kill.
 */
update_scoreboard(id)
{
	message_begin(MSG_BROADCAST, g_msgScoreInfo);
	write_byte(id);
	write_short(get_user_frags(id));
	write_short(get_member(id, m_iDeaths));
	write_short(0);
	write_short(get_member(id, m_iTeam));
	message_end();
}

/**
 * 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);
}

max_money()
{
	if (g_maxMoneyCvar)
		return get_pcvar_num(g_maxMoneyCvar);

	return DEFAULT_MAX_MONEY;
}

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.