Skip to content
View in the app

A better way to browse. Learn more.

Learn more

unlimited-money-mode/addons/amxmodx/scripting/olds_umoney.sma

olds_umoney.sma
292 lines · 8.3 KB · Pawn (AMX Mod X)
Raw
/*
 * Unlimited Money Mode (olds.ro workshop card LIB-2005)
 *
 * For fun servers where buying is not the point: players keep a fixed amount
 * of money, and the money line can be hidden from their HUD.
 *
 *   olds_umoney_mode 1   Every player of the chosen team(s) has the account
 *                        set to olds_umoney_amount when they spawn, and again
 *                        on the next frame after every purchase.
 *   olds_umoney_mode 2   The same, and the money line is hidden from their
 *                        HUD (the HideWeapon message with flag 32, money).
 *                        Buying works as usual.
 *   olds_umoney_mode 0   Off: normal economy for everyone.
 *
 * Players with the fixed amount get no kill reward (unless olds_umoney_kill
 * is 1), and lose no money to penalties: killing a teammate, hurting or
 * killing a hostage. Players of the other team keep the normal economy.
 *
 * Purchases are caught where the game charges them (RG_CBasePlayer_AddAccount
 * with RT_PLAYER_BOUGHT_SOMETHING), which covers weapons, ammo, armour,
 * grenades, the defuse kit, night vision and the shield, from the buy menu,
 * a buy command, autobuy or rebuy.
 *
 * Cvars (configs/plugins/olds_umoney.cfg; AutoExecConfig writes that file
 * with these defaults if it is missing):
 *   olds_umoney_mode   1      0 = off, 1 = fixed money, 2 = fixed money and the money line hidden.
 *   olds_umoney_amount 16000  The fixed amount (0 - 999999; the game caps it at mp_maxmoney).
 *   olds_umoney_team   3      Who gets it: 1 = Terrorists, 2 = Counter-Terrorists, 3 = both.
 *   olds_umoney_kill   0      1 = kill rewards are still paid, 0 = no kill reward.
 *
 * Players see no text from this plugin. The one server console notice comes
 * from data/lang/olds_umoney.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 <amxmisc>
#include <reapi>

#pragma semicolon 1

new const PLUGIN_NAME[] = "Unlimited Money Mode";
new const PLUGIN_VERSION[] = "1.0.0";
new const PLUGIN_AUTHOR[] = "alexit (olds.ro)";

new const DICTIONARY[] = "olds_umoney.txt";

enum
{
	MODE_OFF = 0,
	MODE_FIXED,          // fixed money
	MODE_FIXED_HIDDEN    // fixed money, money line hidden
};

// olds_umoney_team bits.
const TEAM_BIT_T = 1;
const TEAM_BIT_CT = 2;

new g_mode;          // olds_umoney_mode
new g_amount;        // olds_umoney_amount
new g_teams;         // olds_umoney_team
new g_killReward;    // olds_umoney_kill

new g_msgHideWeapon;

// The player's HUD was last told to hide the money line.
new bool:g_moneyHidden[MAX_PLAYERS + 1];

// A refill is already waiting for the next frame.
new bool:g_refillPending[MAX_PLAYERS + 1];

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

	new pcvar = create_cvar("olds_umoney_mode", "1", FCVAR_NONE,
		"0 = off, 1 = players keep a fixed amount of money, 2 = the same and the money line is hidden from the HUD",
		true, 0.0, true, 2.0);
	bind_pcvar_num(pcvar, g_mode);
	hook_cvar_change(pcvar, "OnHudCvarChange");

	bind_pcvar_num(create_cvar("olds_umoney_amount", "16000", FCVAR_NONE,
		"The fixed amount of money (the game caps it at mp_maxmoney, 16000 by default)",
		true, 0.0, true, 999999.0), g_amount);

	pcvar = create_cvar("olds_umoney_team", "3", FCVAR_NONE,
		"Who gets the fixed money: 1 = Terrorists, 2 = Counter-Terrorists, 3 = both teams",
		true, 1.0, true, 3.0);
	bind_pcvar_num(pcvar, g_teams);
	hook_cvar_change(pcvar, "OnHudCvarChange");

	bind_pcvar_num(create_cvar("olds_umoney_kill", "0", FCVAR_NONE,
		"1 = players with the fixed money still get kill rewards, 0 = no kill reward",
		true, 0.0, true, 1.0), g_killReward);

	AutoExecConfig(true, "olds_umoney");

	RegisterHookChain(RG_CBasePlayer_Spawn, "OnPlayerSpawn_Post", true);
	RegisterHookChain(RG_CBasePlayer_AddAccount, "OnAddAccount_Pre", false);

	g_msgHideWeapon = get_user_msgid("HideWeapon");
	register_message(g_msgHideWeapon, "OnHideWeaponMessage");
}

public OnConfigsExecuted()
{
	if (g_mode == MODE_OFF)
		return;

	new maxMoney = get_cvar_pointer("mp_maxmoney");

	if (!maxMoney)
		return;

	new limit = get_pcvar_num(maxMoney);

	if (g_amount > limit)
		server_print("[%s] %L", PLUGIN_NAME, LANG_SERVER, "OLDS_UMONEY_ABOVE_MAX", g_amount, limit, limit);
}

public client_disconnected(id)
{
	g_moneyHidden[id] = false;
	g_refillPending[id] = false;
}

public OnPlayerSpawn_Post(id)
{
	if (!is_user_alive(id))
		return;

	if (has_fixed_money(id))
		rg_add_account(id, g_amount, AS_SET, false);

	// The game sends its own HideWeapon after a spawn as well; this one makes
	// sure the money line is in the state the settings ask for.
	new bool:hide = wants_money_hidden(id);

	if (hide || g_moneyHidden[id])
		send_money_line(id, hide);
}

/**
 * Every change of a player's account passes here first.
 */
