type ALL/MAX in bank depo/withdraw/ic buy and it will do the maximum amount possible. IC sold goes straight to your bank account.

This commit is contained in:
Lorenc Pekaj 2018-10-15 16:46:26 +11:00
parent ee20816ebf
commit b11ea31fb5
3 changed files with 64 additions and 23 deletions

View File

@ -256,3 +256,7 @@ stock IsPlayerAdminOnDuty( playerid ) return p_AdminOnDuty{ playerid };
stock IsPlayerSpawnProtected( playerid ) return p_AntiSpawnKillEnabled{ playerid };
stock IsPlayerLoggedIn( playerid ) return p_PlayerLogged{ playerid };
stock GivePlayerBankMoney( playerid, money ) {
p_BankMoney[ playerid ] += money;
}

View File

@ -38,14 +38,24 @@ hook OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] )
return ShowPlayerCoinSellOrders( playerid );
}
new sellorderid = GetPVarInt( playerid, "playermarket_sellorder" );
new Float: purchase_amount;
if ( sscanf( inputtext, "f", purchase_amount ) )
if ( strmatch( inputtext, "ALL" ) || strmatch( inputtext, "MAX" ) )
{
purchase_amount = float( GetPlayerCash( playerid ) ) / float( GetPVarInt( playerid, "playermarket_askprice" ) );
if ( purchase_amount > GetPVarFloat( playerid, "playermarket_available" ) ) {
purchase_amount = GetPVarFloat( playerid, "playermarket_available" );
}
}
else if ( sscanf( inputtext, "f", purchase_amount ) )
{
return SendError( playerid, "Please specify a valid amount." ), PlayerMarket_ShowSellOrder( playerid, sellorderid ), 1;
}
else if ( ! ( 0.5 <= purchase_amount <= 10000.0 ) )
if ( ! ( 0.5 <= purchase_amount <= 10000.0 ) )
{
return SendError( playerid, "Please specify an amount between 0.5 and 10,000 IC." ), PlayerMarket_ShowSellOrder( playerid, sellorderid ), 1;
}
@ -161,6 +171,8 @@ thread PlayerMarket_OnShowSellOrder( playerid, sellorderid )
new ask_price = cache_get_field_content_int( 0, "ASK_PRICE" );
SetPVarInt( playerid, "playermarket_sellorder", sellorderid );
SetPVarInt( playerid, "playermarket_askprice", ask_price );
SetPVarFloat( playerid, "playermarket_available", quantity );
format( szBigString, sizeof( szBigString ), ""COL_WHITE"This player has %s Irresistible Coins to sell at %s per coin.\n\nHow many Irresistible Coins would you like to buy?", number_format( quantity, .decimals = 3 ), cash_format( ask_price ) );
return ShowPlayerDialog( playerid, DIALOG_IC_BUY, DIALOG_STYLE_INPUT, ""COL_GOLD"Irresistible Coin - "COL_WHITE"Buy Coins", szBigString, "Buy", "Back" ), 1;
@ -240,10 +252,10 @@ thread PlayerMarket_OnPurchaseOrder( playerid, sellorderid, Float: purchase_amou
new after_fee_amount = floatround( float( purchase_cost ) * 0.995, floatround_floor );
if ( 0 <= sellerid < MAX_PLAYERS && Iter_Contains( Player, sellerid ) ) {
GivePlayerCash( sellerid, after_fee_amount ), Beep( sellerid );
GivePlayerBankMoney( sellerid, after_fee_amount ), Beep( sellerid );
SendServerMessage( sellerid, "You have successfully sold %s IC to %s(%d) for "COL_GOLD"%s"COL_WHITE" (-0.5%s fee)!", number_format( purchase_amount, .decimals = 3 ), ReturnPlayerName( playerid ), playerid, cash_format( after_fee_amount ), "%%" );
} else {
mysql_single_query( sprintf( "UPDATE `USERS` SET `CASH` = `CASH` + %d WHERE `ID` = %d", after_fee_amount, seller_account_id ) );
mysql_single_query( sprintf( "UPDATE `USERS` SET `BANKMONEY` = `BANKMONEY` + %d WHERE `ID` = %d", after_fee_amount, seller_account_id ) );
}
// log the purchase
@ -251,7 +263,7 @@ thread PlayerMarket_OnPurchaseOrder( playerid, sellorderid, Float: purchase_amou
mysql_single_query( szBigString );
// credit the buyer
GivePlayerCash( playerid, -purchase_cost );
GivePlayerBankMoney( playerid, -purchase_cost );
GivePlayerIrresistibleCoins( playerid, purchase_amount );
SendServerMessage( playerid, "You have successfully purchased %s IC (@ %s/IC) for %s.", number_format( purchase_amount, .decimals = 3 ), cash_format( ask_price ), cash_format( purchase_cost ) );
return 1;

View File

@ -10617,27 +10617,33 @@ public OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] )
if ( IsPlayerJailed( playerid ) ) return SendError( playerid, "You cannot use this while you're in jail." );
if (response)
{
if ( strmatch( inputtext, "MAX" ) || strmatch( inputtext, "ALL" ) ) format( inputtext, 16, "%d", p_BankMoney[ playerid ] );
if (!strlen(inputtext))
new
money_withdraw[ 24 ];
format( money_withdraw, sizeof( money_withdraw ), "%s", inputtext );
if ( strmatch( money_withdraw, "MAX" ) || strmatch( money_withdraw, "ALL" ) ) format( money_withdraw, sizeof( money_withdraw ), "%d", p_BankMoney[ playerid ] );
if (!strlen(money_withdraw))
{
format( Query, sizeof( Query ), "{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 ] ) );
ShowPlayerDialog(playerid, DIALOG_BANK_WITHDRAW, DIALOG_STYLE_INPUT, "{FFFFFF}Personal Account", Query, "Withdraw", "Back");
}
else if (!IsNumeric(inputtext)) {
else if (!IsNumeric(money_withdraw)) {
format( Query, sizeof( Query ), "{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 ] ) );
ShowPlayerDialog(playerid, DIALOG_BANK_WITHDRAW, DIALOG_STYLE_INPUT, "{FFFFFF}Personal Account", Query, "Withdraw", "Back");
}
else if ( strval( inputtext ) > 99999999 || strval( inputtext ) < 0 )
else if ( strval( money_withdraw ) > 99999999 || strval( money_withdraw ) <= 0 )
{
format( Query, sizeof( Query ), "{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 ] ) );
ShowPlayerDialog(playerid, DIALOG_BANK_WITHDRAW, DIALOG_STYLE_INPUT, "{FFFFFF}Personal Account", Query, "Withdraw", "Back");
}
else if (strval(inputtext) > p_BankMoney[ playerid ]) {
else if (strval(money_withdraw) > p_BankMoney[ playerid ]) {
format( Query, sizeof( Query ), "{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 ] ) );
ShowPlayerDialog(playerid, DIALOG_BANK_WITHDRAW, DIALOG_STYLE_INPUT, "{FFFFFF}Personal Account", Query, "Withdraw", "Back");
}
else {
new iWithdraw = strval( inputtext );
new iWithdraw = strval( money_withdraw );
p_BankMoney[ playerid ] -= iWithdraw;
GivePlayerCash( playerid, iWithdraw );
format( Query, sizeof( Query ), ""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 ) ) );
@ -10649,27 +10655,34 @@ public OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] )
if ( dialogid == DIALOG_BANK_DEPOSIT )
{
if ( IsPlayerJailed( playerid ) ) return SendError( playerid, "You cannot use this while you're in jail." );
if (response) {
if ( strmatch( inputtext, "MAX" ) || strmatch( inputtext, "ALL" ) ) format( inputtext, 16, "%d", GetPlayerCash( playerid ) );
if (!strlen(inputtext)) {
if ( response )
{
new
money_deposit[ 24 ];
format( money_deposit, sizeof( money_deposit ), "%s", inputtext );
if ( strmatch( money_deposit, "MAX" ) || strmatch( money_deposit, "ALL" ) ) format( money_deposit, sizeof( money_deposit ), "%d", GetPlayerCash( playerid ) );
if (!strlen(money_deposit)) {
format( Query, sizeof( Query ), "{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 ] ) );
ShowPlayerDialog(playerid, DIALOG_BANK_DEPOSIT, DIALOG_STYLE_INPUT, "{FFFFFF}Personal Account", Query, "Deposit", "Back");
}
else if (!IsNumeric(inputtext)) {
else if (!IsNumeric(money_deposit)) {
format( Query, sizeof( Query ), "{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 ] ) );
ShowPlayerDialog(playerid, DIALOG_BANK_DEPOSIT, DIALOG_STYLE_INPUT, "{FFFFFF}Personal Account", Query, "Deposit", "Back");
}
else if (strval(inputtext) > GetPlayerCash( playerid )) {
else if (strval(money_deposit) > GetPlayerCash( playerid )) {
format( Query, sizeof( Query ), "{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 ] ) );
ShowPlayerDialog(playerid, DIALOG_BANK_DEPOSIT, DIALOG_STYLE_INPUT, "{FFFFFF}Personal Account", Query, "Deposit", "Back");
}
else if ( strval( inputtext ) > 99999999 || strval( inputtext ) < 0 )
else if ( strval( money_deposit ) > 99999999 || strval( money_deposit ) <= 0 )
{
format( Query, sizeof( Query ), "{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 ] ) );
ShowPlayerDialog( playerid, DIALOG_BANK_DEPOSIT, DIALOG_STYLE_INPUT, "{FFFFFF}Personal Account", Query, "Deposit", "Back" );
}
else {
new iDeposit = strval( inputtext );
new iDeposit = strval( money_deposit );
p_BankMoney[ playerid ] += iDeposit;
GivePlayerCash( playerid, -iDeposit );
format( Query, sizeof( Query ), ""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 ) ) );
@ -10704,12 +10717,18 @@ public OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] )
if ( !IsPlayerGangLeader( playerid, gangid ) )
return ShowPlayerBankMenuDialog( playerid ), SendError( playerid, "You must be the gang leader to use this feature." );
if ( sscanf( inputtext, "d", iWithdraw ) )
if ( strmatch( inputtext, "MAX" ) || strmatch( inputtext, "ALL" ) )
{
iWithdraw = g_gangData[ gangid ] [ E_BANK ];
}
else if ( sscanf( inputtext, "d", iWithdraw ) )
{
format( Query, sizeof( Query ), "{FFFFFF}Enter the amount that you are willing to withdraw from your gang bank account.\n\n"COL_RED"Invalid amount entered!\n\n"COL_GREY"Current Balance:"COL_WHITE" %s", cash_format( g_gangData[ gangid ] [ E_BANK ] ) );
ShowPlayerDialog(playerid, DIALOG_GANG_BANK_WITHDRAW, DIALOG_STYLE_INPUT, "{FFFFFF}Gang Account", Query, "Withdraw", "Back");
return ShowPlayerDialog(playerid, DIALOG_GANG_BANK_WITHDRAW, DIALOG_STYLE_INPUT, "{FFFFFF}Gang Account", Query, "Withdraw", "Back");
}
else if ( iWithdraw > 99999999 || iWithdraw < 0 )
// double check quantity
if ( iWithdraw > 99999999 || iWithdraw <= 0 )
{
format( Query, sizeof( Query ), "{FFFFFF}Enter the amount that you are willing to withdraw from your gang bank account.\n\n"COL_RED"Invalid amount entered!\n\n"COL_GREY"Current Balance:"COL_WHITE" %s", cash_format( g_gangData[ gangid ] [ E_BANK ] ) );
ShowPlayerDialog(playerid, DIALOG_GANG_BANK_WITHDRAW, DIALOG_STYLE_INPUT, "{FFFFFF}Gang Account", Query, "Withdraw", "Back");
@ -10755,12 +10774,18 @@ public OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] )
if ( IsPlayerJailed( playerid ) )
return SendError( playerid, "You cannot use this while you're in jail." );
if ( sscanf( inputtext, "d", iDeposit ) )
if ( strmatch( inputtext, "MAX" ) || strmatch( inputtext, "ALL" ) )
{
iDeposit = GetPlayerCash( playerid );
}
else if ( sscanf( inputtext, "d", iDeposit ) )
{
format( Query, sizeof( Query ), "{FFFFFF}Enter the amount that you are willing to deposit into your gang bank account below.\n\n"COL_RED"Invalid amount entered!\n\n"COL_GREY"Current Balance:"COL_WHITE" %s", cash_format( g_gangData[ gangid ] [ E_BANK ] ) );
ShowPlayerDialog(playerid, DIALOG_GANG_BANK_DEPOSIT, DIALOG_STYLE_INPUT, "{FFFFFF}Gang Account", Query, "Deposit", "Back");
}
else if ( iDeposit > 99999999 || iDeposit < 1 )
// double check
if ( iDeposit > 99999999 || iDeposit < 1 )
{
format( Query, sizeof( Query ), "{FFFFFF}Enter the amount that you are willing to deposit into your gang bank account below.\n\n"COL_RED"Invalid amount entered!\n\n"COL_GREY"Current Balance:"COL_WHITE" %s", cash_format( g_gangData[ gangid ] [ E_BANK ] ) );
ShowPlayerDialog( playerid, DIALOG_GANG_BANK_DEPOSIT, DIALOG_STYLE_INPUT, "{FFFFFF}Gang Account", Query, "Deposit", "Back" );