Setting Textdraw to Money
#1

Hey,

I'm trying to create a money textdraw, I want it like the one built in to GTA.

To do this, if the players amount of money is only 2 digits (For example 25) I need to add another 8(?) digits of zeroes in front, this is what I had, but this fails, pretty bad.
pawn Код:
stock GivePlayerMoneyEx(playerid, money)
{
    new mstring[56];
    PlayerInfo[playerid][Money] += money;
    if(PlayerInfo[playerid][Money] <= 10000000000)
    {
      format(mstring, sizeof(mstring), "$%i", PlayerInfo[playerid][Money]);
    }
    if(PlayerInfo[playerid][Money] <= 1000000000)
    {
      format(mstring,sizeof(mstring), "$0%i", PlayerInfo[playerid][Money]);
    }
    if(PlayerInfo[playerid][Money] <= 100000000)
    {
      format(mstring,sizeof(mstring), "$00%i", PlayerInfo[playerid][Money]);
    }
    if(PlayerInfo[playerid][Money] <= 10000000)
    {
      format(mstring,sizeof(mstring), "$000%i", PlayerInfo[playerid][Money]);
    }
    if(PlayerInfo[playerid][Money] <= 1000000)
    {
      format(mstring,sizeof(mstring), "$0000%i", PlayerInfo[playerid][Money]);
    }
    if(PlayerInfo[playerid][Money] <= 100000)
    {
      format(mstring,sizeof(mstring), "$00000%i", PlayerInfo[playerid][Money]);
    }
    if(PlayerInfo[playerid][Money] <= 10000)
    {
      format(mstring,sizeof(mstring), "$000000%i", PlayerInfo[playerid][Money]);
    }
    if(PlayerInfo[playerid][Money] <= 1000)
    {
      format(mstring,sizeof(mstring), "$0000000%i", PlayerInfo[playerid][Money]);
    }
    if(PlayerInfo[playerid][Money] <= 100)
    {
      format(mstring,sizeof(mstring), "$00000000%i", PlayerInfo[playerid][Money]);
    }
    if(PlayerInfo[playerid][Money] <= 10)
    {
      format(mstring,sizeof(mstring), "$000000000%i", PlayerInfo[playerid][Money]);
    }
    TextDrawSetString(Moneybar, mstring);
    return 1;
}
If anyone can show me a better way of doing this I would really appreciate it.
Reply
#2

pawn Код:
stock GivePlayerMoneyEx(playerid, money)
{
    new mstring[56];
    PlayerInfo[playerid][Money] += money;
    format(mstring, sizeof(mstring), "$%010i", PlayerInfo[playerid][Money]);
    TextDrawSetString(Moneybar, mstring);
    return 1;
}
Reply
#3

Quote:
Originally Posted by MadeMan
pawn Код:
stock GivePlayerMoneyEx(playerid, money)
{
    new mstring[56];
    PlayerInfo[playerid][Money] += money;
    format(mstring, sizeof(mstring), "$%010i", PlayerInfo[playerid][Money]);
    TextDrawSetString(Moneybar, mstring);
    return 1;
}
Thanks a lot, but i'd also like to learn, so could you explain how this works please?
Reply
#4

https://sampwiki.blast.hk/wiki/Format - there is a little explanation

The number between % and i is the number of digits.

I'll make a little table, this should make it clear


value %02i %03i %05i
2 02 002 00002
25 25 025 00025
256 256 256 00256


The same can be done with floats when I have a float 5.123456 for example, then


%.2f 5.12
%.3f 5.123
%.5f 5.12345
Reply
#5

Quote:
Originally Posted by MadeMan
https://sampwiki.blast.hk/wiki/Format - there is a little explanation

The number between % and i is the number of digits.

I'll make a little table, this should make it clear


value %02i %03i %05i
2 02 002 00002
25 25 025 00025
256 256 256 00256


The same can be done with floats when I have a float 5.123456 for example, then


%.2f 5.12
%.3f 5.123
%.5f 5.12345
Thanks a lot for that, I owe you one.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)