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
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 )

View File

@ -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 )