From 2ed679b1494620343a5acb82498af6a08273f109 Mon Sep 17 00:00:00 2001 From: Lorenc Pekaj Date: Tue, 1 Jan 2019 22:01:46 +1100 Subject: [PATCH] add OnPlayerMoneyChanged callback --- gamemodes/irresistible/anticheat/money.pwn | 48 ++++++++++++++++++---- gamemodes/sf-cnr.pwn | 5 +++ 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/gamemodes/irresistible/anticheat/money.pwn b/gamemodes/irresistible/anticheat/money.pwn index 7b37be6..412985b 100644 --- a/gamemodes/irresistible/anticheat/money.pwn +++ b/gamemodes/irresistible/anticheat/money.pwn @@ -19,6 +19,9 @@ static stock p_Cash [ MAX_PLAYERS ]; +/* ** Forwards ** */ +forward OnPlayerMoneyChanged ( playerid, before_amount, after_amount ); + /* ** Hooks ** */ hook OnVehicleMod( playerid, vehicleid, componentid ) { @@ -229,23 +232,50 @@ hook OnVehicleRespray( playerid, vehicleid, color1, color2 ) /* ** Functions ** */ stock GivePlayerCash( playerid, money ) { - p_Cash[ playerid ] += money; - ResetPlayerMoney( playerid ); - GivePlayerMoney( playerid, p_Cash[ playerid ] ); + if ( CallRemoteFunction( "OnPlayerMoneyChanged", "ddd", playerid, p_Cash[ playerid ], p_Cash[ playerid ] + money ) ) + { + p_Cash[ playerid ] += money; + ResetPlayerMoney( playerid ); + GivePlayerMoney( playerid, p_Cash[ playerid ] ); + } +#if defined DEBUG_MODE + else + { + printf( "GivePlayerCash( %d, %d ) prevented [Reason: OnPlayerMoneyChanged returned 0]", playerid, money ); + } +#endif } stock SetPlayerCash( playerid, money ) { - p_Cash[ playerid ] = money; - ResetPlayerMoney( playerid ); - GivePlayerMoney( playerid, p_Cash[ playerid ] ); + if ( CallRemoteFunction( "OnPlayerMoneyChanged", "ddd", playerid, p_Cash[ playerid ], money ) ) + { + p_Cash[ playerid ] = money; + ResetPlayerMoney( playerid ); + GivePlayerMoney( playerid, p_Cash[ playerid ] ); + } +#if defined DEBUG_MODE + else + { + printf( "SetPlayerCash( %d, %d ) prevented [Reason: OnPlayerMoneyChanged returned 0]", playerid, money ); + } +#endif } stock ResetPlayerCash( playerid ) { - p_Cash[ playerid ] = 0; - ResetPlayerMoney( playerid ); - GivePlayerMoney( playerid, p_Cash[ playerid ] ); + if ( CallRemoteFunction( "OnPlayerMoneyChanged", "ddd", playerid, p_Cash[ playerid ], 0 ) ) + { + p_Cash[ playerid ] = 0; + ResetPlayerMoney( playerid ); + GivePlayerMoney( playerid, p_Cash[ playerid ] ); + } +#if defined DEBUG_MODE + else + { + printf( "ResetPlayerCash( %d ) prevented [Reason: OnPlayerMoneyChanged returned 0]", playerid ); + } +#endif } stock GetPlayerCash( playerid ) diff --git a/gamemodes/sf-cnr.pwn b/gamemodes/sf-cnr.pwn index 09c068b..c4155ff 100644 --- a/gamemodes/sf-cnr.pwn +++ b/gamemodes/sf-cnr.pwn @@ -5280,6 +5280,11 @@ function unpause_Player( playerid ) } #if defined AC_INCLUDED + public OnPlayerMoneyChanged( playerid, before_amount, after_amount ) + { + return 1; + } + public OnPlayerCheatDetected( playerid, detection, params ) { if ( detection == CHEAT_TYPE_REMOTE_JACK )