SA-MP Forums Archive
Want to ask - 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: Want to ask (/showthread.php?tid=646619)



Want to ask - Foxer123456 - 20.12.2017

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 ?


Re: Want to ask - Ritzy2K - 20.12.2017

Uh, yeah. Everything is possible.

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


Re: Want to ask - OneDay - 20.12.2017

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


Re: Want to ask - Foxer123456 - 20.12.2017

oh dude thank you.


Re: Want to ask - Konstantinos - 20.12.2017

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..



Re: Want to ask - OneDay - 19.04.2018

Fixed some problems.


Re: Want to ask - jasperschellekens - 19.04.2018

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


Re: Want to ask - OneDay - 19.04.2018

I edited the code above.