Checking If Someone Is In The Vehicle -
Ciarannn - 25.01.2015
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?
Re: Checking If Someone Is In The Vehicle -
Ironboy - 25.01.2015
https://sampwiki.blast.hk/wiki/IsPlayerInAnyVehicle
Re: Checking If Someone Is In The Vehicle -
RayC - 25.01.2015
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.)
Re: Checking If Someone Is In The Vehicle -
Ciarannn - 25.01.2015
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?
Re: Checking If Someone Is In The Vehicle -
Luis- - 25.01.2015
IsPlayerInVehicle(playerid, vehicleid);
Re: Checking If Someone Is In The Vehicle -
Ciarannn - 25.01.2015
Quote:
Originally Posted by Luis-
IsPlayerInVehicle(playerid, vehicleid);
|
Would that not check if a certain player is in the vehicle?
Re: Checking If Someone Is In The Vehicle -
RayC - 25.01.2015
Код:
stock IsVehicleOccupied(vehicleid)
{
for(new i =0; i < MAX_PLAYERS; i++)
{
if(IsPlayerInVehicle(i,vehicleid))
{
return 1;
}
}
return 0;
}
Re: Checking If Someone Is In The Vehicle -
ATGOggy - 25.01.2015
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(i, vehicleid)) count++;
}
}
if(count>0) return 1;
return 0;
}
and use it like:
PHP код:
if(IsAnyPlayerInVehicle(<your vehicle id>))
{
//Your code
}
Re: Checking If Someone Is In The Vehicle -
RayC - 25.01.2015
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(i, vehicleid)) 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.
|
Re: Checking If Someone Is In The Vehicle -
ATGOggy - 25.01.2015
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.