SA-MP Forums Archive
How can I prevent passanger drive-by with no driver? - 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 can I prevent passanger drive-by with no driver? (/showthread.php?tid=369087)



How can I prevent passanger drive-by with no driver? - OleKristian95 - 15.08.2012

Does anyone know how I can prevent players from sitting in a vehicle as a passanger when there is no driver?


Re: How can I prevent passanger drive-by with no driver? - The_Asker - 24.08.2012

You need anti G-Bug


Re: How can I prevent passanger drive-by with no driver? - leonardo1434 - 24.08.2012

@better version is kar post's.


Re: How can I prevent passanger drive-by with no driver? - Kar - 25.08.2012

pawn Код:
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.
}