SA-MP Forums Archive
How can i make cars auto fix after being damaged? - 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: How can i make cars auto fix after being damaged? (/showthread.php?tid=297405)



How can i make cars auto fix after being damaged? - VG-Josh - 15.11.2011

Ok ive seen this on a server before but i dont know how to do it my self.
I would like to know how do i make a car auto fix itself?


Re: How can i make cars auto fix after being damaged? - BlackWolf120 - 15.11.2011

Just use GetVehicleHealth in a timer or in the callback OnPlayerUpdate (but if u want to loop through alot of vehicles id not use this callback due to lag!)


Re: How can i make cars auto fix after being damaged? - [MG]Dimi - 15.11.2011

PHP код:
public OnVehicleDamageStatusUpdate(vehicleidplayerid)
{
    
RepairVehicle(vehicleid);
    return 
1;

The simplest way. It will repair once vehicle damages, not if you use SetVehicleHealth!


Re: How can i make cars auto fix after being damaged? - bestr32 - 17.01.2012

If you wan't + the doors and everything paste this at the end of your script:
pawn Код:
public OnVehicleDamageStatusUpdate(vehicleid, playerid)
{
    #pragma unused playerid

    RepairVehicle(vehicleid);
    new panels, doors, lights, tires;
    GetVehicleDamageStatus(vehicleid, panels, doors, lights, tires);
    tires = encode_tires(0, 0, 0, 0); // fix all tires
    panels = encode_panels(0, 0, 0, 0, 0, 0, 0); // fix all panels //fell off - (3, 3, 3, 3, 3, 3, 3)
    doors = encode_doors(0, 0, 0, 0, 0, 0); // fix all doors //fell off - (4, 4, 4, 4, 0, 0)
    lights = encode_lights(0, 0, 0, 0); // fix all lights
    UpdateVehicleDamageStatus(vehicleid, panels, doors, lights, tires);
    return 1;
}

encode_tires(tire1, tire2, tire3, tire4) return tire1 | (tire2 << 1) | (tire3 << 2) | (tire4 << 3);
encode_panels(flp, frp, rlp, rrp, windshield, front_bumper, rear_bumper)
{
    return flp | (frp << 4) | (rlp << 8) | (rrp << 12) | (windshield << 16) | (front_bumper << 20) | (rear_bumper << 24);
}
encode_doors(bonnet, boot, driver_door, passenger_door, behind_driver_door, behind_passenger_door)
{
    #pragma unused behind_driver_door
    #pragma unused behind_passenger_door
    return bonnet | (boot << 8) | (driver_door << 16) | (passenger_door << 24);
}
encode_lights(light1, light2, light3, light4)
{
    return light1 | (light2 << 1) | (light3 << 2) | (light4 << 3);
}



Re: How can i make cars auto fix after being damaged? - iggy1 - 17.01.2012

RepairVehicle(vehicleid) function fixes everything including doors ect.


Re: How can i make cars auto fix after being damaged? - bestr32 - 17.01.2012

If you get an error for undefined or invalid OnVehicle blablabla (the public), you must define it like this: forward OnVehicleDamageStatusUpdate(vehicleid, playerid);


Re: How can i make cars auto fix after being damaged? - Konstantinos - 17.01.2012

Quote:
Originally Posted by bestr32
Посмотреть сообщение
If you get an error for undefined or invalid OnVehicle blablabla (the public), you must define it like this: forward OnVehicleDamageStatusUpdate(vehicleid, playerid);
I suggest you learn thr basic first before post something.
SA-MP Team have already made these callbacks and it's doesn't need to add the forward, only the public.
Also, I totally agree with the person above you. With this function, repair the vehicle ( all components and vhealth).