Prevent Car Explosion
#1

Код:
forward OnVehicleDamageStatusUpdate(vehicleid,playerid);
public OnVehicleDamageStatusUpdate(vehicleid, playerid)
{
    new Float:f_vHealth;
    GetVehicleHealth(vehicleid, f_vHealth);
    if(f_vHealth < 500.0)
    {
        new engine, lights, alarm, doors, bonnet, boot, objective;
        GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
        SetVehicleParamsEx(vehicleid,VEHICLE_PARAMS_OFF,lights,alarm,doors,bonnet,boot,objective);
        GameTextForPlayer(playerid,"~r~Engine-Stalled",6000,6);
	}
	else
	{
		GetVehicleHealth(vehicleid, f_vHealth);
	 	if(f_vHealth < 400.0)
     	        SetVehicleHealth(vehicleid, 400);

	}
    return 1;
}
My problem is that the most times the car explodes. I mean the engine doesn't stall sometimes when its health is under 500 with the result of car explosion. For example if my vehicle gets damage with a gun the engine doesn't turn off and it catches fire... Any solution ?
Reply
#2

You must keep in mind that the SA-MP Wiki says "this does not include vehicle health changes" in OnVehicleDamageStatusUpdate, so... I guess you know you're able to put a car on fire (decrease its health) shooting it without damaging any of its components (panels, doors, lights, tires).

Anyway, you might use a global timer to check all vehicles' health.

EDIT #1: global timer.
PHP код:
public OnGameModeInit()
{
    
SetTimer("CheckVehHealth"1000true);
    return 
1;
}
forward CheckVehHealth();
public 
CheckVehHealth()
{
    new 
Float:g_VehHealth;
    for(new 
1GetVehiclePoolSize(); <= tx++)
    {
        if(!
GetVehicleModel(x)) continue;
        
        
GetVehicleHealth(xg_VehHealth);
        
        if(
g_VehHealth 250.0)
        {
            
SetVehicleHealth(x250.0);
            
/* Check vehicle's health status here: https://sampwiki.blast.hk/wiki/VehicleHealth */
        
}
    }
    return 
1;

Reply
#3

Quote:
Originally Posted by RIDE2DAY
Посмотреть сообщение
You must keep in mind that the SA-MP Wiki says "this does not include vehicle health changes" in OnVehicleDamageStatusUpdate, so... I guess you know you're able to put a car on fire (decrease its health) shooting it without damaging any of its components (panels, doors, lights, tires).

Anyway, you might use a global timer to check all vehicles' health.
Can you help me with the Global timer ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)