/*
* Round Start Money (olds.ro workshop card LIB-1888)
*
* Sets the money a player has when they spawn, with one amount for the
* Terrorists and one for the Counter-Terrorists. A mode cvar decides when
* the amount is applied: every round, only in the first round of the map or
* of a restarted game, only when the player has less, or only for the team
* that lost the last round. Each player is handled at most once per round,
* so a late spawn or a respawn in the same round is not paid twice.
*
* Console command (admins with the ADMIN_CVAR flag, and the server console):
* amx_startmoney <t|ct|all> <amount> Sets the amount for one team or both.
* amx_startmoney Shows the usage and the current values.
* The command changes the cvars until the map changes; lasting values belong
* in the config file below.
*
* Cvars (saved with their descriptions in configs/plugins/olds_startmoney.cfg
* the first time the plugin starts):
* olds_smoney_t 1500 Money of a Terrorist after spawning (0 - 999999).
* olds_smoney_ct 1500 Money of a Counter-Terrorist after spawning (0 - 999999).
* olds_smoney_mode 1 0 = off
* 1 = every round
* 2 = only the first round of the map and the first
* round after a restart (sv_restart,
* sv_restartround, game commencing)
* 3 = every round, but only raises money that is
* lower than the amount, never takes money away
* 4 = like 3, only for the team that lost the last
* round
*
* The amount is never more than the game allows: mp_maxmoney.
*
* How it works, as the card asks: RG_CBasePlayer_Spawn (post) sets the
* money with rg_add_account(AS_SET). It runs after the game has paid the
* round rewards, so the amount set there is the one the player starts with.
* A full restart is read from m_bCompleteReset in RG_CSGameRules_RestartRound
* and the winner of a round from RG_RoundEnd.
*
* Requires AMX Mod X 1.10 with ReAPI (ReGameDLL_CS). 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 <amxmisc>
#include <reapi>
#pragma semicolon 1
new const PLUGIN_NAME[] = "Round Start Money";
new const PLUGIN_VERSION[] = "1.1.0";
new const PLUGIN_AUTHOR[] = "alexit (olds.ro)";
// Highest amount the cvars and the command accept. The game's own limit is
// applied on top of it when the money is set.
const MAX_AMOUNT = 999999;
// Money limit used if mp_maxmoney cannot be found.
const DEFAULT_MAX_MONEY = 16000;
// Value of g_handledRound[] for a player not handled since joining.
const NOT_HANDLED = 0;
enum
{
MODE_OFF,
MODE_ALWAYS,
MODE_FIRST_ROUND,
MODE_RAISE_ONLY,
MODE_LOSING_TEAM
};
new g_amountT; // olds_smoney_t
new g_amountCT; // olds_smoney_ct
new g_mode; // olds_smoney_mode
new g_pcvarAmountT;
new g_pcvarAmountCT;
new g_pcvarMaxMoney;
// Number of the current round on this map. Counts up at every new round.
new g_round = 1;
// Round in which each player was last handled, so nobody is paid twice in
// one round.
new g_handledRound[MAX_PLAYERS + 1];
// The current round is the first one of the map or of a restarted game.
new bool:g_firstRound = true;
// Team that lost the last round, TEAM_UNASSIGNED after a draw or restart.
new TeamName:g_losingTeam = TEAM_UNASSIGNED;
// Team that won the round that is ending, TEAM_UNASSIGNED for a draw.
new TeamName:g_roundWinner = TEAM_UNASSIGNED;
public plugin_init()
{
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR);
g_pcvarAmountT = create_cvar("olds_smoney_t", "1500", FCVAR_NONE,
"Money of a Terrorist after spawning (capped by mp_maxmoney)",
true, 0.0, true, float(MAX_AMOUNT));
bind_pcvar_num(g_pcvarAmountT, g_amountT);
g_pcvarAmountCT = create_cvar("olds_smoney_ct", "1500", FCVAR_NONE,
"Money of a Counter-Terrorist after spawning (capped by mp_maxmoney)",
true, 0.0, true, float(MAX_AMOUNT));
bind_pcvar_num(g_pcvarAmountCT, g_amountCT);
bind_pcvar_num(create_cvar("olds_smoney_mode", "1", FCVAR_NONE,
"0 = off, 1 = every round, 2 = first round of the map and after a restart, 3 = only raise lower money, 4 = like 3 for the team that lost the last round",
true, 0.0, true, 4.0), g_mode);
AutoExecConfig(true, "olds_startmoney");
g_pcvarMaxMoney = get_cvar_pointer("mp_maxmoney");
register_concmd("amx_startmoney", "cmd_startmoney", ADMIN_CVAR,
"<t|ct|all> <amount> - money players have after spawning");
RegisterHookChain(RG_CBasePlayer_Spawn, "fw_player_spawn_post", true);
// Runs at every new round, before the players respawn.
RegisterHookChain(RG_CSGameRules_RestartRound, "fw_restart_round_pre", false);
RegisterHookChain(RG_RoundEnd, "fw_round_end_post", true);
}
public client_disconnected(id)
{
// The slot may go to a new player, who must be paid on their first spawn.
g_handledRound[id] = NOT_HANDLED;
}
public fw_round_end_post(WinStatus:status, ScenarioEventEndRound:event, Float:delay)
{
// The game may refuse to end the round; then nothing changes.
if (!GetHookChainReturn(ATYPE_BOOL))
return HC_CONTINUE;
switch (status)
{
case WINSTATUS_TERRORISTS: g_roundWinner = TEAM_TERRORIST;
case WINSTATUS_CTS: g_roundWinner = TEAM_CT;
default: g_roundWinner = TEAM_UNASSIGNED;
}
return HC_CONTINUE;
}
public fw_restart_round_pre()
{
g_round++;
// sv_restart, sv_restartround and the restart when the game commences
// all reset the whole game.
g_firstRound = bool:get_member_game(m_bCompleteReset);
// A restarted game has no last round. After a draw nobody lost.
if (g_firstRound || g_roundWinner == TEAM_UNASSIGNED)
g_losingTeam = TEAM_UNASSIGNED;
else
g_losingTeam = (g_roundWinner == TEAM_TERRORIST) ? TEAM_CT : TEAM_TERRORIST;
g_roundWinner = TEAM_UNASSIGNED;
return HC_CONTINUE;
}
public fw_player_spawn_post(const id)
{
// Spawn also runs for a player who has only just connected and is not
// in the game yet; that is not a spawn into the round.
if (g_mode == MODE_OFF || !is_user_alive(id) || g_handledRound[id] == g_round)
return HC_CONTINUE;
new TeamName:team = get_member(id, m_iTeam);
if (team != TEAM_TERRORIST && team != TEAM_CT)
return HC_CONTINUE;
// Once per round, whatever the mode decides below.
g_handledRound[id] = g_round;
if (g_mode == MODE_FIRST_ROUND && !g_firstRound)
return HC_CONTINUE;
if (g_mode == MODE_LOSING_TEAM && team != g_losingTeam)
return HC_CONTINUE;
new amount = min(team == TEAM_TERRORIST ? g_amountT : g_amountCT, max_money());
new money = get_member(id, m_iAccount);
if ((g_mode == MODE_RAISE_ONLY || g_mode == MODE_LOSING_TEAM) && money >= amount)
return HC_CONTINUE;
if (money != amount)
rg_add_account(id, amount, AS_SET);
return HC_CONTINUE;
}
public cmd_startmoney(id, level, cid)
{
if (!cmd_access(id, level, cid, 1))
return PLUGIN_HANDLED;
if (read_argc() < 3)
{
console_print(id, "Usage: amx_startmoney <t|ct|all> <amount from 0 to %d>", MAX_AMOUNT);
console_print(id, "Now: Terrorists %d, Counter-Terrorists %d, mode %d, money limit %d.",
g_amountT, g_amountCT, g_mode, max_money());
return PLUGIN_HANDLED;
}
new teamArg[8], amountArg[12];
read_argv(1, teamArg, charsmax(teamArg));
read_argv(2, amountArg, charsmax(amountArg));
new bool:setT, bool:setCT, teamName[24];
if (equali(teamArg, "t"))
{
setT = true;
copy(teamName, charsmax(teamName), "Terrorists");
}
else if (equali(teamArg, "ct"))
{
setCT = true;
copy(teamName, charsmax(teamName), "Counter-Terrorists");
}
else if (equali(teamArg, "all"))
{
setT = true;
setCT = true;
copy(teamName, charsmax(teamName), "both teams");
}
else
{
console_print(id, "Unknown team ^"%s^". Use t, ct or all.", teamArg);
return PLUGIN_HANDLED;
}
// Digits only, at most six of them, so "-5", "1e3", "12abc" or a number
// too long for the buffer are refused instead of being read as something else.
new length = strlen(amountArg);
if (length == 0 || length > 6 || !is_str_num(amountArg))
{
console_print(id, "The amount must be a whole number from 0 to %d.", MAX_AMOUNT);
return PLUGIN_HANDLED;
}
new amount = str_to_num(amountArg);
if (setT)
set_pcvar_num(g_pcvarAmountT, amount);
if (setCT)
set_pcvar_num(g_pcvarAmountCT, amount);
console_print(id, "Start money for %s set to %d. It applies from the next spawn.", teamName, amount);
new limit = max_money();
if (amount > limit)
console_print(id, "Players get at most %d, the money limit of this server.", limit);
new name[MAX_NAME_LENGTH], authid[MAX_AUTHID_LENGTH];
get_user_name(id, name, charsmax(name));
get_user_authid(id, authid, charsmax(authid));
log_amx("^"%s<%d><%s>^" set the start money for %s to %d",
name, id ? get_user_userid(id) : 0, authid, teamName, amount);
return PLUGIN_HANDLED;
}
/**
* The most money a player can hold on this server.
*/
max_money()
{
if (!g_pcvarMaxMoney)
return DEFAULT_MAX_MONEY;
return max(get_pcvar_num(g_pcvarMaxMoney), 0);
}