add OnPlayerMoneyChanged callback

This commit is contained in:
Lorenc Pekaj 2019-01-01 22:01:46 +11:00
parent fc7aeb2559
commit 2ed679b149
2 changed files with 44 additions and 9 deletions

View File

@ -19,6 +19,9 @@
static stock static stock
p_Cash [ MAX_PLAYERS ]; p_Cash [ MAX_PLAYERS ];
/* ** Forwards ** */
forward OnPlayerMoneyChanged ( playerid, before_amount, after_amount );
/* ** Hooks ** */ /* ** Hooks ** */
hook OnVehicleMod( playerid, vehicleid, componentid ) hook OnVehicleMod( playerid, vehicleid, componentid )
{ {
@ -228,25 +231,52 @@ hook OnVehicleRespray( playerid, vehicleid, color1, color2 )
/* ** Functions ** */ /* ** Functions ** */
stock GivePlayerCash( playerid, money ) stock GivePlayerCash( playerid, money )
{
if ( CallRemoteFunction( "OnPlayerMoneyChanged", "ddd", playerid, p_Cash[ playerid ], p_Cash[ playerid ] + money ) )
{ {
p_Cash[ playerid ] += money; p_Cash[ playerid ] += money;
ResetPlayerMoney( playerid ); ResetPlayerMoney( playerid );
GivePlayerMoney( playerid, p_Cash[ 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 ) stock SetPlayerCash( playerid, money )
{
if ( CallRemoteFunction( "OnPlayerMoneyChanged", "ddd", playerid, p_Cash[ playerid ], money ) )
{ {
p_Cash[ playerid ] = money; p_Cash[ playerid ] = money;
ResetPlayerMoney( playerid ); ResetPlayerMoney( playerid );
GivePlayerMoney( playerid, p_Cash[ 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 ) stock ResetPlayerCash( playerid )
{
if ( CallRemoteFunction( "OnPlayerMoneyChanged", "ddd", playerid, p_Cash[ playerid ], 0 ) )
{ {
p_Cash[ playerid ] = 0; p_Cash[ playerid ] = 0;
ResetPlayerMoney( playerid ); ResetPlayerMoney( playerid );
GivePlayerMoney( playerid, p_Cash[ playerid ] ); GivePlayerMoney( playerid, p_Cash[ playerid ] );
} }
#if defined DEBUG_MODE
else
{
printf( "ResetPlayerCash( %d ) prevented [Reason: OnPlayerMoneyChanged returned 0]", playerid );
}
#endif
}
stock GetPlayerCash( playerid ) stock GetPlayerCash( playerid )
{ {

View File

@ -5280,6 +5280,11 @@ function unpause_Player( playerid )
} }
#if defined AC_INCLUDED #if defined AC_INCLUDED
public OnPlayerMoneyChanged( playerid, before_amount, after_amount )
{
return 1;
}
public OnPlayerCheatDetected( playerid, detection, params ) public OnPlayerCheatDetected( playerid, detection, params )
{ {
if ( detection == CHEAT_TYPE_REMOTE_JACK ) if ( detection == CHEAT_TYPE_REMOTE_JACK )