How to set this textdraw string?
#1

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;
}
Reply
#2

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;
}
Reply
#3

Thank you!
Reply
#4

Did it work?
Reply
#5

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;
}
Reply
#6

Thank you all both works perfectly.
Reply
#7

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.
Reply
#8

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!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)