19.03.2013, 13:35
I remembered that you can't hook functions using y_hooks and I couldn't figure out how to do it with ALS. Here's the new code, I added a game text and made the timer call every 3 seconds, instead of every 1.5. 3 seconds is still more than enough time.
Also note that the OnVehicleSpawn callback only gets called when a vehicle respawns. When I figure out the function hooking, I'll try to hook CreateVehicle to add the health check timer for you!

pawn Код:
new
Timer:healthCheckTimer[MAX_VEHICLES]
;
hook OnVehicleSpawn(vehicleid)
{
healthCheckTimer[vehicleid] = repeat checkVehicleHealth(vehicleid);
return 1;
}
hook OnVehicleDeath(vehicleid)
{
stop healthCheckTimer[vehicleid];
return 1;
}
timer checkVehicleHealth[3000](vehicleid)
{
new
Float:vehicleHealth
;
GetVehicleHealth(vehicleid, vehicleHealth);
if(vehicleHealth < 400.0)
{
foreach(new i : Player)
if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
if(GetPlayerVehicleID(i) == vehicleid) GameTextForPlayer(i, "~w~You broke the vehicle, ~r~idiot~w~!", 3000, 3);
SetVehicleHealth(vehicleid, 400.0);
new engine, lights, alarm, doors, bonnet, boot, objective;
GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
SetVehicleParamsEx(vehicleid, 0, lights, alarm, doors, bonnet, boot, objective);
}
return 1;
}