SA-MP Forums Archive
Setting Textdraw to Money - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Setting Textdraw to Money (/showthread.php?tid=104919)



Setting Textdraw to Money - NeRoSiS - 26.10.2009

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.


Re: Setting Textdraw to Money - MadeMan - 26.10.2009

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;
}



Re: Setting Textdraw to Money - NeRoSiS - 26.10.2009

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?


Re: Setting Textdraw to Money - MadeMan - 26.10.2009

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



Re: Setting Textdraw to Money - NeRoSiS - 26.10.2009

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.