# setVehicleDoorState (Shared)

> Changes the state of one or more doors of a vehicle: shut, open, damaged or missing.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Shared
- **Category**: Vehicles
- **URL**: https://wiki.mymp.gg/en/setVehicleDoorState

## Syntax

```lua
bool setVehicleDoorState(element vehicle, int|string|table door, int state [, bool spawnFlyingComponent = true])
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `vehicle` | `element` | The vehicle, or a parent element whose vehicles all change. |
| `door` | `int\|string\|table` | Which door: its number (0 the front lid, 1 the rear lid, 2 and 3 the front doors on the driver's and the passenger's side, 4 and 5 the rear ones), its frame name (`door_dside_f`; `left` and `right` in place of `dside` and `pside` follow the vehicle's driving side), a group (`all`, `side_doors`, `front_doors`, `rear_doors`, `left_doors`, `right_doors`), `-1` for all of them or a table of several. |
| `state` | `int` | The new state: 0 shut, 1 open, 2 shut and damaged, 3 open and damaged, 4 missing. |
| `spawnFlyingComponent` | `bool` | Whether a door that goes missing flies off as a loose piece. *(default: `true`)* |

## Returns

`true` if any door changed. `false` if the state is out of range, or the vehicle lacks the door or has no doors at all. On the server, also `false` when nothing changed.

Given a parent element such as `root`, it applies to every vehicle below it, but the value returned is the element's own: `false` when it is not a vehicle.

## Example

```lua
addCommandHandler("tirarportas", function(player)
    local vehicle = getPedOccupiedVehicle(player)
    if vehicle then
        setVehicleDoorState(vehicle, "side_doors", 4)
    end
end)
```

## See also

- [getVehicleDoorState (Shared)](https://wiki.mymp.gg/en/getVehicleDoorState.md): Returns the state of one or more doors of a vehicle.
- [setVehicleDoorOpenRatio (Shared)](https://wiki.mymp.gg/en/setVehicleDoorOpenRatio.md): Opens or closes one or more doors of a vehicle to a fraction, at once or over time.
- [fixVehicle (Shared)](https://wiki.mymp.gg/en/fixVehicle.md): Repairs a vehicle completely: its health goes back to 1000 and its doors, wheels and lights to their initial state, with no dents or bullet holes.
