Skip to content
View in the app

A better way to browse. Learn more.

Learn more

bomb-plant-reward/addons/amxmodx/scripting/olds_plantreward.sma

olds_plantreward.sma
192 lines · 5.8 KB · Pawn (AMX Mod X)
Raw
/*
 * Bomb Plant Reward (olds.ro workshop card LIB-0116)
 *
 * The player who plants the bomb gets money and frags at once, on top of
 * what the game itself gives. Optionally the player who defuses it is
 * rewarded too.
 *
 * Commands: none.
 *
 * Cvars (in configs/plugins/olds_plantreward.cfg, which ships with the
 * plugin; if the file is missing, the plugin writes it with these defaults
 * the first time it starts):
 *   olds_pr_money   300  Money for planting the bomb.
 *   olds_pr_frags   1    Frags for planting the bomb (and for defusing it,
 *                        with olds_pr_both 1).
 *   olds_pr_both    0    1 = the defuser is rewarded too.
 *   olds_pr_defuse  300  Money for defusing the bomb (with olds_pr_both 1).
 *
 * Rules:
 *   - One plant reward and one defuse reward per round at most, whoever
 *     plants or defuses.
 *   - Money never goes above mp_maxmoney (16000 by default); money that is
 *     already higher is not lowered.
 *   - Bots are rewarded the same way as players.
 *
 * How it works, as the card asks: an RG_PlantBomb post hook (the game's own
 * function that creates the planted bomb) pays the planter with
 * cs_set_user_money, adds the frags and sends the game's ScoreInfo message
 * so the scoreboard shows them at once. RG_CGrenade_DefuseBombEnd (post,
 * only when the bomb was really defused) does the same for the defuser.
 * The round's flags are cleared in RG_CSGameRules_RestartRound. The chat
 * text is in data/lang/olds_plantreward.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[] = "Bomb Plant Reward";
new const PLUGIN_VERSION[] = "1.0.0";
new const PLUGIN_AUTHOR[] = "alexit (olds.ro)";

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

new g_plantMoney;      // olds_pr_money
new g_frags;           // olds_pr_frags
new g_rewardDefuse;    // olds_pr_both
new g_defuseMoney;     // olds_pr_defuse

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

// The round's plant and defuse have been rewarded.
new bool:g_plantPaid;
new bool:g_defusePaid;

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

	// The bomb 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_plantreward.txt");

	bind_pcvar_num(create_cvar("olds_pr_money", "300", FCVAR_NONE,
		"Money for planting the bomb",
		true, 0.0), g_plantMoney);

	bind_pcvar_num(create_cvar("olds_pr_frags", "1", FCVAR_NONE,
		"Frags for planting the bomb (and for defusing it with olds_pr_both 1)",
		true, 0.0, true, 100.0), g_frags);

	bind_pcvar_num(create_cvar("olds_pr_both", "0", FCVAR_NONE,
		"1 = the player who defuses the bomb is rewarded too",
		true, 0.0, true, 1.0), g_rewardDefuse);

	bind_pcvar_num(create_cvar("olds_pr_defuse", "300", FCVAR_NONE,
		"Money for defusing the bomb (with olds_pr_both 1)",
		true, 0.0), g_defuseMoney);

	AutoExecConfig(true, "olds_plantreward");

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

	RegisterHookChain(RG_PlantBomb, "on_plant_bomb_post", true);
	RegisterHookChain(RG_CGrenade_DefuseBombEnd, "on_defuse_end_post", true);
	RegisterHookChain(RG_CSGameRules_RestartRound, "on_restart_round_post", true);
}

/**
 * A new round: both rewards can be earned again.
 */
public on_restart_round_post()
{
	g_plantPaid = false;
	g_defusePaid = false;
	return HC_CONTINUE;
}

/**
 * The game has just created the planted bomb for this player.
 */
public on_plant_bomb_post(planter, Float:origin[3], Float:velocity[3])
{
	// No bomb was created: nothing was planted.
	if (GetHookChainReturn(ATYPE_INTEGER) <= 0)
		return HC_CONTINUE;

	if (g_plantPaid || !is_user_connected(planter))
		return HC_CONTINUE;

	g_plantPaid = true;
	reward(planter, g_plantMoney, "PR_PLANTED");
	return HC_CONTINUE;
}

/**
 * Defusing has ended; only a finished defuse is rewarded.
 */
public on_defuse_end_post(bomb, defuser, bool:defused)
{
	if (!defused || !g_rewardDefuse || g_defusePaid || !is_user_connected(defuser))
		return HC_CONTINUE;

	g_defusePaid = true;
	reward(defuser, g_defuseMoney, "PR_DEFUSED");
	return HC_CONTINUE;
}

reward(id, money, const key[])
{
	if (money > 0)
	{
		new current = cs_get_user_money(id);
		cs_set_user_money(id, max(current, min(current + money, max_money())));
	}

	if (g_frags > 0)
	{
		set_user_frags(id, get_user_frags(id) + g_frags);
		update_scoreboard(id);
	}

	client_print_color(id, print_team_default, "%L", id, key, money, g_frags);
}

/**
 * Sends the player'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();
}

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.