Disable A Vehicle
#1

I'm trying to figure out how to disable a vehicle from being driven if it's HP is at a certain level.

I run a heavy roleplay server and would like this achieved. This is what I have come up with:

pawn Код:
public CrashCar()
{
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
                if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
                {
                        new vehicle[MAX_PLAYERS];
                        vehicle[i] = GetPlayerVehicleID(i);
                        new Float:health;
                        GetVehicleHealth(vehicle[i], health);
                        if (health <= 500)
                        {
                                if (carcrashed[i] == 0)
                                {
                                    TogglePlayerControllable(i, 0);
                                    GameTextForPlayer(i, "~w~Your car is~n~~p~Broken", 3500, 1);
However, it seems that all someone has to do, is press their button to exit the vehicle, then they do, and then they can get back in and drive off.
Any ideas?
Reply
#2

Try this:
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    new Float:health;
    GetVehicleHealth(vehicleid, health);
    if (health <= 500)
    {
        if (carcrashed[vehicleid] == 0)
        {
            carcrashed[vehicleid] = 1;
            TogglePlayerControllable(playerid, 0);
            GameTextForPlayer(playerid, "~w~This car is~n~~p~Broken", 3500, 1);
        }
    }
    return 1;
}
Reply
#3

pawn Код:
public CrashCar()
{
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
                if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
                {
                        new vehicle[MAX_PLAYERS];
                        vehicle[i] = GetPlayerVehicleID(i);
                        new Float:health;
                        GetVehicleHealth(vehicle[i], health);
                        if (health <= 500)
                        {
                                if (carcrashed[i] == 0)
                                {
                                    TogglePlayerControllable(i, 0);
                                    GameTextForPlayer(i, "~w~Your car is~n~~p~Broken", 3500, 1);
                                    new engine, lights, alarm, doors, bonnet, boot, objective;
                                    GetVehicleParamsEx(GetPlayerVehicleID(i), engine, lights, alarm, doors, bonnet, boot, objective);
                                    SetVehicleParamsEx(GetPlayerVehicleID(i), 0, lights, alarm, doors, bonnet, boot, objective);
Basically, just add these three lines in to your crash function:

pawn Код:
new engine, lights, alarm, doors, bonnet, boot, objective;
                                    GetVehicleParamsEx(GetPlayerVehicleID(i), engine, lights, alarm, doors, bonnet, boot, objective);
                                    SetVehicleParamsEx(GetPlayerVehicleID(i), 0, lights, alarm, doors, bonnet, boot, objective);
https://sampwiki.blast.hk/wiki/GetVehicleParamsEx
https://sampwiki.blast.hk/wiki/SetVehicleParamsEx
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)