/*
* First Kill Money Bonus (olds.ro workshop card LIB-0277)
*
* The first player who kills an enemy in a round gets a money bonus, and a
* little more when that kill is a headshot. Everyone is told in chat who it
* was, with a bell sound. Team kills, suicides and deaths caused by the map
* do not count: the next real kill on an enemy is then the first kill.
*
* Commands: none.
*
* Cvars (in configs/plugins/olds_firstkill.cfg, which ships with the plugin;
* if the file is missing, the plugin writes it with these defaults the first
* time it starts):
* olds_fkm_bonus 1000 Money for the first kill of the round.
* olds_fkm_hs_extra 500 Extra money when that kill is a headshot.
* olds_fkm_announce 1 1 = tell everyone in chat who made the first
* kill, with a bell sound; 0 = silent.
* olds_fkm_minplayers 4 The bonus is paid only when at least this many
* players are on the two teams (bots count).
* 0 = always.
*
* Rules:
* - Only the first kill of a round on an enemy counts, and only while the
* round is being played (not after it has been won).
* - When too few players are on the teams, the first kill still uses up
* the round's bonus, but nothing is paid or announced.
* - Money never goes above the server's 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 checks
* the round's first-kill flag and that the killer is an enemy player, then
* pays with cs_get_user_money / cs_set_user_money. The flag is cleared in
* RG_CSGameRules_RestartRound. The headshot is the game's own m_bHeadshotKilled,
* the same one the kill feed shows. The chat text is in
* data/lang/olds_firstkill.txt; the bell is the stock buttons/bell1.wav,
* played with "spk" on each client, so nothing has to be downloaded.
*
* Requires AMX Mod X 1.10 with ReAPI (ReGameDLL_CS) and the cstrike module.
* Written and tested on 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 <reapi>
#pragma semicolon 1
new const PLUGIN_NAME[] = "First Kill Money Bonus";
new const PLUGIN_VERSION[] = "1.0.0";
new const PLUGIN_AUTHOR[] = "alexit (olds.ro)";
// Stock Half-Life sound, played on each client with "spk" (no download).
new const BELL_SOUND[] = "buttons/bell1";
// Money limit when the server has no mp_maxmoney cvar.
const DEFAULT_MAX_MONEY = 16000;
new g_bonus; // olds_fkm_bonus
new g_headshotExtra; // olds_fkm_hs_extra
new g_announce; // olds_fkm_announce
new g_minPlayers; // olds_fkm_minplayers
new g_maxMoneyCvar; // mp_maxmoney, 0 if the server has none
new g_freeForAllCvar; // mp_freeforall, 0 if the server has none
// Set once the round's first kill on an enemy has happened.
new bool:g_firstKillDone;
// For each victim: the round was already won when the death began.
new bool:g_roundOverAtDeath[MAX_PLAYERS + 1];
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_firstkill.txt");
bind_pcvar_num(create_cvar("olds_fkm_bonus", "1000", FCVAR_NONE,
"Money for the first kill of the round",
true, 0.0), g_bonus);
bind_pcvar_num(create_cvar("olds_fkm_hs_extra", "500", FCVAR_NONE,
"Extra money when the first kill is a headshot",
true, 0.0), g_headshotExtra);
bind_pcvar_num(create_cvar("olds_fkm_announce", "1", FCVAR_NONE,
"1 = tell everyone in chat who made the first kill, with a bell sound; 0 = silent",
true, 0.0, true, 1.0), g_announce);
bind_pcvar_num(create_cvar("olds_fkm_minplayers", "4", FCVAR_NONE,
"Players needed on the two teams (bots count) for the bonus to be paid; 0 = always",
true, 0.0, true, float(MAX_PLAYERS)), g_minPlayers);
AutoExecConfig(true, "olds_firstkill");
g_maxMoneyCvar = get_cvar_pointer("mp_maxmoney");
g_freeForAllCvar = get_cvar_pointer("mp_freeforall");
RegisterHookChain(RG_CBasePlayer_Killed, "on_killed_pre", false);
RegisterHookChain(RG_CBasePlayer_Killed, "on_killed_post", true);
RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round_post", true);
}
/**
* A new round: its first kill is still to come.
*/
public on_restart_round_post()
{
g_firstKillDone = false;
return HC_CONTINUE;
}
/**
* Notes whether the round was already won before this death. The death that
* wins the round ends it inside the game's own code, so this is read first.
*/
public on_killed_pre(victim, killer, gib)
{
g_roundOverAtDeath[victim] = bool:get_member_game(m_bRoundTerminating);
return HC_CONTINUE;
}
public on_killed_post(victim, killer, gib)
{
if (g_firstKillDone || g_roundOverAtDeath[victim] || !is_enemy_kill(victim, killer))
return HC_CONTINUE;
// This is the round's first kill, whether or not it is paid.
g_firstKillDone = true;
if (count_team_players() < g_minPlayers)
return HC_CONTINUE;
new bool:headshot = bool:get_member(victim, m_bHeadshotKilled);
new reward = g_bonus + (headshot ? g_headshotExtra : 0);
if (reward > 0)
{
// Capped at mp_maxmoney, but money that is already higher (given by
// an admin or another plugin) is never lowered.
new money = cs_get_user_money(killer);
cs_set_user_money(killer, max(money, min(money + reward, max_money())));
}
if (g_announce)
{
new name[MAX_NAME_LENGTH];
get_user_name(killer, name, charsmax(name));
client_print_color(0, killer, "%L", LANG_PLAYER, headshot ? "FKM_FIRST_KILL_HS" : "FKM_FIRST_KILL",
name, reward);
client_cmd(0, "spk %s", BELL_SOUND);
}
return HC_CONTINUE;
}
/**
* True when a player killed someone of the other team. Suicides, team kills
* and deaths caused by the map or a falling player 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);
}
/**
* Players on the Terrorist and Counter-Terrorist teams, alive or dead.
*/
count_team_players()
{
new count;
for (new id = 1; id <= MaxClients; id++)
{
if (!is_user_connected(id))
continue;
new TeamName:team = TeamName:get_member(id, m_iTeam);
if (team == TEAM_TERRORIST || team == TEAM_CT)
count++;
}
return count;
}
max_money()
{
if (g_maxMoneyCvar)
return get_pcvar_num(g_maxMoneyCvar);
return DEFAULT_MAX_MONEY;
}