Is it possible
#1

Hi

I'm trying to make a /inventory command, it will show the player his money/materials...
and i would like to show the money in this format: 000.000.000$, not 0000000$
so if the player have 100000$ it will be 100.000$, not 100000$ any way to do it?
Reply
#2

try this

Код:
format(string,sizeof(string),"your money %s",FormatNumber(PlayerInfo[playerid][pMoney]));
SendClientMessage(playerid,-1,string);
and the stock
Код:
stock FormatNumber(number)
{
   new Str[15];
   format(Str, 15, "%d", number);

   if (strlen(Str) < sizeof(Str))
   {
      if (number >= 1000 && number < 10000)
             strins( Str, ",", 1, sizeof(Str));

      else if (number >= 10000 && number < 100000)
           strins(Str, ",", 2, sizeof(Str));

      else if (number >= 100000 && number < 1000000)
           strins(Str, ",", 3, sizeof(Str));

      else if (number >= 1000000 && number < 10000000)
           strins(Str, ",", 1, sizeof(Str)),strins(Str, ",", 5, sizeof(Str));

      else if (number >= 10000000 && number < 100000000)
           strins(Str, ",", 2, sizeof(Str)),strins(Str, ",", 6, sizeof(Str));

      else if (number >= 100000000 && number < 1000000000)
           strins(Str, ",", 3, sizeof(Str)),strins(Str, ",", 7, sizeof(Str));

      else if (number >= 1000000000 && number < 10000000000)
           strins(Str, ",", 1, sizeof(Str)),
           strins(Str, ",", 5, sizeof(Str)),
           strins(Str, ",", 9, sizeof(Str));
      else format(Str, 10, "%d", number);
   }
   else  format( Str, 15, "<NUMBER ERROR>" );
   return Str;
}
Reply
#3

Quote:
Originally Posted by Mister0
Посмотреть сообщение
try this

Код:
format(string,sizeof(string),"your money %s",FormatNumber(PlayerInfo[playerid][pMoney]));
SendClientMessage(playerid,-1,string);
and the stock
Код:
stock FormatNumber(number)
{
   new Str[15];
   format(Str, 15, "%d", number);

   if (strlen(Str) < sizeof(Str))
   {
      if (number >= 1000 && number < 10000)
             strins( Str, ",", 1, sizeof(Str));

      else if (number >= 10000 && number < 100000)
           strins(Str, ",", 2, sizeof(Str));

      else if (number >= 100000 && number < 1000000)
           strins(Str, ",", 3, sizeof(Str));

      else if (number >= 1000000 && number < 10000000)
           strins(Str, ",", 1, sizeof(Str)),strins(Str, ",", 5, sizeof(Str));

      else if (number >= 10000000 && number < 100000000)
           strins(Str, ",", 2, sizeof(Str)),strins(Str, ",", 6, sizeof(Str));

      else if (number >= 100000000 && number < 1000000000)
           strins(Str, ",", 3, sizeof(Str)),strins(Str, ",", 7, sizeof(Str));

      else if (number >= 1000000000 && number < 10000000000)
           strins(Str, ",", 1, sizeof(Str)),
           strins(Str, ",", 5, sizeof(Str)),
           strins(Str, ",", 9, sizeof(Str));
      else format(Str, 10, "%d", number);
   }
   else  format( Str, 15, "<NUMBER ERROR>" );
   return Str;
}
Didn't work, always show "49"
Reply
#4

Yep. It's possible.
Reply
#5

Quote:
Originally Posted by Threshold
Посмотреть сообщение
Yep. It's possible.
any example how to do it?
Reply
#6

Quote:
Originally Posted by BrianS123
Посмотреть сообщение
any example how to do it?
Код:
CMD:mymoney(playerid,params[])
{
 new string23[70];
 format(string23,sizeof(string23),"your money %s ",FormatNumber(GetPlayerMoney(playerid)));
 SendClientMessage(playerid,-1,string);
 return 1;
}
Reply
#7

Quote:
Originally Posted by BrianS123
Посмотреть сообщение
Didn't work, always show "49"
Use %s instead of %d, FormatNumber returns a string not an integer
Reply
#8

Quote:
Originally Posted by JaKe Elite
Посмотреть сообщение
Use %s instead of %d, FormatNumber returns a string not an integer
I'll try it, thanks
Reply
#9

Works, thank y'all <3
Reply
#10

Quote:
Originally Posted by Mister0
Посмотреть сообщение
and the stock
[/code]
I'm just going to link to this: https://sampwiki.blast.hk/wiki/AddThousandsSeparators
Obviously a much cleaner version.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)