Getting argument type?
#3

pawn Код:
// ** INCLUDES

#include <a_samp>

// ** MAIN

main()
{
    print("Loaded \"argument_type.amx\".");

    Function(""); // "2" = integer, "2.0" = float, "test" = string
}

// ** CALLBACKS

public OnGameModeInit()
{
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

// ** FUNCTIONS

stock Function({_, Float}:...)
{
    new string[144], bool:character = false, bool:point = false, bool:number = false;
    for(new i = 0, j = sizeof(string); i < j; i ++)
    {
        string[i] = getarg(0, i);
    }

    for(new i = 0, j = strlen(string); i < j; i ++)
    {
        if(!character)
        {
            switch(string[i])
            {
                case 'A'..'z':
                {
                    character = true;
                }  
            }
        }

        if(!point)
        {
            switch(string[i])
            {
                case '.':
                {
                    point = true;
                }
            }
        }

        if(!number)
        {
            switch(string[i])
            {
                case '0'..'9':
                {
                    number = true;
                }
            }
        }
    }

    if(character)
    {
        print("string");
    }
    else if(number && point)
    {
        print("float");
    }
    else
    {
        print("integer");
    }
    return 1;
}
Remember to put the arguments in double quotes.
Reply


Messages In This Thread
Getting argument type? - by Gammix - 19.01.2016, 01:18
Re: Getting argument type? - by Jefff - 19.01.2016, 01:43
Re: Getting argument type? - by SickAttack - 19.01.2016, 02:19
Re: Getting argument type? - by Gammix - 19.01.2016, 02:21
Re: Getting argument type? - by Vince - 19.01.2016, 10:53
Re: Getting argument type? - by Gammix - 19.01.2016, 13:27
Re: Getting argument type? - by BroZeus - 19.01.2016, 13:48

Forum Jump:


Users browsing this thread: 1 Guest(s)