SA-MP Forums Archive
What's this ? - 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: What's this ? (/showthread.php?tid=473077)



What's this ? - AnonScripter - 01.11.2013

somebody please explain what's this ?

pawn Код:
stock sscanf(string[], format[], {Float,_}:...)
{
    new
        formatPos = 0,
        stringPos = 0,
        paramPos = 2,
        paramCount = numargs();
    while (paramPos < paramCount && string[stringPos])
    {
        switch (format[formatPos++])
        {
            case '\0':
            {
                return 0;
            }
            case 'i', 'd':
            {
                new
                    neg = 1,
                    num = 0,
                    ch = string[stringPos];
                if (ch == '-')
                {
                    neg = -1;
                    ch = string[++stringPos];
                }
                do
                {
                    stringPos++;
                    if (ch >= '0' && ch <= '9')
                    {
                        num = (num * 10) + (ch - '0');
                    }
                    else
                    {
                        return 1;
                    }
                }
                while ((ch = string[stringPos]) && ch != ' ');
                setarg(paramPos, 0, num * neg);
            }
            case 'h', 'x':
            {
                new
                    ch,
                    num = 0;
                while ((ch = string[stringPos++]))
                {
                    switch (ch)
                    {
                        case 'x', 'X':
                        {
                            num = 0;
                            continue;
                        }
                        case '0' .. '9':
                        {
                            num = (num << 4) | (ch - '0');
                        }
                        case 'a' .. 'f':
                        {
                            num = (num << 4) | (ch - ('a' - 10));
                        }
                        case 'A' .. 'F':
                        {
                            num = (num << 4) | (ch - ('A' - 10));
                        }
                        case ' ':
                        {
                            break;
                        }
                        default:
                        {
                            return 1;
                        }
                    }
                }
                setarg(paramPos, 0, num);
            }
            case 'c':
            {
                setarg(paramPos, 0, string[stringPos++]);
            }
            case 'f':
            {
                new tmp[25];
                strmid(tmp, string, stringPos, stringPos+sizeof(tmp)-2);
                setarg(paramPos, 0, _:floatstr(tmp));
            }
            case 's', 'z':
            {
                new
                    i = 0,
                    ch;
                if (format[formatPos])
                {
                    while ((ch = string[stringPos++]) && ch != ' ')
                    {
                        setarg(paramPos, i++, ch);
                    }
                    if (!i) return 1;
                }
                else
                {
                    while ((ch = string[stringPos++]))
                    {
                        setarg(paramPos, i++, ch);
                    }
                }
                stringPos--;
                setarg(paramPos, i, '\0');
            }
            default:
            {
                continue;
            }
        }
        while (string[stringPos] && string[stringPos] != ' ')
        {
            stringPos++;
        }
        while (string[stringPos] == ' ')
        {
            stringPos++;
        }
        paramPos++;
    }
    while (format[formatPos] == 'z') formatPos++;
    return format[formatPos];
}



Re: What's this ? - Konstantinos - 01.11.2013

It was possible to be used without the plugin itself, but like SA-MP Wiki says:

Quote:

This version is deprecated. Please use the plugin version (referenced above).

It's recommended to use the plugin (latest version) for it!


Re: What's this ? - Ninad - 01.11.2013

I think its some kind of reaction test (~.^)


Re: What's this ? - Konstantinos - 01.11.2013

Quote:
Originally Posted by Ninad
Посмотреть сообщение
I think its some kind of reaction test (~.^)


Quote:

Sscanf is string splitting routine made by Alex a.k.a. ******.




Re: What's this ? - Pottus - 01.11.2013

The plugin version is standard these days just like the streamer plugin is standard or ZCMD / YCMD yet people still persist to use antiquated methods so it's actually good that you asked.


Re: What's this ? - AnonScripter - 01.11.2013

i see this on every "Hit Command" Tutorial, so what is it ?>