Array of position
#1

Hello.

I don't know how to make it so I would be really grateful if someone could.

I need something like when a player joins something ( a spectactor team ) they will get the first position & then another player will get the second position. Like 1 position to each player who joins

Could anyone show me how?
Reply
#2

Well I think I understand what you mean, I guess you could just create an array with the amount of seats in the stadium, and then when someone joins, set them to the first empty one you find, using a loop, for example:

pawn Код:
new array[10];


// Player types /join or whatever your initializing phase is
for(new i; i < sizeof(array); i++)
{
    if(!array[i])
    {
        // Put the player in the seat
        array[i] = 1;
        return 1; // Stop the loop from continuing as we found an empty seat
    }
}
Does that help?

EDIT: Might even be a good idea to store what player is sitting in that seat, for future reference.
Reply
#3

Hm I think something like that, but I need more than 20 positions, so could you show the array, tried but failed
Reply
#4

I'm not sure what you mean, do you mean you want a multi-dimensional array to store some x,y,z co-ordinates? If so then you're looking for this:

pawn Код:
new Float:array[2][3] = {
    {0.0,0.0,0.0},
    {0.0,0.0,0.0}
};
Is that what you mean?
Reply
#5

Hm yes let me explain a bit better.

Example

Let's say a game is on, and someone wants to join. Then a player will get to the first position in the array & get freezed and no one else can use that position since its used, only when the player disconnected

If the first position is used, then the second player who joins will take the next position in the array & get freezed. then etc

So in the end lets say if 10 players join the game, there will be a nice line of 10 players who are freezed and their Angle will face on the game.

I hope I explained better, because I really suck at it
Reply
#6

Okay well then basically that's what the two snippets of code I posted do, for example:

pawn Код:
new Float:Positions[4][4] = {
    {0.0,0.0,0.0,0.0}, // X,Y,Z,A of Position 1
    {0.0,0.0,0.0,0.0}, // X,Y,Z,A of Position 2
    {0.0,0.0,0.0,0.0}, // X,Y,Z,A of Position 3
    {0.0,0.0,0.0,0.0} // X,Y,Z,A of Position 4
};

new Seats[4] = -1; // 4 Seats, all empty

// Find empty seat function and put player in it

stock PutPlayerInEmptySeat(playerid)
{
    for(new i; i < sizeof(Seats); i++)
    {
        if(!Seat[i]) // This seat is empty, do your thang
        {
            SetPlayerPos(playerid, Position[i][0], Position[i][1], Position[i][2]); // Put him in the x,y,z co-ords for that seat
            SetPlayerFacingAngle(playerid, Position[i][3]); // Set his angle for that seat
            TogglePlayerControllable(playerid, false);
            return i; // Return the seat ID
        }
    }
    return -1;
}

// Usage:

new seatid = PutPlayerInEmptySeat(playerid);
printf("Player was put in seat %d", seatid);
I hope that helps!
Reply
#7

Okay I tested it & seems like it's not changing to the second position, my friend and I we stayed at the same place

this is what I got

pawn Код:
new Float:Positions[2][4] = {
    {1443.3706,-2287.0959,13.5469,89.9231},
    {1553.2623,-1675.2860,16.1953,92.7704}
};

new Seats[2] = -1; // 4 Seats, all empty
pawn Код:
COMMAND:join(playerid, params[])
{
    new seatid = PutPlayerInEmptySeat(playerid);
    printf("Player was put in seat %d", seatid);
    return 1;
}
pawn Код:
stock PutPlayerInEmptySeat(playerid)
{
    for(new i; i < sizeof(Seats); i++)
    {
        if(!Seats[i]) // This seat is empty, do your thang
        {
            SetPlayerPos(playerid, Positions[i][0], Positions[i][1], Positions[i][2]); // Put him in the x,y,z co-ords for that seat
            SetPlayerFacingAngle(playerid, Positions[i][3]); // Set his angle for that seat
            TogglePlayerControllable(playerid, false);
            return i; // Return the seat ID
        }
    }
    return -1;
}
By the way, thank you so much for your help! SO Much!

I had another attempt, but failed. Could anyone show me? Or you could show me it JaTochNietDan?
Reply
#8

pawn Код:
new Float:Positions[2][4] = {
    {1443.3706,-2287.0959,13.5469,89.9231},
    {1553.2623,-1675.2860,16.1953,92.7704}
};

new Seats[2] = {999,...}; // 4 Seats, all empty

stock PutPlayerInEmptySeat(playerid)
{
    for(new i; i < sizeof(Seats); i++)
    {
        if(Seats[i] == 999) // This seat is empty, do your thang
        {
            Seats[i] = playerid;
            SetPlayerPos(playerid, Positions[i][0], Positions[i][1], Positions[i][2]); // Put him in the x,y,z co-ords for that seat
            SetPlayerFacingAngle(playerid, Positions[i][3]); // Set his angle for that seat
            TogglePlayerControllable(playerid, false);
            return i; // Return the seat ID
        }
    }
    return -1;
}
Reply
#9

I don't know what Jeff is doing there, but anyway the only problem is you're not setting the Seat variable which counts if the seat is empty or not, here is what you need to do:

pawn Код:
stock PutPlayerInEmptySeat(playerid)
{
    for(new i; i < sizeof(Seats); i++)
    {
        if(Seats[i] == -1) // This seat is empty, do your thang
        {
            Seats[i] = playerid; // Set the seat to the playerid, as it is taken
            SetPlayerPos(playerid, Positions[i][0], Positions[i][1], Positions[i][2]); // Put him in the x,y,z co-ords for that seat
            SetPlayerFacingAngle(playerid, Positions[i][3]); // Set his angle for that seat
            TogglePlayerControllable(playerid, false);
            return i; // Return the seat ID
        }
    }
    return -1;
}
Reply
#10

Hello JaTochNietDan.

I tested it with Sandboxie.

When I pressed join it put me in seat 0 the first pos in the array(before it was the 2nd pos) but now it's the first so it works.

Now when I go on the other account and I write test I don't get teleported.

This are the result the console printed

Код:
Player was put in seat 0 // first account
Player was put in seat -1 // second account
nvm.

Hi JaTochNietDan, figured out when

I try to /join twice with first account, first time it puts me in seat 0, then after seat -1. when it should just return seat 0 as he is already there, then the next account should be in seat 1 but it doesnt, still puts me in seat -1
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)