SA-MP Forums Archive
check value - 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: check value (/showthread.php?tid=484059)



check value - PawnoQ - 28.12.2013

hi,

if i have smth like this:

pawn Код:
new const NUMBERS[4][1] =
{
    {0},{3},{4},{12}
};
How can i check if a number is included in this function?
E.g. when a player types in a number in a command and then when the typed in number is uncluded in this
collection i posted above it will say: Right number! other wise return wrong.
How can i do this?
I dont want u to script this command for me, just dont know how to check if the entered number is in the number pool.

thanks


Re: check value - SuperViper - 29.12.2013

Loop through the array and check if the numbers are equal.


Re: check value - Emmet_ - 29.12.2013

What SuperViper said above, however you don't need a 2D array for that purpose:

pawn Код:
static const NUMBERS[] =
{
    0,
    3,
    4,
    12
};
And then you can do this:

pawn Код:
IsNumberRight(number)
{
    for (new i = 0; i < sizeof(NUMBERS); i ++)
    {
        if (NUMBERS[i] != number)
            continue;

        return 1;
    }
    return 0;
}