Door States

From SA-MP Wiki

Jump to: navigation, search

DoorStates can be used with the functions GetVehicleDamageStatus and UpdateVehicleDamageStatus.

Contents

Which bit stores what?

The damage of each door (note that the hood and the trunk are also doors) will be saved in 1 byte (which is 8 bits). You can only change the state of one bit for every door at each time - so you have to call the function twice if you want to damage and open the door.

  • The first bit stores whether the door is opened(1) or not(0) (the door will still lock (and change the first bit to 0) if closed - its just open)
  • The second bit stores whether the door is damaged(1) or not(0) (If you want a damaged door to turn normal you have to remove and re-attach it undamaged)
  • The third bit stores whether the door is removed(1) or attached(0)
  • The rest of the bits are empty

It seems like there is no bit which stores if the door will lock or not.

Notice that you count the bits from behind - so the first is the rightmost bit

Which byte stores what?

  • The first byte stores the state of the hood
  • The second byte stores the state of the trunk
  • The third byte stores the state of the drivers door
  • The fourth byte stores the state of the co-drivers door

The states of the 2 rear doors cannot be handled by GetVehicleDamageStatus and UpdateVehicleDamageStatus.

Notice that I count the bytes from behind - so the first is the rightmost byte

Example

The following code tells that the hood is removed, the front left door damaged, the front right door opened and the trunk is damaged and opened:

00000001 00000010 00000011 00000100

However SA-MP returns a decimal number so you have to convert it to a binary number first to get a result like above. What SA-MP would return you in this case is this:

16909060

Info table

First byte (hood):

0 (000)   1 (001)   2 (010)   3 (011)   4 (100)   5 (101)   6 (110)   7 (111)
  °--°      °[]°      °~~°      °{}°      °  °      °  °      °  °      °  °
  |  |      |  |      |  |      |  |      |  |      |  |      |  |      |  |
  °--°      °--°      °--°      °--°      °--°      °--°      °--°      °--°

Second byte (trunk):

0 (000)   1 (001)   2 (010)   3 (011)   4 (100)   5 (101)   6 (110)   7 (111)
  °--°      °--°      °--°      °--°      °--°      °--°      °--°      °--°
  |  |      |  |      |  |      |  |      |  |      |  |      |  |      |  |
  °--°      °[]°      °--°      °{}°      °  °      °  °      °  °      °  °

Third byte (drivers door):

0 (000)   1 (001)   2 (010)   3 (011)   4 (100)   5 (101)   6 (110)   7 (111)
  °--°      °--°      °--°      °--°      °--°      °--°      °--°      °--°
  |  |     --  |      §  |     ww  |         |         |         |         |
  °--°      °--°      °--°      °--°      °--°      °--°      °--°      °--°

Fourth byte (co-drivers door):

0 (000)   1 (001)   2 (010)   3 (011)   4 (100)   5 (101)   6 (110)   7 (111)
  °--°      °--°      °--°      °--°      °--°      °--°      °--°      °--°
  |  |      |  --     |  §      |  ww     |         |         |         |   
  °--°      °--°      °--°      °--°      °--°      °--°      °--°      °--°


Legend:

Static        Doors                    Hood / Trunk

° - Light      | - healthy, closed     -- - healthy, closed
              -- - healthy, opened     [] - healthy, opened
               § - damaged, closed     ~~ - damaged, closed
              ww - damaged, opened     {} - damaged, opened
                 - missing                - missing

Wrapper

Usefull little snippet to avoid working with the bits and bytes too much;

enum Door
{
	DOOR_HOOD,
	DOOR_TRUNK,
	DOOR_DRIVER
	DOOR_PASSENGER
}
 
enum DoorState(<<= 1)
{
	IS_OPENED = 1,
	IS_DAMAGED,
	IS_REMOVED
}
 
stock GetDoorState(doorStates, Door:door, DoorState:doorState)
	return (doorStates >>> (8 * door)) & doorState;

Example usage

new panels, doors, lights, tires;
GetVehicleDamageStatus(vehicleid,panels,doors,lights,tires);
 
 
// simple
if(GetDoorState(doors, DOOR_DRIVER, IS_DAMAGED))
{
    SendClientMessage(playerid, -1, "The driver door of your vehicle is damaged!");
}
 
// or even combined
if(GetDoorState(doors, DOOR_HOOD, IS_OPENED | IS_DAMAGED))
{
    SendClientMessage(playerid, -1, "The hood of your vehicle is both opened and damaged!");
}
Personal tools