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; }
public OnGameModeInit()
{
SetTimer("CheckVehHealth", 1000, true);
return 1;
}
forward CheckVehHealth();
public CheckVehHealth()
{
new Float:g_VehHealth;
for(new x = 1, t = GetVehiclePoolSize(); x <= t; x++)
{
if(!GetVehicleModel(x)) continue;
GetVehicleHealth(x, g_VehHealth);
if(g_VehHealth < 250.0)
{
SetVehicleHealth(x, 250.0);
/* Check vehicle's health status here: https://sampwiki.blast.hk/wiki/VehicleHealth */
}
}
return 1;
}
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. |