Prevent a vehicle from exploding?
#1

I'm gonna create some lines in my game mode that prevents a vehicle from catching on fire and exploding, and instead leaves it smoking dark smoke...

How is this possible? May anyone help me a little, where to place the lines and such?

Already written this, but in OnPlayerUpdate it doesn't work:
Code:
new vehid = GetPlayerVehicleID(playerid);
  new Float:vehiclehealth;
  GetVehicleHealth(vehid, vehiclehealth);
  if(IsPlayerInAnyVehicle(playerid) && vehiclehealth <= 300){
    SetVehicleHealth(vehid, 300);
    TogglePlayerControllable(playerid, 0);
    SendClientMessage(playerid, RED, "The vehicle is broken. Press F or return to step out of the vehicle." );
    }
I've also done a onplayerkeychange or what it is so that if someone presses F or Return inside a vehicle they get unfrozen and removed from the vehicle.
Reply
#2

You'll wanna make vehicle health a float, not an integer. So..

pawn Code:
new Float:vehiclehealth;
Also I believe a vehicle catches alight at around 280 health? Not sure.
Reply
#3

I've already done that. And I've changed the vehicle health stuff to 300. But it catches on fire and explodes anyway. OnPlayerUpdate is maybe wrong place to place it?
Reply
#4

I think I've heard somewhere that the fire and exploding thing will happen even if the health is set to 1000.
Reply
#5

Hmm... You don't know a way to prevent that from happening? UG-RP(.net) has got this kind of system...
So it's possible...
Reply
#6

I've made It before,
1. Check (all) vehicle(s) health in a loop
2. If vehicles health is below 500, freeze player, remove from vehicle, unfreeze player
3. Put this in a 2 seconds or so timer
4. Done.

Aslong as there's someone in the vehicle the vehicle will take damage. And being on the edge like you were by
activating it first at 300 makes It very easy to go below that, which causes it to catch fire.

Once It catches fire there's no going back, It will explode.
Reply
#7

Quote:
Originally Posted by Mike Garber
View Post
I've made It before,
1. Check (all) vehicle(s) health in a loop
2. If vehicles health is below 500, freeze player, remove from vehicle, unfreeze player
3. Put this in a 2 seconds or so timer
4. Done.

Aslong as there's someone in the vehicle the vehicle will take damage. And being on the edge like you were by
activating it first at 300 makes It very easy to go below that, which causes it to catch fire.

Once It catches fire there's no going back, It will explode.
It catches fire at EXACTLY 250 and as Mike Garber said, when it catches fire there is no going back.
And why not use OnPlayerUpdate with a check to see if a player is in any vehicle like.

pawn Code:
public OnPlayerUpdate(playerid)
{
    if(IsPlayerInAnyVehicle(playerid))
    {
        new Float:health, veh;
        veh = GetPlayerVehicleID(playerid);
        GetVehicleHealth(veh, health);
        if(health <400)
        {
                RemovePlayerFromVehicle(playerid);
        }
    }
    return 1;
}
Now you can for example, make the vehicle go 'locked' that way you'll have to get a mechanic to come to the car to repair it.

(basicly told the idea I had for my own script lol)
Reply
#8

pawn Code:
public OnGameModeInit()
{
    SetTimer("OnVehicleUpdate", 1000, true);
    return 1;
}

forward OnVehicleUpdate();
public OnVehicleUpdate()
{
    for(new i = 0; i < MAX_VEHICLES; i++)
    {
        new Float: vHealth;
        GetVehicleHealth(i, vHealth);
        if(vHealth < 250)
        {
            SetVehicleHealth(i, 300.0);
        }
    }
    return 1;
}
Reply
#9

Quote:
Originally Posted by The_Moddler
View Post
pawn Code:
public OnGameModeInit()
{
    SetTimer("OnVehicleUpdate", 1000, true);
    return 1;
}

forward OnVehicleUpdate();
public OnVehicleUpdate()
{
    for(new i = 0; i < MAX_VEHICLES; i++)
    {
        new Float: vHealth;
        GetVehicleHealth(i, vHealth);
        if(vHealth < 250)
        {
            SetVehicleHealth(i, 300.0);
        }
    }
    return 1;
}
Why would you use a timer, when you can use a native function called 'OnPlayerUpdate'
Also the only thing yours does it setting the health back to 300 and like 'Mike Garber' said. When a vehicle is on fire there is no going back. And you set it back to 300 exactly at the moment it catches fire. It WON'T work the vehicle will just explode..
Reply
#10

Quote:
Originally Posted by playbox12
View Post
Why would you use a timer, when you can use a native function called 'OnPlayerUpdate'
Also the only thing yours does it setting the health back to 300 and like 'Mike Garber' said. When a vehicle is on fire there is no going back. And you set it back to 300 exactly at the moment it catches fire. It WON'T work the vehicle will just explode..
Oh, really? Did you even try?

OnPlayerUpdate is called 32 times in a second, there is no need too much presicion, also, a vehicle explodes in around 8 seconds, so you can actually set the timer to 2000 ms.

My code works fine.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)