SA-MP Forums Archive
how many players in vehicle - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: how many players in vehicle (/showthread.php?tid=603606)



how many players in vehicle - Alpha000 - 25.03.2016

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.


Re: how many players in vehicle - Mencent - 25.03.2016

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.


Re: how many players in vehicle - Abagail - 25.03.2016

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


Re: how many players in vehicle - Alpha000 - 27.03.2016

thanks guys this helped me a lot +Reped