SA-MP Forums Archive
How to set this textdraw string? - 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)
+--- Thread: How to set this textdraw string? (/showthread.php?tid=513038)



How to set this textdraw string? - HitterHitman - 14.05.2014

Hello all I am creating a server sided money system but I want the money to show in a textdraw something like:

$000004000 not $4000 how can i do this please help this is my Give money stock:

pawn Код:
stock GiveMoney(playerid,money)
{
    new str[64];
    format(str,sizeof(str),"+$%i",money);
    TextDrawSetString(ShowMoneyEarned[playerid],str);
    pInfo[playerid][pMoney] += money;
    TextDrawShowForPlayer(playerid, ShowMoneyEarned[playerid]);
    return 1;
}



Re: How to set this textdraw string? - Lynn - 14.05.2014

I think this will work, Not sure tbh.
pawn Код:
stock GiveMoney(playerid,money)
{
    new str[64];
    if(money < 10) { format(str,sizeof(str),"+$00000000%i",money); }
    else if(money < 100) { format(str,sizeof(str),"+$0000000%i",money); }
    else if(money < 1000) { format(str,sizeof(str),"+$000000%i",money); }
    else if(money < 10000) { format(str,sizeof(str),"+$00000%i",money); }
    else if(money < 100000) { format(str,sizeof(str),"+$0000%i",money); }
    else if(money < 1000000) { format(str,sizeof(str),"+$000%i",money); }
    else if(money < 10000000) { format(str,sizeof(str),"+$00%i",money); }
    else if(money < 100000000) { format(str,sizeof(str),"+$0%i",money); }
    else if(money < 1000000000) { format(str,sizeof(str),"+$%i",money); }
    TextDrawSetString(ShowMoneyEarned[playerid],str);
    pInfo[playerid][pMoney] += money;
    TextDrawShowForPlayer(playerid, ShowMoneyEarned[playerid]);
    return 1;
}



Re: How to set this textdraw string? - HitterHitman - 14.05.2014

Thank you!


Re: How to set this textdraw string? - Lynn - 14.05.2014

Did it work?


Re: How to set this textdraw string? - iZN - 14.05.2014

Use switch statement, it's much faster than using if-else statements.

pawn Код:
stock GiveMoney(playerid,money)
{
    new str[64];
    switch(money)
    {
        case 1 .. 9: format(str, sizeof(str), "$0000000%d", money);
        case 10 .. 99: format(str, sizeof(str), "$000000%d", money);
        case 100 .. 999: format(str, sizeof(str), "$00000%d", money);
        case 1000 .. 9999: format(str, sizeof(str), "$0000%d", money);
        case 10000 .. 99999: format(str, sizeof(str), "$000%d", money);
        case 100000 .. 999999: format(str, sizeof(str), "$00%d", money);
        case 1000000 .. 9999999: format(str, sizeof(str), "$00%d", money);
        case 10000000 .. 99999999: format(str, sizeof(str), "$0%d", money);
        case 100000000 .. 999999999: format(str, sizeof(str), "$%d", money);
        default: format(str, sizeof(str), "$00000000");

        TextDrawSetString(ShowMoneyEarned[playerid], str);
    }
    pInfo[playerid][pMoney] += money;
    TextDrawShowForPlayer(playerid, ShowMoneyEarned[playerid]);
    return 1;
}



Re: How to set this textdraw string? - HitterHitman - 14.05.2014

Thank you all both works perfectly.


Re: How to set this textdraw string? - Vince - 14.05.2014

Wow, I though this would be common knowledge by now. There is absolutely NO need for extensive functions. The only thing you need is:
pawn Код:
format(str,sizeof(str),"+$%09d",money);
Where the 9 tells it to make it 9 characters long and pad it with 0's if it isn't.


Re: How to set this textdraw string? - iZN - 14.05.2014

Quote:
Originally Posted by Vince
Посмотреть сообщение
Wow, I though this would be common knowledge by now. There is absolutely NO need for extensive functions. The only thing you need is:
pawn Код:
format(str,sizeof(str),"+$%09d",money);
Where the 9 tells it to make it 9 characters long and pad it with 0's if it isn't.
TIL. I never know about this thing, thanks!