Checking array elements and comparing them
#1

Hello,
So let's say I have four arrays. Each one contains the skins that each clothing shop sells.
We have Binco, ZIP, Sub-Urban and Victim clothing shops.

What I want to do, is to compare an input, for example a ZCMD command with params, with all the elements in the four arrays, and if the number inputted is not in any of the arrays, it will say the skin is invalid.

Also, how do I check if I've insert a skin from the Sub-Urban array, but if I'm at Binco, for example, it will return an error?
I hope you can help me as this is urgent.

The array:
pawn Код:
new BincoSkins[][] =
{
    {1},
    {4},
    {5},
    {6},
    {7},
    {8},
    {9},
    {10},
    {11},
    {12},
    {13},
    {14},
    {15},
    {16},
    {18},
    {19},
    {21},
    {22},
    {28},
    {30},
    {41},
    {44},
    {45},
    {53},
    {54},
    {62},
    {66},
    {67},
    {75},
    {76},
    {77},
    {78},
    {79},
    {80},
    {81},
    {85},
    {86},
    {87},
    {101},
    {102},
    {103},
    {104},
    {105},
    {106},
    {107},
    {108},
    {109},
    {110},
    {128},
    {129},
    {130},
    {131},
    {132},
    {133},
    {134},
    {135},
    {136},
    {137},
    {138},
    {139},
    {140},
    {154},
    {156},
    {157},
    {158},
    {159},
    {160},
    {161},
    {162},
    {168},
    {195},
    {196},
    {197},
    {198},
    {199},
    {200},
    {201},
    {202},
    {209},
    {210},
    {212},
    {213},
    {218},
    {230},
    {243},
    {244},
    {245},
    {246},
    {252},
    {253},
    {256},
    {257},
    {269},
    {270},
    {271},
    {297},
    {298}
};
   
new VictimSkins[][] =
{
    {26},
    {27},
    {32},
    {33},
    {34},
    {40},
    {49},
    {50},
    {55},
    {56},
    {58},
    {68},
    {72},
    {73},
    {82},
    {83},
    {84},
    {89},
    {90},
    {92},
    {96},
    {97},
    {151},
    {152},
    {153},
    {178},
    {179},
    {182},
    {188},
    {191},
    {192},
    {193},
    {203},
    {204},
    {211},
    {214},
    {229},
    {231},
    {232},
    {234},
    {235},
    {247},
    {248},
    {249},
    {251},
    {254},
    {255},
    {260},
    {261},
    {264},
    {289},
    {299}
};

new SubUrbanSkins[][] =
{
    {23},
    {24},
    {25},
    {29},
    {31},
    {42},
    {47},
    {48},
    {60},
    {63},
    {64},
    {65},
    {69},
    {99},
    {100},
    {101},
    {114},
    {115},
    {116},
    {121},
    {122},
    {123},
    {142},
    {143},
    {144},
    {145},
    {146},
    {170},
    {173},
    {174},
    {175},
    {176},
    {177},
    {180},
    {183},
    {184},
    {206},
    {207},
    {220},
    {221},
    {222},
    {236},
    {237},
    {238},
    {239},
    {241},
    {242},
    {250},
    {262},
    {268},
    {273},
    {291}
};

new ZIPSkins[][] =
{
    {17},
    {20},
    {35},
    {36},
    {37},
    {38},
    {39},
    {43},
    {46},
    {51},
    {52},
    {59},
    {61},
    {70},
    {88},
    {91},
    {93},
    {94},
    {98},
    {111},
    {112},
    {113},
    {118},
    {119},
    {120},
    {124},
    {125},
    {126},
    {127},
    {141},
    {147},
    {148},
    {150},
    {163},
    {164},
    {165},
    {169},
    {171},
    {172},
    {185},
    {186},
    {187},
    {189},
    {194},
    {208},
    {215},
    {216},
    {217},
    {219},
    {223},
    {224},
    {225},
    {226},
    {227},
    {228},
    {233},
    {240},
    {258},
    {259},
    {263},
    {272},
    {290},
    {294},
    {295},
    {296}
};
Reply
#2

For one, you don't need the extra dimension; this works too:
pawn Код:
new const BincoSkins[] = {1, 4, 5, 6, 7, 8, 9, ... }
Personally, I use this function to check if a value is present in an array:
pawn Код:
stock inArray(value, const array[], size = sizeof(array))
{
    for(new i; i < size; i++)
        if(array[i] == value) return true;

    return false;
}
Reply
#3

It could be better to do something like so:

pawn Код:
// Shop IDS
#define SHOP_BINCO 0
#define SHOP_SUBURBAN
#define SHOP_ZIP
#define SHOP_VICTIM

new shopSkins[] = {
SHOP_BINCO, // CJ - ID 0
SHOP_ZIP, // Skin 1
etc.
};
And then just do shopSkins[skinid] to see which shop it belongs to.
Reply
#4

Vince's solution has became much easier, efficent and quicker to perform.
Thanks for the array tip and the function, it works like a charm, and thanks to you too MP2.
Reply
#5

I wouldn't say more efficient.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)