Damage Status
From SA-MP Wiki
(Difference between revisions)
Revision as of 23:25, 12 May 2015
Vehicle damage is stored in 4 values: Panels, Doors, Lights and Tires. Each value holds a bit mask of the state of all the panels/doors/light/tires. This means you need to use bitwise operators to work with them (most of the time).
For example, the 'tires' status stores 4 bits for the 4 tires. The value is 1 if the tire is popped, and 0 if it is not popped. So, for example, a value of '1010' means both the front tires are popped, and the rear ones are not.
To make working with these easier, there are some encoding and decoding functions, which can be found below with example usage.
decode_lights(lights, &light1, &light2, &light3, &light4) { light1 = lights & 1; light2 = lights >> 1 & 1; light3 = lights >> 2 & 1; light4 = lights >> 3 & 1; } decode_panels(panels, &front_bumper, &rear_bumper) { front_bumper= panels >> 20 & 15; rear_bumper = panels >> 24 & 15; } decode_doors(doors, &bonnet, &boot, &driver_door, &passenger_door) { bonnet = doors & 7; boot = doors >> 8 & 7; driver_door = doors >> 16 & 7; passenger_door = doors >> 24 & 7; } decode_tires(tires, &tire1, &tire2, &tire3, &tire4) { tire1 = tires & 1; tire2 = tires >> 1 & 1; tire3 = tires >> 2 & 1; tire4 = tires >> 3 & 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); }
For more info on tire states, see here.