PutPlayerInEmptyVehicleSeat(vehicleid,playerid)
#1

It is from these threads https://sampforum.blast.hk/showthread.php?tid=274578

Код:
public PutPlayerInEmptyVehicleSeat(vehicleid,playerid)
{
    new bool:Seat[4];
    foreach (new i : Player)
    {
        if(IsPlayerConnected(i))
        {
            if(IsPlayerInVehicle(i,vehicleid))
            {
                if(GetPlayerVehicleSeat(i) == 0) Seat[0] = true;
                if(GetPlayerVehicleSeat(i) == 1) Seat[1] = true;
                if(GetPlayerVehicleSeat(i) == 2) Seat[2] = true;
                if(GetPlayerVehicleSeat(i) == 3) Seat[3] = true;
            }
        }
    }
    for(new a;a<sizeof(Seat);a++)
    {
        if(Seat[a] == false) PutPlayerInVehicle(playerid,vehicleid,a);
    }
    return 1;
}
You need to insert a player on the first free seat in the vehicle, but to throw it to the last seat.
Reply
#2

Reverse the loop:
pawn Код:
for (new a = sizeof (Seat) - 1; a > -1; --a)
and remove the IsPlayerConnected check because foreach loops through ONLY connected players so it's pointless.
Reply
#3

pawn Код:
public PutPlayerInEmptyVehicleSeat(vehicleid,playerid)
{
    new bool:Seat[4],seat;
    foreach(new i : Player)
    {
        if(IsPlayerInVehicle(i,vehicleid))
        {
            seat = GetPlayerVehicleSeat(i);
            if(!(0 <= seat < sizeof(Seat))) seat = sizeof(Seat)-1;
            Seat[seat] = true;
        }
    }

    for(new seatID = sizeof(Seat)-1; seatID > -1; seatID--)
        if(!Seat[seatID])
        {
            seat = INVALID_PLAYER_ID;
            PutPlayerInVehicle(playerid,vehicleid,seatID);
            break;
        }

    return seat;
}

example usage

new result = PutPlayerInEmptyVehicleSeat(vehicleid,playerid);
if(result != INVALID_PLAYER_ID)
{
    SendClientMessage(playerid,-1,"No empty seats");
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)