OnVehicleDamageStatusUpdate
From SA-MP Wiki
(Difference between revisions)
Revision as of 05:05, 2 February 2014 Connor Mead (Talk | contribs) ← Previous diff |
Revision as of 23:18, 12 May 2015 MP2 (Talk | contribs) Next diff → |
||
Line 13: | Line 13: | ||
{{NoReturnCallback}} | {{NoReturnCallback}} | ||
+ | {{Example|Prevent tire popping}} | ||
<pawn> | <pawn> | ||
public OnVehicleDamageStatusUpdate(vehicleid, playerid) | public OnVehicleDamageStatusUpdate(vehicleid, playerid) | ||
- | { | + | { |
- | printf("Vehicle ID %d of playerid %d was damaged.", vehicleid, playerid); | + | // Get the damage status of all the components |
- | return 1; | + | new panels, doors, lights, tires; |
- | } | + | GetVehicleDamageStatus(vehicleid, panels, doors, lights, tires); |
- | </pawn> | + | |
- | <pawn> | + | // Set the tires to 0, which means none are popped |
+ | tires = 0; | ||
- | // example code: protect vehicle tires from being popped | + | // Update the vehicle's damage status with unpopped tires |
- | // uses encode_tires function from: http://forum.sa-mp.com/index.php?topic=161491.msg960040#msg960040 | + | |
- | + | ||
- | public OnVehicleDamageStatusUpdate(vehicleid, playerid) | + | |
- | { | + | |
- | #pragma unused playerid | + | |
- | + | ||
- | 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); | UpdateVehicleDamageStatus(vehicleid, panels, doors, lights, tires); | ||
return 1; | 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); | ||
} | } | ||
</pawn> | </pawn> |
Revision as of 23:18, 12 May 2015
Description:
This callback is called when a vehicle element such as doors, tires, panels, or lights get damaged.
(vehicleid, playerid)
vehicleid | The ID of the vehicle that was damaged. |
playerid | The ID of the player who synced the damage (who had the car damaged). |
Return Values:
This callback does not handle returns.
Example Usage: Prevent tire popping
public OnVehicleDamageStatusUpdate(vehicleid, playerid) { // Get the damage status of all the components new panels, doors, lights, tires; GetVehicleDamageStatus(vehicleid, panels, doors, lights, tires); // Set the tires to 0, which means none are popped tires = 0; // Update the vehicle's damage status with unpopped tires UpdateVehicleDamageStatus(vehicleid, panels, doors, lights, tires); return 1; }
Related Functions
The following functions might be useful, as they're related to this callback in one way or another.
- GetVehicleDamageStatus: Get the vehicle damage state for each part individually.
- UpdateVehicleDamageStatus: Update the vehicle damage.