ConvertPrice bug ? -
Sanady - 18.10.2014
Well hello today I wanted to test ConvertPrice how it works and I found bug or it`s my wrong usage. Well see. I put my variable value to 1000. Then I used that variable to give a player money so it`s means that variable and function (GivePlayerMoney) will give player 1000 dollars. But when SendClientMessage shows up it`s says that player get only 36. Strange well this is the command and ConvertPrice code. Please take a look!
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/givemoney", cmdtext, true, 10) == 0)
{
new cash[MAX_PLAYERS] = 1000, string[100];
GivePlayerMoney(playerid,cash[playerid]);
format(string,sizeof(string),"[Info] You get %d !",ConvertPrice(cash[playerid], 1));
SendClientMessage(playerid, -1, string);
return 1;
}
return 0;
}
stock ConvertPrice( iValue, iCashSign = 1 )
{
static
szNum[ 32 ]
;
format( szNum, sizeof( szNum ), "%d", iValue < 0 ? -iValue : iValue );
for( new i = strlen( szNum ) - 3; i > 0; i -= 3 ) {
strins( szNum, ",", i, sizeof( szNum ) );
}
if( iCashSign ) strins( szNum, "$", 0 );
if( iValue < 0 ) strins( szNum, "-", 0, sizeof( szNum ) );
return szNum;
}
Screens
Re: ConvertPrice bug ? -
zaibaslr2 - 18.10.2014
I think you should use
if (strcmp("/givemoney", cmdtext, true, 10) == 0)
{
new cash = 1000, string[100];
GivePlayerMoney(playerid,cash);
format(string,sizeof(string),"[Info] You get %s !",ConvertPrice(cash, 1));
SendClientMessage(playerid, -1, string);
return 1;
}
I used %s instead of %d because the function ConvertPrice returns string
Re: ConvertPrice bug ? -
[LvZ]Free - 18.10.2014
Shouldn't you give ConvertPrice(cash[playerid] instead cash[playerid] on GivePlayerMoney(playerid,cash[playerid]); ?
Re: ConvertPrice bug ? -
cessil - 18.10.2014
you're making an array:
new cash[MAX_PLAYERS] = 1000
and then using cash[playerid]
it doesn't need to be an array
Re: ConvertPrice bug ? -
Neil. - 18.10.2014
Quote:
Originally Posted by [LvZ]Free
Shouldn't you give ConvertPrice(cash[playerid] instead cash[playerid] on GivePlayerMoney(playerid,cash[playerid]); ?
|
No, GivePlayerMoney accepts integer not formatted strings.
On-Topic: You're printing an integer (given the flag: %d), change that to %s as the stock function returns a string.
One more thing, if the array stores an integer, 1000. Why store it as an array? You're wasting memory on something that can essentially be a single variable.
Re: ConvertPrice bug ? -
Yera96 - 18.10.2014
You're creating an array which isn't needed here.
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/givemoney", cmdtext, true, 10) == 0)
{
new string[100];
GivePlayerMoney(playerid, 1000);
format(string,sizeof(string),"[Info] You get %d !",ConvertPrice(1000, 1));
SendClientMessage(playerid, -1, string);
return 1;
}
return 0;
}
If don't want to remove, then just use single variable.
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/givemoney", cmdtext, true, 10) == 0)
{
new cash = 1000, string[100];
GivePlayerMoney(playerid, cash);
format(string,sizeof(string),"[Info] You get %d !",ConvertPrice(cash, 1));
SendClientMessage(playerid, -1, string);
return 1;
}
return 0;
}
But I prefer to use #define here.