15.08.2012, 18:48
Does anyone know how I can prevent players from sitting in a vehicle as a passanger when there is no driver?
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
if(ispassenger)
{
if(GetVehicleDriverCount(vehicleid) == 0)
{
ClearAnimations(playerid);
return 0;
}
}
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == PLAYER_STATE_PASSENGER)
{
new vehicleid = GetPlayerVehicleID(playerid);
if(GetVehicleDriverCount(vehicleid) == 0)
{
RemovePlayerFromVehicle(playerid);
}
}
return 1;
}
stock GetVehicleDriverCount(vehicleid) {
if ((vehicleid <= 0) || (vehicleid == INVALID_VEHICLE_ID) || (vehicleid > MAX_VEHICLES)) return INVALID_PLAYER_ID;
new totaldrivers = 0, i ;
for (i = 0; i < MAX_PLAYERS; i++)
{
if (IsPlayerConnected(i) == 0) continue;
if (GetPlayerState(i) != PLAYER_STATE_DRIVER) continue; // not a driver of any vehicle?
if (GetPlayerVehicleID(i) == vehicleid) // found a connected driver in this car.
{
totaldrivers++;
}
}
return totaldrivers; // return how many there are.
}