changed to cash_format() to style numbers into money and fixes a bug with formatting negative numbers

This commit is contained in:
Lorenc Pekaj 2018-09-11 03:44:05 +10:00
parent 835618c940
commit 95f4957f9a
6 changed files with 206 additions and 203 deletions

View File

@ -116,7 +116,7 @@ CMD:creategarage( playerid, params[ ] )
if ( ( iTmp = CreateGarage( 0, cost, 0, X, Y, Z, Angle ) ) != -1 ) if ( ( iTmp = CreateGarage( 0, cost, 0, X, Y, Z, Angle ) ) != -1 )
{ {
SaveToAdminLog( playerid, iTmp, "created garage" ); SaveToAdminLog( playerid, iTmp, "created garage" );
SendClientMessageFormatted( playerid, -1, ""COL_PINK"[GARAGE]"COL_WHITE" You have created a %s garage taking up garage id %d.", number_format( cost ), iTmp ); SendClientMessageFormatted( playerid, -1, ""COL_PINK"[GARAGE]"COL_WHITE" You have created a %s garage taking up garage id %d.", cash_format( cost ), iTmp );
} }
else else
SendClientMessage( playerid, -1, ""COL_PINK"[GARAGE]"COL_WHITE" Unable to create a garage due to a unexpected error." ); SendClientMessage( playerid, -1, ""COL_PINK"[GARAGE]"COL_WHITE" Unable to create a garage due to a unexpected error." );
@ -666,8 +666,8 @@ CMD:createhouse( playerid, params[ ] )
{ {
if ( ( iTmp = CreateHouse( "Home", cost, X, Y, Z ) ) != -1 ) if ( ( iTmp = CreateHouse( "Home", cost, X, Y, Z ) ) != -1 )
{ {
SaveToAdminLogFormatted( playerid, iTmp, "created house for %s", number_format( cost ) ); SaveToAdminLogFormatted( playerid, iTmp, "created house for %s", cash_format( cost ) );
SendClientMessageFormatted( playerid, -1, ""COL_PINK"[HOUSE]"COL_WHITE" You have created a %s house taking up house id %d.", number_format( cost ), iTmp ); SendClientMessageFormatted( playerid, -1, ""COL_PINK"[HOUSE]"COL_WHITE" You have created a %s house taking up house id %d.", cash_format( cost ), iTmp );
} }
else SendClientMessage( playerid, -1, ""COL_PINK"[HOUSE]"COL_WHITE" Unable to create a house due to a unexpected error." ); else SendClientMessage( playerid, -1, ""COL_PINK"[HOUSE]"COL_WHITE" Unable to create a house due to a unexpected error." );
} }

View File

