use player bank getters & setters instead of variable directly

This commit is contained in:
Lorenc Pekaj 2019-01-16 18:47:31 +11:00
parent bb45138674
commit d1e58ea2aa
2 changed files with 30 additions and 28 deletions

View File

@ -29,17 +29,17 @@ hook OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] )
{ {
case 0: case 0:
{ {
format( szBigString, sizeof( szBigString ), "{FFFFFF}Enter the amount that you are willing to withdraw from your bank account.\n\n"COL_GREY"Current Balance:"COL_WHITE" %s", cash_format( p_BankMoney[ playerid ] ) ); format( szBigString, sizeof( szBigString ), "{FFFFFF}Enter the amount that you are willing to withdraw from your bank account.\n\n"COL_GREY"Current Balance:"COL_WHITE" %s", cash_format( GetPlayerBankMoney( playerid ) ) );
ShowPlayerDialog( playerid, DIALOG_BANK_WITHDRAW, DIALOG_STYLE_INPUT, "{FFFFFF}Personal Account", szBigString, "Withdraw", "Back" ); ShowPlayerDialog( playerid, DIALOG_BANK_WITHDRAW, DIALOG_STYLE_INPUT, "{FFFFFF}Personal Account", szBigString, "Withdraw", "Back" );
} }
case 1: case 1:
{ {
format( szBigString, sizeof( szBigString ), "{FFFFFF}Enter the amount that you are willing to deposit into your bank account below.\n\n"COL_GREY"Current Balance:"COL_WHITE" %s", cash_format( p_BankMoney[ playerid ] ) ); format( szBigString, sizeof( szBigString ), "{FFFFFF}Enter the amount that you are willing to deposit into your bank account below.\n\n"COL_GREY"Current Balance:"COL_WHITE" %s", cash_format( GetPlayerBankMoney( playerid ) ) );
ShowPlayerDialog( playerid, DIALOG_BANK_DEPOSIT, DIALOG_STYLE_INPUT, "{FFFFFF}Personal Account", szBigString, "Deposit", "Back" ); ShowPlayerDialog( playerid, DIALOG_BANK_DEPOSIT, DIALOG_STYLE_INPUT, "{FFFFFF}Personal Account", szBigString, "Deposit", "Back" );
} }
case 2: case 2:
{ {
format( szBigString, sizeof( szBigString ), ""COL_GREY"Current Balance:"COL_WHITE" %s\n"COL_GREY"Current Money:{FFFFFF} %s", cash_format( p_BankMoney[ playerid ] ), cash_format( GetPlayerCash( playerid ) ) ); format( szBigString, sizeof( szBigString ), ""COL_GREY"Current Balance:"COL_WHITE" %s\n"COL_GREY"Current Money:{FFFFFF} %s", cash_format( GetPlayerBankMoney( playerid ) ), cash_format( GetPlayerCash( playerid ) ) );
ShowPlayerDialog( playerid, DIALOG_BANK_INFO, DIALOG_STYLE_MSGBOX, "{FFFFFF}Personal Account", szBigString, "Ok", "Back" ); ShowPlayerDialog( playerid, DIALOG_BANK_INFO, DIALOG_STYLE_MSGBOX, "{FFFFFF}Personal Account", szBigString, "Ok", "Back" );
} }
// ... cases 3, 4, 5 handled in cnr\features\gangs\gbank.pwn // ... cases 3, 4, 5 handled in cnr\features\gangs\gbank.pwn
@ -57,33 +57,33 @@ hook OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] )
format( money_withdraw, sizeof( money_withdraw ), "%s", inputtext ); format( money_withdraw, sizeof( money_withdraw ), "%s", inputtext );
if ( strmatch( money_withdraw, "MAX" ) || strmatch( money_withdraw, "ALL" ) ) { if ( strmatch( money_withdraw, "MAX" ) || strmatch( money_withdraw, "ALL" ) ) {
format( money_withdraw, sizeof( money_withdraw ), "%d", p_BankMoney[ playerid ] ); format( money_withdraw, sizeof( money_withdraw ), "%d", GetPlayerBankMoney( playerid ) );
} }
if ( ! strlen( money_withdraw ) ) if ( ! strlen( money_withdraw ) )
{ {
format( szBigString, sizeof( szBigString ), "{FFFFFF}Enter the amount that you are willing to withdraw from your bank account.\n\n"COL_RED"Invalid amount entered!\n\n"COL_GREY"Current Balance:"COL_WHITE" %s", cash_format( p_BankMoney[ playerid ] ) ); format( szBigString, sizeof( szBigString ), "{FFFFFF}Enter the amount that you are willing to withdraw from your bank account.\n\n"COL_RED"Invalid amount entered!\n\n"COL_GREY"Current Balance:"COL_WHITE" %s", cash_format( GetPlayerBankMoney( playerid ) ) );
ShowPlayerDialog( playerid, DIALOG_BANK_WITHDRAW, DIALOG_STYLE_INPUT, "{FFFFFF}Personal Account", szBigString, "Withdraw", "Back" ); ShowPlayerDialog( playerid, DIALOG_BANK_WITHDRAW, DIALOG_STYLE_INPUT, "{FFFFFF}Personal Account", szBigString, "Withdraw", "Back" );
} }
else if ( ! IsNumeric( money_withdraw ) ) { else if ( ! IsNumeric( money_withdraw ) ) {
format( szBigString, sizeof( szBigString ), "{FFFFFF}Enter the amount that you are willing to withdraw from your bank account.\n\n"COL_RED"Invalid amount entered!\n\n"COL_GREY"Current Balance:"COL_WHITE" %s", cash_format( p_BankMoney[ playerid ] ) ); format( szBigString, sizeof( szBigString ), "{FFFFFF}Enter the amount that you are willing to withdraw from your bank account.\n\n"COL_RED"Invalid amount entered!\n\n"COL_GREY"Current Balance:"COL_WHITE" %s", cash_format( GetPlayerBankMoney( playerid ) ) );
ShowPlayerDialog( playerid, DIALOG_BANK_WITHDRAW, DIALOG_STYLE_INPUT, "{FFFFFF}Personal Account", szBigString, "Withdraw", "Back" ); ShowPlayerDialog( playerid, DIALOG_BANK_WITHDRAW, DIALOG_STYLE_INPUT, "{FFFFFF}Personal Account", szBigString, "Withdraw", "Back" );
} }
else if ( strval( money_withdraw ) > 99999999 || strval( money_withdraw ) <= 0 ) else if ( strval( money_withdraw ) > 99999999 || strval( money_withdraw ) <= 0 )
{ {
format( szBigString, sizeof( szBigString ), "{FFFFFF}Enter the amount that you are willing to withdraw from your bank account.\n\n"COL_RED"Invalid amount entered!\n\n"COL_GREY"Current Balance:"COL_WHITE" %s", cash_format( p_BankMoney[ playerid ] ) ); format( szBigString, sizeof( szBigString ), "{FFFFFF}Enter the amount that you are willing to withdraw from your bank account.\n\n"COL_RED"Invalid amount entered!\n\n"COL_GREY"Current Balance:"COL_WHITE" %s", cash_format( GetPlayerBankMoney( playerid ) ) );
ShowPlayerDialog( playerid, DIALOG_BANK_WITHDRAW, DIALOG_STYLE_INPUT, "{FFFFFF}Personal Account", szBigString, "Withdraw", "Back" ); ShowPlayerDialog( playerid, DIALOG_BANK_WITHDRAW, DIALOG_STYLE_INPUT, "{FFFFFF}Personal Account", szBigString, "Withdraw", "Back" );
} }
else if ( strval( money_withdraw ) > p_BankMoney[ playerid ] ) { else if ( strval( money_withdraw ) > GetPlayerBankMoney( playerid ) ) {
format( szBigString, sizeof( szBigString ), "{FFFFFF}Enter the amount that you are willing to withdraw from your bank account.\n\n"COL_RED"Insufficient balance, therefore withdrawal failed.\n\n"COL_GREY"Current Balance:"COL_WHITE" %s", cash_format( p_BankMoney[ playerid ] ) ); format( szBigString, sizeof( szBigString ), "{FFFFFF}Enter the amount that you are willing to withdraw from your bank account.\n\n"COL_RED"Insufficient balance, therefore withdrawal failed.\n\n"COL_GREY"Current Balance:"COL_WHITE" %s", cash_format( GetPlayerBankMoney( playerid ) ) );
ShowPlayerDialog( playerid, DIALOG_BANK_WITHDRAW, DIALOG_STYLE_INPUT, "{FFFFFF}Personal Account", szBigString, "Withdraw", "Back" ); ShowPlayerDialog( playerid, DIALOG_BANK_WITHDRAW, DIALOG_STYLE_INPUT, "{FFFFFF}Personal Account", szBigString, "Withdraw", "Back" );
} }
else else
{ {
new iWithdraw = strval( money_withdraw ); new iWithdraw = strval( money_withdraw );
p_BankMoney[ playerid ] -= iWithdraw; GivePlayerBankMoney( playerid, -iWithdraw );
GivePlayerCash( playerid, iWithdraw ); GivePlayerCash( playerid, iWithdraw );
format( szBigString, sizeof( szBigString ), ""COL_GREY"Amount Withdrawn:"COL_WHITE" %s\n"COL_GREY"Current Balance:"COL_WHITE" %s\n"COL_GREY"Current Money:{FFFFFF} %s", cash_format( iWithdraw ), cash_format( p_BankMoney[ playerid ] ), cash_format( GetPlayerCash( playerid ) ) ); format( szBigString, sizeof( szBigString ), ""COL_GREY"Amount Withdrawn:"COL_WHITE" %s\n"COL_GREY"Current Balance:"COL_WHITE" %s\n"COL_GREY"Current Money:{FFFFFF} %s", cash_format( iWithdraw ), cash_format( GetPlayerBankMoney( playerid ) ), cash_format( GetPlayerCash( playerid ) ) );
ShowPlayerDialog( playerid, DIALOG_BANK_INFO, DIALOG_STYLE_MSGBOX, "{FFFFFF}Personal Account", szBigString, "Ok", "Back" ); ShowPlayerDialog( playerid, DIALOG_BANK_INFO, DIALOG_STYLE_MSGBOX, "{FFFFFF}Personal Account", szBigString, "Ok", "Back" );
} }
return 1; return 1;
@ -106,28 +106,28 @@ hook OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] )
// validate amount // validate amount
if ( !strlen( money_deposit ) ) { if ( !strlen( money_deposit ) ) {
format( szBigString, sizeof( szBigString ), "{FFFFFF}Enter the amount that you are willing to deposit into your bank account below.\n\n"COL_RED"Invalid amount entered!\n\n"COL_GREY"Current Balance:"COL_WHITE" %s", cash_format( p_BankMoney[ playerid ] ) ); format( szBigString, sizeof( szBigString ), "{FFFFFF}Enter the amount that you are willing to deposit into your bank account below.\n\n"COL_RED"Invalid amount entered!\n\n"COL_GREY"Current Balance:"COL_WHITE" %s", cash_format( GetPlayerBankMoney( playerid ) ) );
ShowPlayerDialog( playerid, DIALOG_BANK_DEPOSIT, DIALOG_STYLE_INPUT, "{FFFFFF}Personal Account", szBigString, "Deposit", "Back" ); ShowPlayerDialog( playerid, DIALOG_BANK_DEPOSIT, DIALOG_STYLE_INPUT, "{FFFFFF}Personal Account", szBigString, "Deposit", "Back" );
} }
else if ( ! IsNumeric( money_deposit ) ) { else if ( ! IsNumeric( money_deposit ) ) {
format( szBigString, sizeof( szBigString ), "{FFFFFF}Enter the amount that you are willing to deposit into your bank account below.\n\n"COL_RED"Invalid amount entered!\n\n"COL_GREY"Current Balance:"COL_WHITE" %s", cash_format( p_BankMoney[ playerid ] ) ); format( szBigString, sizeof( szBigString ), "{FFFFFF}Enter the amount that you are willing to deposit into your bank account below.\n\n"COL_RED"Invalid amount entered!\n\n"COL_GREY"Current Balance:"COL_WHITE" %s", cash_format( GetPlayerBankMoney( playerid ) ) );
ShowPlayerDialog( playerid, DIALOG_BANK_DEPOSIT, DIALOG_STYLE_INPUT, "{FFFFFF}Personal Account", szBigString, "Deposit", "Back" ); ShowPlayerDialog( playerid, DIALOG_BANK_DEPOSIT, DIALOG_STYLE_INPUT, "{FFFFFF}Personal Account", szBigString, "Deposit", "Back" );
} }
else if ( strval( money_deposit ) > GetPlayerCash( playerid ) ) { else if ( strval( money_deposit ) > GetPlayerCash( playerid ) ) {
format( szBigString, sizeof( szBigString ), "{FFFFFF}Enter the amount that you are willing to deposit into your bank account below.\n\n"COL_RED"Insufficient balance, therefore deposition failed.\n\n"COL_GREY"Current Balance:"COL_WHITE" %s", cash_format( p_BankMoney[ playerid ] ) ); format( szBigString, sizeof( szBigString ), "{FFFFFF}Enter the amount that you are willing to deposit into your bank account below.\n\n"COL_RED"Insufficient balance, therefore deposition failed.\n\n"COL_GREY"Current Balance:"COL_WHITE" %s", cash_format( GetPlayerBankMoney( playerid ) ) );
ShowPlayerDialog( playerid, DIALOG_BANK_DEPOSIT, DIALOG_STYLE_INPUT, "{FFFFFF}Personal Account", szBigString, "Deposit", "Back" ); ShowPlayerDialog( playerid, DIALOG_BANK_DEPOSIT, DIALOG_STYLE_INPUT, "{FFFFFF}Personal Account", szBigString, "Deposit", "Back" );
} }
else if ( strval( money_deposit ) > 99999999 || strval( money_deposit ) <= 0 ) else if ( strval( money_deposit ) > 99999999 || strval( money_deposit ) <= 0 )
{ {
format( szBigString, sizeof( szBigString ), "{FFFFFF}Enter the amount that you are willing to deposit into your bank account below.\n\n"COL_RED"Invalid amount entered!\n\n"COL_GREY"Current Balance:"COL_WHITE" %s", cash_format( p_BankMoney[ playerid ] ) ); format( szBigString, sizeof( szBigString ), "{FFFFFF}Enter the amount that you are willing to deposit into your bank account below.\n\n"COL_RED"Invalid amount entered!\n\n"COL_GREY"Current Balance:"COL_WHITE" %s", cash_format( GetPlayerBankMoney( playerid ) ) );
ShowPlayerDialog( playerid, DIALOG_BANK_DEPOSIT, DIALOG_STYLE_INPUT, "{FFFFFF}Personal Account", szBigString, "Deposit", "Back" ); ShowPlayerDialog( playerid, DIALOG_BANK_DEPOSIT, DIALOG_STYLE_INPUT, "{FFFFFF}Personal Account", szBigString, "Deposit", "Back" );
} }
else else
{ {
new iDeposit = strval( money_deposit ); new iDeposit = strval( money_deposit );
p_BankMoney[ playerid ] += iDeposit; GivePlayerBankMoney( playerid, iDeposit );
GivePlayerCash( playerid, -iDeposit ); GivePlayerCash( playerid, -iDeposit );
format( szBigString, sizeof( szBigString ), ""COL_GREY"Amount Deposited:"COL_WHITE" %s\n"COL_GREY"Current Balance:"COL_WHITE" %s\n"COL_GREY"Current Money:{FFFFFF} %s", cash_format( iDeposit ), cash_format( p_BankMoney[ playerid ] ), cash_format( GetPlayerCash( playerid ) ) ); format( szBigString, sizeof( szBigString ), ""COL_GREY"Amount Deposited:"COL_WHITE" %s\n"COL_GREY"Current Balance:"COL_WHITE" %s\n"COL_GREY"Current Money:{FFFFFF} %s", cash_format( iDeposit ), cash_format( GetPlayerBankMoney( playerid ) ), cash_format( GetPlayerCash( playerid ) ) );
ShowPlayerDialog( playerid, DIALOG_BANK_INFO, DIALOG_STYLE_MSGBOX, "{FFFFFF}Personal Account", szBigString, "Ok", "Back" ); ShowPlayerDialog( playerid, DIALOG_BANK_INFO, DIALOG_STYLE_MSGBOX, "{FFFFFF}Personal Account", szBigString, "Ok", "Back" );
} }
} }
@ -144,7 +144,18 @@ hook OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] )
} }
hook OnPlayerDisconnect( playerid, reason ) { hook OnPlayerDisconnect( playerid, reason ) {
p_BankMoney[ playerid ] = 0; p_BankMoney[ playerid ] = 0;
return 1;
}
/* ** Callbacks ** */
public OnPlayerBankMoneyChanged( playerid, amount )
{
// save player bank money on each monetary movement
if ( IsPlayerLoggedIn( playerid ) )
{
mysql_single_query( sprintf( "UPDATE `USERS` SET `BANKMONEY` = %d WHERE `ID` = %d", GetPlayerBankMoney( playerid ), GetPlayerAccountID( playerid ) ) );
}
return 1; return 1;
} }
@ -159,6 +170,7 @@ stock SetPlayerBankMoney( playerid, money ) {
stock GivePlayerBankMoney( playerid, money ) { stock GivePlayerBankMoney( playerid, money ) {
p_BankMoney[ playerid ] += money; p_BankMoney[ playerid ] += money;
CallRemoteFunction( "OnPlayerBankMoneyChanged", "dd", playerid, money );
} }
stock ShowPlayerBankMenuDialog( playerid ) stock ShowPlayerBankMenuDialog( playerid )

View File

@ -4609,16 +4609,6 @@ function unpause_Player( playerid )
return 1; return 1;
} }
public OnPlayerBankMoneyChanged( playerid, amount )
{
// save player bank money on each monetary movement
if ( IsPlayerLoggedIn( playerid ) )
{
mysql_single_query( sprintf( "UPDATE `USERS` SET `BANKMONEY` = %d WHERE `ID` = %d", GetPlayerBankMoney( playerid ), GetPlayerAccountID( playerid ) ) );
}
return 1;
}
public OnPlayerCheatDetected( playerid, detection, params ) public OnPlayerCheatDetected( playerid, detection, params )
{ {
if ( detection == CHEAT_TYPE_REMOTE_JACK ) if ( detection == CHEAT_TYPE_REMOTE_JACK )