how many players in vehicle
#1

Is there any way to check that how many players are in a vehicle? OR to check that if there is only 1 player in a car.
Reply
#2

Hi!

Yes, of course. You can use this function which I just wrote.
PHP код:
//The function you need:
stock GetVehiclePassengers(vehicleid)
{
    new 
passengers[MAX_VEHICLES];
    for(new 
i;i<MAX_PLAYERS;i++)
    {
        if(!
IsPlayerConnected(i) || IsPlayerNPC(i))continue;
        if(
GetPlayerVehicleID(i) == vehicleid)
        {
            
passengers[vehicleid] ++;
        }
    }
    return 
passengers[vehicleid];
}
//How many passengers are in this vehicle?
printf("Passengers in vehicleid %i: %i",vehicleid,GetVehiclePassengers(vehicleid));
//When you want to check wheather there is only one person in this vehicleid:
if(GetVehiclePassengers(vehicleid) == 1)printf("in vehicleid %i is only one passenger!",vehicleid); 
You have two examples how you can use this function.
Reply
#3

A better method is storing vehicles occupants as they enter/exit the vehicle as I suggested here.

This can be expanded to store passengers as well, example:
pawn Код:
new VehicleOccupants[MAX_VEHICLES][10];
// Store some extra seats for vehicles such as coach, etc
Reply
#4

thanks guys this helped me a lot +Reped
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)