/*
* Wealth-Scaled Damage (olds.ro workshop card LIB-2031)
*
* The richer the attacker, the harder they hit. Damage a player deals to an
* enemy is multiplied by
*
* 1 + (attacker's money / 1000) x olds_wdmg_perk, at most olds_wdmg_cap
*
* read from the attacker's account at the moment of the hit, so spending the
* money brings the damage straight back down. With the defaults, $16000 gives
* x1.32 and $0 gives the stock damage.
*
* Left unchanged: damage to teammates (friendly fire) and to oneself, damage
* from the world (falls, map hazards), and, with olds_wdmg_knife 0, knife hits.
* In free-for-all (mp_freeforall 1) every other player counts as an enemy.
*
* say /wealth (or say_team /wealth) shows a player's money and multiplier.
*
* Cvars (configs/plugins/olds_wealthdmg.cfg; AutoExecConfig writes that file
* with these defaults if it is missing):
* olds_wdmg_perk 0.02 Damage added per $1000 of the attacker's money (0 - 1; 0.02 = +2%).
* olds_wdmg_cap 1.5 Highest multiplier (1 - 10).
* olds_wdmg_knife 0 1 = knife hits are scaled too, 0 = the knife keeps its stock damage.
*
* Every text players read comes from data/lang/olds_wealthdmg.txt (English).
*
* Requires AMX Mod X 1.10 or newer and ReAPI with ReGameDLL_CS. Written and
* tested on 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 <reapi>
#pragma semicolon 1
new const PLUGIN_NAME[] = "Wealth-Scaled Damage";
new const PLUGIN_VERSION[] = "1.0.0";
new const PLUGIN_AUTHOR[] = "alexit (olds.ro)";
new const DICTIONARY[] = "olds_wealthdmg.txt";
new Float:g_perk; // olds_wdmg_perk
new Float:g_cap; // olds_wdmg_cap
new g_knife; // olds_wdmg_knife
// mp_freeforall of ReGameDLL; stays 0 if the cvar does not exist.
new g_freeForAll;
public plugin_init()
{
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
register_dictionary(DICTIONARY);
bind_pcvar_float(create_cvar("olds_wdmg_perk", "0.02", FCVAR_NONE,
"Damage added per 1000 dollars of the attacker's money (0.02 = +2%)",
true, 0.0, true, 1.0), g_perk);
bind_pcvar_float(create_cvar("olds_wdmg_cap", "1.5", FCVAR_NONE,
"Highest damage multiplier (1 - 10)",
true, 1.0, true, 10.0), g_cap);
bind_pcvar_num(create_cvar("olds_wdmg_knife", "0", FCVAR_NONE,
"1 = knife hits are scaled by money too, 0 = the knife keeps its stock damage",
true, 0.0, true, 1.0), g_knife);
new freeForAll = get_cvar_pointer("mp_freeforall");
if (freeForAll)
bind_pcvar_num(freeForAll, g_freeForAll);
AutoExecConfig(true, "olds_wealthdmg");
register_clcmd("say /wealth", "cmd_wealth");
register_clcmd("say_team /wealth", "cmd_wealth");
RegisterHookChain(RG_CBasePlayer_TakeDamage, "OnPlayerTakeDamage_Pre", false);
}
/**
* Every hit a player takes passes here before the game applies it.
*/
public OnPlayerTakeDamage_Pre(victim, inflictor, attacker, Float:damage, damageBits)
{
// World damage, and damage a player does to themselves.
if (attacker < 1 || attacker > MaxClients || attacker == victim || !is_user_connected(attacker))
return HC_CONTINUE;
// Friendly fire keeps the stock damage.
if (!g_freeForAll && get_member(attacker, m_iTeam) == get_member(victim, m_iTeam))
return HC_CONTINUE;
if (!g_knife && is_knife_hit(inflictor, attacker))
return HC_CONTINUE;
new Float:multiplier = money_multiplier(attacker);
if (multiplier != 1.0)
SetHookChainArg(4, ATYPE_FLOAT, damage * multiplier);
return HC_CONTINUE;
}
public cmd_wealth(id)
{
new money = get_member(id, m_iAccount);
// Rounded to hundredths and shown as whole numbers, so 1.32 (stored as
// 1.3199...) is not cut down to 1.31.
new hundredths = floatround(money_multiplier(id) * 100.0);
client_print_color(id, print_team_default, "^4*^1 %L", id,
g_knife ? "OLDS_WDMG_INFO" : "OLDS_WDMG_INFO_NO_KNIFE", money, hundredths / 100, hundredths % 100);
return PLUGIN_HANDLED;
}
/**
* 1 + (money / 1000) x olds_wdmg_perk, at most olds_wdmg_cap.
*/
Float:money_multiplier(id)
{
new Float:multiplier = 1.0 + float(get_member(id, m_iAccount)) / 1000.0 * g_perk;
return floatmin(multiplier, g_cap);
}
/**
* A knife hit comes from the attacker himself (a grenade blast comes from the
* grenade) while the knife is in his hands.
*/
bool:is_knife_hit(inflictor, attacker)
{
if (inflictor != attacker)
return false;
new item = get_member(attacker, m_pActiveItem);
return item > 0 && get_member(item, m_iId) == WEAPON_KNIFE;
}