public OnAddAccount_Pre(id, amount, RewardType:type, bool:trackChange)
{
	if (!has_fixed_money(id))
		return HC_CONTINUE;

	switch (type)
	{
		case RT_PLAYER_BOUGHT_SOMETHING:
		{
			// The game is charging a purchase: put the fixed amount back once
			// the whole purchase is done. One refill per frame is enough.
			if (!g_refillPending[id])
			{
				g_refillPending[id] = true;
				RequestFrame("refill_account", get_user_userid(id));
			}
		}
		case RT_ENEMY_KILLED, RT_VIP_KILLED:
		{
			if (!g_killReward && amount > 0)
				return HC_SUPERCEDE;
		}
		case RT_TEAMMATES_KILLED, RT_HOSTAGE_DAMAGED, RT_HOSTAGE_KILLED:
		{
			if (amount < 0)
				return HC_SUPERCEDE;
		}
	}

	return HC_CONTINUE;
}

public refill_account(userid)
{
	new id = find_player_ex(FindPlayer_MatchUserId, userid);

	if (!id)
		return;

	g_refillPending[id] = false;

	if (has_fixed_money(id))
		rg_add_account(id, g_amount, AS_SET, false);
}

/**
 * The game tells a client which HUD parts to hide. For a player whose money
 * line should be hidden, the money flag is added, so the game's own updates
 * (spawn, death, spectating) never bring it back.
 */
public OnHideWeaponMessage(msgId, msgDest, receiver)
{
	if (receiver < 1 || receiver > MaxClients || !is_user_connected(receiver))
		return PLUGIN_CONTINUE;

	new flags = get_msg_arg_int(1);

	if (wants_money_hidden(receiver))
	{
		flags |= HIDEHUD_MONEY;
		set_msg_arg_int(1, ARG_BYTE, flags);
	}

	g_moneyHidden[receiver] = (flags & HIDEHUD_MONEY) != 0;
	return PLUGIN_CONTINUE;
}

/**
 * olds_umoney_mode or olds_umoney_team changed: show or hide the money line
 * of everyone in game on the next frame, when the bound values are current.
 */
public OnHudCvarChange(pcvar, const oldValue[], const newValue[])
{
	RequestFrame("refresh_money_lines");
}

public refresh_money_lines()
{
	new players[MAX_PLAYERS], count;
	get_players_ex(players, count, GetPlayers_ExcludeHLTV);

	for (new i = 0; i < count; i++)
	{
		new id = players[i];
		new bool:hide = wants_money_hidden(id);

		if (hide != g_moneyHidden[id])
			send_money_line(id, hide);
	}
}

/**
 * Sends the HideWeapon message with the game's own HUD flags for the player,
 * plus the money flag when the money line should be hidden.
 */
send_money_line(id, bool:hide)
{
	new flags = get_member(id, m_iHideHUD);

	if (hide)
		flags |= HIDEHUD_MONEY;
	else
		flags &= ~HIDEHUD_MONEY;

	message_begin(MSG_ONE, g_msgHideWeapon, _, id);
	write_byte(flags);
	message_end();

	g_moneyHidden[id] = hide;
}

bool:has_fixed_money(id)
{
	return g_mode != MODE_OFF && team_is_chosen(id);
}

bool:wants_money_hidden(id)
{
	return g_mode == MODE_FIXED_HIDDEN && team_is_chosen(id);
}

bool:team_is_chosen(id)
{
	switch (get_member(id, m_iTeam))
	{
		case TEAM_TERRORIST: return (g_teams & TEAM_BIT_T) != 0;
		case TEAM_CT: return (g_teams & TEAM_BIT_CT) != 0;
	}

	return false;
}

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.