How to check for vehicle passengers
#1

Hello,

Is it possible to check for vehicle passengers?

Regards, Jochem
Reply
#2

Check what ? Like if theres anyone in the vehicle as passenger or not ?
Reply
#3

Yes, that
Reply
#4

But I want this: the driver types /park. Then the vehicle gets linked to an interior and warped. The drivers interior gets set to the interior to. But how can I set the passengers interior?
Reply
#5

Hope this gives you an idea

Код:
for(new i = 0; i < MAX_PLAYERS; i++) // Scans from 1-Max player slots
{
if(IsPlayerConnected(i)) // Checks for all connected IDs
{
if(GetPlayerVehicleID(i) == GetPlayerVehicleID(playerid) && i != playerid) // Makes sure the connected IDs are in the car and is not the person that typed /park
{
SetPlayerInterior(i, [INTERIOR]); // Sets interior of the player found in the vehicle
}
}
}
It's untested, but I think it should work
Reply
#6

Of course, that must work
Reply
#7

With the native functions it is not possible.

But you could do something like this: (not tested)

pawn Код:
GetVehiclePassengers(vehicleid, &passengers[4])
{
    for(new i = 0; i < 4; i ++)
        passengers[i] = -1;
    for(new i = 0; i < MAX_PLAYERS; i ++)
        if(GetPlayerVehicleID(i) == vehicleid)
            passengers[GetPlayerVehicleSeat(i)] = i;
}
it should fill an array with the players on the seat 0-3 of vehicleid. If a seat is unoccupied, it returns -1 for the seat id.

EDIT: Paladin was faster, his code should fit perfectly to your needs
Reply
#8

@ Mauzen: How can I use that with interior? Does it need to be stored away into a variable?
Reply
#9

You would have to create an array, send it to the function, and then set the interior for all players in the array. So its more hard to use than Paladins code, but can be used for lots of other stuff, too.
Reply
#10

Indeed, I will add it into my gm
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)