Looping thru array in 2 directions
#1

Hello folks.

I want to make a custom class selection. A couple of days ago, I had an idea to detect in which direction player is moving in class selection. It returns 1 for a move right and -1 for a move left.

Everything till here works perfect, however I came to face another problem. I am not that experienced with loops so I came here to seek for a little help of yours.

Here is my list of skins:

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] =
{
    {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}}
};
What I want to do is when player is switching keys into those two directions, set his skins.

From where I stuck was going from ID 0 to the last ID in the array. Lets say a player makes a whole turn left. In normal class selection you go to the last classid. What I look to do is go from ID 0 to the last ID 6 and the opposite, from 6 to 0.

Thank you.
Reply
#2

Quote:
Originally Posted by ******
Посмотреть сообщение
Have you tried y_classes? It does exactly what you just said.
I had a look there as well. The code looks complicated to me as I'm not that much experienced.

I also tried to use it but it was messing up with my script. When a player connects to the server, I set him to spectate in order to show him the intro, y_classes seems to go instantly to the class selection showing the class buttons which I want to be hidden during the intro. That's why I didn't use it.
Reply
#3

Quote:
Originally Posted by ******
Посмотреть сообщение
I did try to allow avoiding class selection, but I found that doing so broke the camera when you returned to it...
Alright. But is there actually a way to make what I'm looking for without y_classes. I already made the switching direction detect, now what's left is switching the skins with SetSpawnInfo and a loop which seems to be complicated for me to make.
Reply
#4

pawn Код:
pos[MAX_PLAYERS];

// Lets say that you're using OnPlayerClickPlayerTextDraw

public OnPlayerClickPlayerTextDraw(playerid, PlayerText:playertextid) {
    if (playertextid == tdLeft) {
        if ((pos[playerid] - 1) >= 0) {
            -- pos[playerid];
            SetPlayerSkin(playerid, cData[pos[playerid]][e_CLASS_SKIN]);
        }
    } else if (playertextid == tdRight) {
        if ((pos[playerid] + 1) < sizeof (cData)) {
            ++ pos[playerid];
           SetPlayerSkin(playerid, cData[pos[playerid]][e_CLASS_SKIN]);
        }
    }
}
Is that what you asked for?
Reply
#5

Quote:
Originally Posted by Djole1337
Посмотреть сообщение
pawn Код:
pos[MAX_PLAYERS];

// Lets say that you're using OnPlayerClickPlayerTextDraw

public OnPlayerClickPlayerTextDraw(playerid, PlayerText:playertextid) {
    if (playertextid == tdLeft) {
        if ((pos[playerid] - 1) >= 0) {
            -- pos[playerid];
            SetPlayerSkin(playerid, cData[pos[playerid]][e_CLASS_SKIN]);
        }
    } else if (playertextid == tdRight) {
        if ((pos[playerid] + 1) < sizeof (cData)) {
            ++ pos[playerid];
           SetPlayerSkin(playerid, cData[pos[playerid]][e_CLASS_SKIN]);
        }
    }
}
Is that what you asked for?
Looks like that however I need to try it. As I understand the pos[MAX_PLAYERS] is meant to hold the classid value, right?
Reply
#6

Lol, completely misread a question. Yeah it's supposed to hold class id.
Reply
#7

Quote:
Originally Posted by Djole1337
Посмотреть сообщение
No, In my case it's meant to be a global variable.
Obviously it's a variable. What I asked if this variable holds the player's classid value or if it should do so.
Reply
#8

Quote:
Originally Posted by Cypress
Посмотреть сообщение
Obviously it's a variable. What I asked if this variable holds the player's classid value or if it should do so.
Yes it does.
Reply
#9

Quote:
Originally Posted by Djole1337
Посмотреть сообщение
pawn Код:
pos[MAX_PLAYERS];

Then you should edit code like:
// Lets say that you're using OnPlayerClickPlayerTextDraw

public OnPlayerClickPlayerTextDraw(playerid, PlayerText:playertextid) {
    if (playertextid == tdLeft) {
        if ((pos[playerid] - 1) >= 0) {
            -- pos[playerid];
            SetPlayerSkin(playerid, cData[pos[playerid]][e_CLASS_SKIN]);
        } else {
            pos[playerid] = sizeof (cData); // lets set it to the highest possible skin ID from your class array;
        }
    } else if (playertextid == tdRight) {
        if ((pos[playerid] + 1) < sizeof (cData)) {
            ++ pos[playerid];
           SetPlayerSkin(playerid, cData[pos[playerid]][e_CLASS_SKIN]);
        } else {
            pos[playerid] = 0; // set it to 0
        }
    }
}
Something like that?
Reply
#10

Quote:
Originally Posted by Djole1337
Посмотреть сообщение
Something like that?
That's pretty much it. Thank you.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)