Want to ask
#1

Hey guys i want to ask you is it possible to make this system with letters example i want to give some money to player and writing like this /givemoney [playername] [how much M/K]. What is M or K. Its like if i want to give 10,000,000Ђ and by shortening write text i write 10M and system give 10,000,000 or i write 100K, it give me 100,000Ђ. So is it possible ?
Reply
#2

Uh, yeah. Everything is possible.

But I can't stress enough on the fact that how useless that is.
Reply
#3

PHP код:
StringToNumber(const string[]) {
    new 
0;
    new 
neg 1;
    while (
string[i] <= ' 'i++;
    if (
string[i] == '+'i++;
    else if (
string[i] == '-'neg = -1i++;
    if (!(
'0' <= string[i] <= '9')) return 0;
    new 
upper 0;
    new 
lower 0;
    for ( ; ; 
i++) {
        switch (
string[i]) {
            case 
'0'lower lower 10;
            case 
'1'lower lower 10 1;
            case 
'2'lower lower 10 2;
            case 
'3'lower lower 10 3;
            case 
'4'lower lower 10 4;
            case 
'5'lower lower 10 5;
            case 
'6'lower lower 10 6;
            case 
'7'lower lower 10 7;
            case 
'8'lower lower 10 8;
            case 
'9'lower lower 10 9;
            case 
'.'',': {}
            case 
'k''K'upper = (upper lower) * 1000lower 0;
            case 
'm''M'upper = (upper lower) * 1000000lower 0;
            case 
'g''G'upper = (upper lower) * 1000000000lower 0;
            default: break;
        }
    }
    return (
upper lower) * neg;

it is like resistors

10 = 10
10k = 10000
10k1 = 10001
11k11 = 11011
10kk = 10000000
10M = 10000000
1k1 = 1001
1k1k1 = 1001001
Reply
#4

oh dude thank you.
Reply
#5

While OneDay's solution allows multiple letters to be used at once, for a simpler way of just M/K (or m/k) at the end, you can use custom sscanf specifier as well:
pawn Код:
SSCANF:money(k_string[])
{
    new k_length = strlen(k_string);

    switch (k_string[k_length - 1])
    {
        case 'K', 'k':
        {
            k_string[k_length - 1] = EOS;
            return strval(k_string) * 1000;
        }
        case 'M', 'm':
        {
            k_string[k_length - 1] = EOS;
            return strval(k_string) * 1000000;
        }
    }

    return strval(k_string);
}
pawn Код:
if (sscanf(params, "uk<money>", id, value)) return error_usage_here..
Reply
#6

Fixed some problems.
Reply
#7

Quote:
Originally Posted by OneDay
Посмотреть сообщение
Fixed some problems.
Do you realize you bumped a 5 months old topic for no reason?
Reply
#8

I edited the code above.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)