Array manipulation
#1

Hello.

I'm creating a custom class selection and with my quite beginner experience I faced another problem during the day. I'm trying to list skins from array which I already achieved by some little help around the forums today, however another problem occurred.

Here is the current array I've been working on.

pawn Код:
enum e_CLASS_DATA
{
    e_CLASS_ID,
    e_CLASS_SKIN,
    e_CLASS_TEAM,
    e_CLASS_INTERIOR,
    Float:e_CLASS_POS[4]
};

new const cData[MAX_CLASSES][e_CLASS_DATA] =
{
        // Main Classes
    {0,  271, 0, 7, {766.6708,    -68.6765, 1001.5692, 270.0}},
    {1,  102, 1, 7, {766.6708,    -68.6765, 1001.5692, 270.0}},
    {2,  115, 2, 7, {766.6708,    -68.6765, 1001.5692, 270.0}},
    {3,  109, 3, 7, {766.6708,    -68.6765, 1001.5692, 270.0}},
    {4,  100, 4, 7, {766.6708,    -68.6765, 1001.5692, 270.0}},
    {5,  280, 5, 7, {766.6708,    -68.6765, 1001.5692, 270.0}},
    {6,    2, 6, 7, {766.6708,    -68.6765, 1001.5692, 270.0}},
   
        //Tree of skins only for the first class which is in case id 0 above
    {7,  271, 0, 3, {2496.0537, -1693.6073, 1014.7422, 180.6}},
    {8,  105, 0, 3, {2496.0537, -1693.6073, 1014.7422, 180.6}},
    {9,  106, 0, 3, {2496.0537, -1693.6073, 1014.7422, 180.6}},
    {10, 107, 0, 3, {2496.0537, -1693.6073, 1014.7422, 180.6}},
    {11, 269, 0, 3, {2496.0537, -1693.6073, 1014.7422, 180.6}},
    {12, 270, 0, 3, {2496.0537, -1693.6073, 1014.7422, 180.6}}
};
What I'm trying to do is actually like a small "binary tree". What I mean by this is that for example if you press shift in class ID 1, you will be forced to choose skins that are only related to class ID 1.

In my code above, there are all the "main classes" and the "tree of the first class only which is id 0. Alright, till here everything works fine.

What I was trying to make is so if I select ID: 0, then I can only switch between ID 7 and 12 and cannot switch the main ID's which are in case from 0 to 6.

Is there any possible way to do that?

EDIT:

A little idea came to my mind. I created a simple function which knows which skins are related to main class.

pawn Код:
stock name(playerid)
{
    for (new i = 0; i < MAX_CLASSES; i++)
    {
        if (pData[playerid][P_CLASS_REAL_ID] == cData[i][e_CLASS_TEAM])
        {
            printf("%d", i);
        }
    }
}
Dunno if it could get any useful.
Reply
#2

If I were you, I would just split up the arrays.
Код:
new const mainClassData[MAX_MAIN_CLASSES][e_CLASS_DATA] =
{
        // Main Classes
    {0,  271, 0, 7, {766.6708,    -68.6765, 1001.5692, 270.0}},
    {1,  102, 1, 7, {766.6708,    -68.6765, 1001.5692, 270.0}},
    {2,  115, 2, 7, {766.6708,    -68.6765, 1001.5692, 270.0}}
    // ...
};

new const subClassData[MAX_MAIN_CLASSES][MAX_SUB_CLASSES][e_CLASS_DATA] =
{
    {
            //Tree of skins only for the first class which is in case id 0 above
        {7,  271, 0, 3, {2496.0537, -1693.6073, 1014.7422, 180.6}},
        {8,  105, 0, 3, {2496.0537, -1693.6073, 1014.7422, 180.6}},
        {9,  106, 0, 3, {2496.0537, -1693.6073, 1014.7422, 180.6}},
        {10, 107, 0, 3, {2496.0537, -1693.6073, 1014.7422, 180.6}},
        {11, 269, 0, 3, {2496.0537, -1693.6073, 1014.7422, 180.6}},
        {12, 270, 0, 3, {2496.0537, -1693.6073, 1014.7422, 180.6}}
    },
    {
        // ... all subclasses of the second main class.
        {...},
        {...}
    },
    {
        // all subclasses of the third main class.
        {...},
        {...}
    }
};
Might not work with your fourth dimension at the class spawn position, but maybe you can split that one up in multiple variables.

If you are certain this is not what you want; you can use your name() function and every time the player goes to the next (or previous) class, you search for the next class with within the same category of the previous class.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)