Checking If Someone Is In The Vehicle
#1

How would I check if anyone is currently in any seat of a vehicle by using the vehicles ID?

Like, IsAnyPlayerInVehicle(vehicleid);

or something like that?
Reply
#2

https://sampwiki.blast.hk/wiki/IsPlayerInAnyVehicle
Reply
#3

The states;
Код:
0 Empty (while initializing)
1 Player is on foot
2 Player is driver of a vehicle
3 Player is passenger of a vehicle
7 Player is wasted or on class selection
8 Player is spawned
Код:
 GetPlayerVehicleSeat(playerid);
Seats:
Код:
Seats:
0 - Driver
1 - Front passenger
2 - Back-left passenger
3 - Back-right passenger
4+ - Passenger seats (coach etc.)
Reply
#4

Quote:
Originally Posted by Ironboy
Посмотреть сообщение
I know about that,

I mean lets say the vehicle ID is 150, how do I check if anyone is in vehicle ID 150?
Reply
#5

IsPlayerInVehicle(playerid, vehicleid);
Reply
#6

Quote:
Originally Posted by Luis-
Посмотреть сообщение
IsPlayerInVehicle(playerid, vehicleid);
Would that not check if a certain player is in the vehicle?
Reply
#7

Код:
stock IsVehicleOccupied(vehicleid)
{
    for(new i =0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerInVehicle(i,vehicleid))
        {
            return 1;
        }
    }
return 0;
}
Reply
#8

Add this somewhere in your script
PHP код:
new count=0;
stock IsAnyPlayerInVehicle(vehicleid)
{
    for(new 
i=0;i<MAX_PLAYERS;i++)
    {
        if(
IsPlayerConnected(i))
        {
             if(
IsPlayerInVehicle(ivehicleid)) count++;
        }
    }
    if(
count>0) return 1;
    return 
0;

and use it like:
PHP код:
if(IsAnyPlayerInVehicle(<your vehicle id>))
{
    
//Your code

Reply
#9

Quote:
Originally Posted by ATGOggy
Посмотреть сообщение
Add this somewhere in your script
PHP код:
new count=0;
stock IsAnyPlayerInVehicle(vehicleid)
{
    for(new 
i=0;i<MAX_PLAYERS;i++)
    {
        if(
IsPlayerConnected(i))
        {
             if(
IsPlayerInVehicle(ivehicleid)) count++;
        }
    }
    if(
count>0) return 1;
    return 
0;

and use it like:
PHP код:
if(IsAnyPlayerInVehicle(<your vehicle id>))
{
    
//Your code

IsPlayerConnected is not really needed as a player can't be in a vehicle if they are not connected, as LarzI said elsewhere,
Quote:

The code becomes slower with an unnecessary check like that.

Reply
#10

Quote:
Originally Posted by RayC
Посмотреть сообщение
IsPlayerConnected is not really needed as a player can't be in a vehicle if they are not connected, as LarzI said elsewhere,
But if it is used in a command, it returns 'SERVER: Unrecognized command.' to the player. But here, it's not needed. Also, that doesn't make much lag bcz it's returning only yes or no.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)