SA-MP Forums Archive
Disable A Vehicle - 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: Disable A Vehicle (/showthread.php?tid=410866)



Disable A Vehicle - DJ_Shocker - 27.01.2013

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?


Re: Disable A Vehicle - Roach_ - 27.01.2013

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;
}



Re: Disable A Vehicle - Threshold - 27.01.2013

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