View Single Post
Author Message
AnimalMonster
Senior Member
Join Date: May 2020
Old 09-21-2022 , 11:38   [Sketch] CSO Like Money System Prototype
Reply With Quote #1

A reapi approach for a money system like in cso which was pretty popular back then.

Code:
#include <amxmodx>
#include <reapi>

#define MONEY_MULHEAD 1.0
#define MONEY_MULLEG 0.75
#define MONEY_MULARM 0.75
#define MONEY_MULSTOMACH 0.6
#define MONEY_MULCHEST 0.65

#define MONEY_KILL 500
#define MONEY_HIT 2

#define MONEY_START 2000

#define MONEY_MULVIC 0.65

public plugin_init()
{
	register_plugin("Money", "-", "-")

	for(new RewardRules:i = RR_CTS_WIN; i < RR_END+RewardRules:1; i++)
		rg_set_account_rules(i, 0)

	RegisterHookChain(RG_CBasePlayer_Killed, "ReHook_Killed", 1)
	RegisterHookChain(RG_CBasePlayer_TakeDamage, "ReHook_TakeDamage_Post", 1)
        RegisterHookChain(RG_CBasePlayer_AddAccount, "ReHook_AddAccount_Pre")
}

public ReHook_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:flDamage, dmgBits)
{
	if(iVictim == iAttacker)
		return HC_CONTINUE;

	if(get_user_team(iVictim) == get_user_team(iAttacker))
		return HC_CONTINUE;

	if(!is_user_alive(iVictim))
		return HC_CONTINUE;

	if(!(0 < iAttacker < 33) || !(0 < iVictim < 33))
		return HC_CONTINUE;

	new addMoney = floatround(flDamage*MONEY_HIT)

	switch(get_member(iVictim, m_LastHitGroup))
	{
		case HIT_STOMACH: addMoney = floatround(addMoney*MONEY_MULSTOMACH)
		case HIT_CHEST: addMoney = floatround(addMoney*MONEY_MULCHEST)
		case HIT_LEFTLEG, HIT_RIGHTLEG: addMoney = floatround(addMoney*MONEY_MULLEG)
		case HIT_LEFTARM, HIT_RIGHTARM: addMoney = floatround(addMoney*MONEY_MULARM)
		case HIT_HEAD: addMoney = floatround(addMoney*MONEY_MULHEAD)
	}

	rg_add_account(iAttacker, addMoney, AS_ADD)
	rg_add_account(iVictim, floatround(addMoney*MONEY_MULVIC), AS_ADD)

	return HC_CONTINUE;
}

public ReHook_Killed(iId, iAttacker)
{
	rg_add_account(iAttacker, MONEY_KILL, AS_ADD)
}

public ReHook_AddAccount_Pre(id, amount, RewardType:type, bool:bTrackChange)
{
	if(type == RT_NONE)
		return HC_CONTINUE;

	return HC_SUPERCEDE;
}

GetMoney(iId) return get_member(iId, m_iLastAccount)
SetMoney(iId, amount) rg_add_account(iId, amount, AS_SET)
AddMoney(iId, amount) rg_add_account(iId, amount)

Last edited by AnimalMonster; 09-23-2022 at 11:12.
AnimalMonster is offline