@ -33,7 +33,7 @@ CMD:hitmanbudget( playerid, params[ ] )
return SendUsage( playerid, "/hitmanbudget [AMOUNT]" ); return SendUsage( playerid, "/hitmanbudget [AMOUNT]" );
UpdateServerVariable( "hitman_budget", GetGVarInt( "hitman_budget" ) + amount, 0.0, "", GLOBAL_VARTYPE_INT ); UpdateServerVariable( "hitman_budget", GetGVarInt( "hitman_budget" ) + amount, 0.0, "", GLOBAL_VARTYPE_INT );
SendServerMessage( playerid, "Hitman budget now currently at %s.", number_format( GetGVarInt( "hitman_budget" ) ) ); SendServerMessage( playerid, "Hitman budget now currently at %s.", cash_format( GetGVarInt( "hitman_budget" ) ) );
return 1; return 1;
} }
@ -153,7 +153,7 @@ CMD:playsound( playerid, params[ ] )
pID, pID,
sound; sound;
if ( sscanf( params, ""#sscanf_u"d", pID, sound ) ) if ( sscanf( params, "ud", pID, sound ) )
return SendUsage( playerid, "/playsound [PLAYER_ID] [SOUND]" ); return SendUsage( playerid, "/playsound [PLAYER_ID] [SOUND]" );
PlayerPlaySound( pID, sound, 0.0, 0.0, 0.0 ); PlayerPlaySound( pID, sound, 0.0, 0.0, 0.0 );
@ -166,7 +166,7 @@ CMD:addgpci( playerid, params[ ] )
pID; pID;
if ( !IsPlayerAdmin( playerid ) ) return 0; if ( !IsPlayerAdmin( playerid ) ) return 0;
else if ( sscanf( params, #sscanf_u, pID ) ) SendUsage( playerid, "/addgpci [PLAYER_ID]"); else if ( sscanf( params, "u", pID ) ) SendUsage( playerid, "/addgpci [PLAYER_ID]");
else if ( !IsPlayerConnected( pID ) || IsPlayerNPC( pID ) ) return SendError( playerid, "Invalid Player ID." ); else if ( !IsPlayerConnected( pID ) || IsPlayerNPC( pID ) ) return SendError( playerid, "Invalid Player ID." );
else else
{ {
@ -421,7 +421,7 @@ CMD:givewanted( playerid, params[ ] )
pID, wantedlvl pID, wantedlvl
; ;
if ( !IsPlayerAdmin( playerid ) ) return 0; if ( !IsPlayerAdmin( playerid ) ) return 0;
else if ( sscanf( params, ""#sscanf_u"d", pID, wantedlvl ) ) SendUsage( playerid, "/givewanted [PLAYER_ID] [WANTED_LVL]" ); else if ( sscanf( params, "ud", pID, wantedlvl ) ) SendUsage( playerid, "/givewanted [PLAYER_ID] [WANTED_LVL]" );
else if ( !IsPlayerConnected( pID ) ) SendError( playerid, "Invalid Player ID." ); else if ( !IsPlayerConnected( pID ) ) SendError( playerid, "Invalid Player ID." );
else else
{ {
@ -439,7 +439,7 @@ CMD:givescore( playerid, params[ ] )
pID, score pID, score
; ;
if ( !IsPlayerAdmin( playerid ) ) return 0; if ( !IsPlayerAdmin( playerid ) ) return 0;
else if ( sscanf( params, ""#sscanf_u"d", pID, score ) ) SendUsage( playerid, "/givescore [PLAYER_ID] [SCORE]" ); else if ( sscanf( params, "ud", pID, score ) ) SendUsage( playerid, "/givescore [PLAYER_ID] [SCORE]" );
else if ( !IsPlayerConnected( pID ) ) SendError( playerid, "Invalid Player ID." ); else if ( !IsPlayerConnected( pID ) ) SendError( playerid, "Invalid Player ID." );
else else
{ {
@ -474,7 +474,7 @@ CMD:givexp( playerid, params [ ] )
xp xp
; ;
if ( !IsPlayerAdmin( playerid ) || !IsPlayerLorenc( playerid ) ) return 0; if ( !IsPlayerAdmin( playerid ) || !IsPlayerLorenc( playerid ) ) return 0;
else if ( sscanf( params, ""#sscanf_u"d", pID, xp ) ) SendUsage( playerid, "/givexp [PLAYER_ID] [XP_AMOUNT]" ); else if ( sscanf( params, "ud", pID, xp ) ) SendUsage( playerid, "/givexp [PLAYER_ID] [XP_AMOUNT]" );
else if ( !IsPlayerConnected( pID ) ) SendError( playerid, "Invalid Player ID." ); else if ( !IsPlayerConnected( pID ) ) SendError( playerid, "Invalid Player ID." );
else else
{ {
@ -493,7 +493,7 @@ CMD:giveip( playerid, params [ ] )
ip ip
; ;
if ( !IsPlayerAdmin( playerid ) || !IsPlayerLorenc( playerid ) ) return 0; if ( !IsPlayerAdmin( playerid ) || !IsPlayerLorenc( playerid ) ) return 0;
else if ( sscanf( params, ""#sscanf_u"d", pID, ip ) ) SendUsage( playerid, "/giveip [PLAYER_ID] [IP_AMOUNT]" ); else if ( sscanf( params, "ud", pID, ip ) ) SendUsage( playerid, "/giveip [PLAYER_ID] [IP_AMOUNT]" );
else if ( !IsPlayerConnected( pID ) ) SendError( playerid, "Invalid Player ID." ); else if ( !IsPlayerConnected( pID ) ) SendError( playerid, "Invalid Player ID." );
else else
{ {
@ -512,7 +512,7 @@ CMD:givecoins( playerid, params [ ] )
Float: coins Float: coins
; ;
if ( !IsPlayerAdmin( playerid ) || !IsPlayerLorenc( playerid ) ) return 0; if ( !IsPlayerAdmin( playerid ) || !IsPlayerLorenc( playerid ) ) return 0;
else if ( sscanf( params, ""#sscanf_u"f", sendtoid, coins ) ) SendUsage( playerid, "/givecoins [PLAYER_ID] [COINS]" ); else if ( sscanf( params, "uf", sendtoid, coins ) ) SendUsage( playerid, "/givecoins [PLAYER_ID] [COINS]" );
else if ( !IsPlayerConnected( sendtoid ) ) SendError( playerid, "Invalid Player ID." ); else if ( !IsPlayerConnected( sendtoid ) ) SendError( playerid, "Invalid Player ID." );
else else
{ {
@ -531,14 +531,14 @@ CMD:givecash( playerid, params [ ] )
cash cash
; ;
if ( !IsPlayerAdmin( playerid ) || !IsPlayerLorenc( playerid ) ) return 0; if ( !IsPlayerAdmin( playerid ) || !IsPlayerLorenc( playerid ) ) return 0;
else if ( sscanf( params, ""#sscanf_u"d", pID, cash ) ) SendUsage( playerid, "/givecash [PLAYER_ID] [CASH]" ); else if ( sscanf( params, "ud", pID, cash ) ) SendUsage( playerid, "/givecash [PLAYER_ID] [CASH]" );
else if ( !IsPlayerConnected( pID ) ) SendError( playerid, "Invalid Player ID." ); else if ( !IsPlayerConnected( pID ) ) SendError( playerid, "Invalid Player ID." );
else else
{ {
GivePlayerCash( pID, cash ); GivePlayerCash( pID, cash );
AddAdminLogLineFormatted( "%s(%d) has given %s(%d) %d dollars", ReturnPlayerName( playerid ), playerid, ReturnPlayerName( pID ), pID, cash ); AddAdminLogLineFormatted( "%s(%d) has given %s(%d) %d dollars", ReturnPlayerName( playerid ), playerid, ReturnPlayerName( pID ), pID, cash );
SendClientMessageFormatted( pID, -1, ""COL_PINK"[ADMIN]{FFFFFF} %s(%d) has given you "COL_GOLD"%s", ReturnPlayerName( playerid ), playerid, number_format( cash ) ); SendClientMessageFormatted( pID, -1, ""COL_PINK"[ADMIN]{FFFFFF} %s(%d) has given you "COL_GOLD"%s", ReturnPlayerName( playerid ), playerid, cash_format( cash ) );
SendClientMessageFormatted( playerid, -1, ""COL_PINK"[ADMIN]{FFFFFF} You've given %s(%d) "COL_GOLD"%s", ReturnPlayerName( pID ), pID, number_format( cash ) ); SendClientMessageFormatted( playerid, -1, ""COL_PINK"[ADMIN]{FFFFFF} You've given %s(%d) "COL_GOLD"%s", ReturnPlayerName( pID ), pID, cash_format( cash ) );
} }
return 1; return 1;
} }
@ -551,7 +551,7 @@ CMD:setviplevel( playerid, params[ ] )
; ;
if ( !IsPlayerAdmin( playerid ) || !IsPlayerLorenc( playerid ) ) return 0; if ( !IsPlayerAdmin( playerid ) || !IsPlayerLorenc( playerid ) ) return 0;
else if ( sscanf( params, ""#sscanf_u"d", pID, level ) ) return SendUsage( playerid, "/setviplevel [PLAYER_ID] [VIP_LEVEL]" ); else if ( sscanf( params, "ud", pID, level ) ) return SendUsage( playerid, "/setviplevel [PLAYER_ID] [VIP_LEVEL]" );
else if ( !IsPlayerConnected( pID ) ) SendError( playerid, "Invalid Player ID." ); else if ( !IsPlayerConnected( pID ) ) SendError( playerid, "Invalid Player ID." );
else if ( p_PlayerLogged{ pID } == false ) return SendError( playerid, "This player is not logged in." ); else if ( p_PlayerLogged{ pID } == false ) return SendError( playerid, "This player is not logged in." );
else if ( level > VIP_DIAMOND || level < 0 ) return SendError( playerid, "Specify a level between 0 - 5 please!" ); else if ( level > VIP_DIAMOND || level < 0 ) return SendError( playerid, "Specify a level between 0 - 5 please!" );
@ -572,7 +572,7 @@ CMD:extendvip( playerid, params[ ] )
; ;
if ( !IsPlayerAdmin( playerid ) ) return 0; if ( !IsPlayerAdmin( playerid ) ) return 0;
else if ( sscanf( params, ""#sscanf_u"d", pID, days ) ) return SendUsage( playerid, "/extendvip [PLAYER_ID] [DAYS]" ); else if ( sscanf( params, "ud", pID, days ) ) return SendUsage( playerid, "/extendvip [PLAYER_ID] [DAYS]" );
else if ( !IsPlayerConnected( pID ) ) SendError( playerid, "Invalid Player ID." ); else if ( !IsPlayerConnected( pID ) ) SendError( playerid, "Invalid Player ID." );
else if ( p_VIPLevel[ pID ] < VIP_REGULAR ) return SendError( playerid, "This player doesn't have a V.I.P level." ); else if ( p_VIPLevel[ pID ] < VIP_REGULAR ) return SendError( playerid, "This player doesn't have a V.I.P level." );
else if ( days < -365 || days > 365 ) return SendError( playerid, "Extension can only vary from -365 to 365 days." ); else if ( days < -365 || days > 365 ) return SendError( playerid, "Extension can only vary from -365 to 365 days." );

View File

@ -26,7 +26,7 @@ CMD:createbusiness( playerid, params[ ] )
if ( iTmp != ITER_NONE ) { if ( iTmp != ITER_NONE ) {
SaveToAdminLog( playerid, iTmp, "created business" ); SaveToAdminLog( playerid, iTmp, "created business" );
SendClientMessageFormatted( playerid, -1, ""COL_PINK"[BUSINESS]"COL_WHITE" You have created a %s business taking up business id %d.", number_format( cost ), iTmp ); SendClientMessageFormatted( playerid, -1, ""COL_PINK"[BUSINESS]"COL_WHITE" You have created a %s business taking up business id %d.", cash_format( cost ), iTmp );
} else { } else {
SendClientMessage( playerid, -1, ""COL_PINK"[BUSINESS]"COL_WHITE" Unable to create a business due to a unexpected error." ); SendClientMessage( playerid, -1, ""COL_PINK"[BUSINESS]"COL_WHITE" Unable to create a business due to a unexpected error." );
} }

View File

@ -291,7 +291,7 @@ CMD:vadminstats( playerid, params[ ] )
""COL_GREY"Vehicle ID:"COL_WHITE" %d\n"\ ""COL_GREY"Vehicle ID:"COL_WHITE" %d\n"\
""COL_GREY"Vehicle Price:"COL_WHITE" %s", ""COL_GREY"Vehicle Price:"COL_WHITE" %s",
ReturnPlayerName( ownerid ), GetVehicleName( GetVehicleModel( GetPlayerVehicleID( playerid ) ) ), ReturnPlayerName( ownerid ), GetVehicleName( GetVehicleModel( GetPlayerVehicleID( playerid ) ) ),
g_vehicleData[ ownerid ] [ slotid ] [ E_SQL_ID ], number_format( g_vehicleData[ ownerid ] [ slotid ] [ E_PRICE ] ) ); g_vehicleData[ ownerid ] [ slotid ] [ E_SQL_ID ], cash_format( g_vehicleData[ ownerid ] [ slotid ] [ E_PRICE ] ) );
ShowPlayerDialog( playerid, DIALOG_NULL, DIALOG_STYLE_MSGBOX, "{FFFFFF}Vehicle Data", szBigString, "Okay", "" ); ShowPlayerDialog( playerid, DIALOG_NULL, DIALOG_STYLE_MSGBOX, "{FFFFFF}Vehicle Data", szBigString, "Okay", "" );
return 1; return 1;

View File

@ -250,7 +250,7 @@ stock Player_GetUnusedAttachIndex( playerid )
} }
// purpose: convert integer into dollar string (large credit to Slice - i just added a prefix parameter) // purpose: convert integer into dollar string (large credit to Slice - i just added a prefix parameter)
stock number_format( { _, Float, Text3D, Menu, Text, DB, DBResult, bool, File }: variable, prefix = '$', decimals = -1, thousand_seperator = ',', decimal_point = '.', tag = tagof( variable ) ) stock number_format( { _, Float, Text3D, Menu, Text, DB, DBResult, bool, File }: variable, prefix = '\0', decimals = -1, thousand_seperator = ',', decimal_point = '.', tag = tagof( variable ) )
{ {
static static
s_szReturn[ 32 ], s_szReturn[ 32 ],
@ -305,7 +305,7 @@ stock number_format( { _, Float, Text3D, Menu, Text, DB, DBResult, bool, File }:
while ( --s_iChar > 0 ) while ( --s_iChar > 0 )
{ {
if ( ++s_iSepPos == 3 ) if ( ++s_iSepPos == 3 && s_szReturn[ s_iChar - 1 ] != '-' )
{ {
strins( s_szReturn, s_szThousandSeparator, s_iChar ); strins( s_szReturn, s_szThousandSeparator, s_iChar );
@ -316,11 +316,14 @@ stock number_format( { _, Float, Text3D, Menu, Text, DB, DBResult, bool, File }:
if ( prefix != '\0' ) { if ( prefix != '\0' ) {
// new minus = strfind( s_szReturn, "-" ); // new minus = strfind( s_szReturn, "-" );
strins( s_szReturn, "$", variable < 0 ); // no point finding - strins( s_szReturn, "$", s_szReturn[ 0 ] == '-' ); // no point finding -
} }
return s_szReturn; return s_szReturn;
} }
#define cash_format(%0) \
(number_format(%0, .prefix = '$'))
// purpose: find a random element in sample space, excluding [a, b, c, ...] // purpose: find a random element in sample space, excluding [a, b, c, ...]
stock randomExcept( except[ ], len = sizeof( except ), available_element_value = -1 ) { stock randomExcept( except[ ], len = sizeof( except ), available_element_value = -1 ) {

File diff suppressed because it is too large Load Diff