# Body Damage

## Damage System API - LVS Inventory

### `GetPlayerDamage()`

Retrieves the current damage state of the player by body parts.

#### Description

Returns an object containing damage data for 6 main body zones, providing a simplified structure for external use.

#### Syntax

```lua
local damageData = exports['lvs_inventory']:GetPlayerDamage()
```

#### Return Value

**Type:** `table`

Object with the following properties:

* `head` (table): Head damage data
* `torso` (table): Upper torso damage data
* `leftArm` (table): Left arm damage data
* `rightArm` (table): Right arm damage data
* `leftLeg` (table): Left leg damage data
* `rightLeg` (table): Right leg damage data

Each body part contains:

* `percent` (number): Accumulated damage percentage (0-100)
* `bullets` (number): Number of bullet impacts received
* `severity` (boolean): Indicates if damage is severe
* `broken` (boolean): Indicates broken bones
* `bleeding` (boolean): Indicates if the zone is bleeding

#### Example

```lua
local damage = exports['lvs_inventory']:GetPlayerDamage()

if damage.head.percent > 50 then
    print('Critical head damage!')
end

if damage.leftLeg.broken then
    print('Left leg broken')
end
```

***

### `UpdatePlayerDamage()`

Updates damage for a specific body part and notifies linked systems.

#### Description

This function allows manual modification of the damage state for a specific body zone. It registers bullet impacts, updates damage percentage, and maintains negative states (severity, fractures, bleeding).

#### Syntax

```lua
exports['lvs_inventory']:UpdatePlayerDamage(bodyPart, bulletCount, newPercent, severity, broken, bleeding)
```

#### Parameters

| Parameter     | Type    | Description                                                                                      |
| ------------- | ------- | ------------------------------------------------------------------------------------------------ |
| `bodyPart`    | string  | Body part to update. Valid values: `head`, `torso`, `leftArm`, `rightArm`, `leftLeg`, `rightLeg` |
| `bulletCount` | number  | Number of bullet impacts to register (typically 1 per impact)                                    |
| `newPercent`  | number  | New damage percentage (0-100)                                                                    |
| `severity`    | boolean | Indicates if damage is severe                                                                    |
| `broken`      | boolean | Indicates broken bones                                                                           |
| `bleeding`    | boolean | Indicates if the zone is bleeding                                                                |

#### Behavior

* If `bodyPart` is invalid, defaults to `torso`
* Bullet impacts are accumulated to the existing counter
* Damage percentage is replaced with the new value
* Negative states are preserved if they already existed
* Automatically saves data to the server
* Triggers the `lvs_injury:client:UpdatePlayerDamage` event to notify other scripts

#### Example

```lua
-- Player shot in torso
exports['lvs_inventory']:UpdatePlayerDamage('torso', 1, 45, true, false, true)

-- Player falls and breaks leg
exports['lvs_inventory']:UpdatePlayerDamage('leftLeg', 0, 60, false, true, false)

-- Player receives severe head impact
exports['lvs_inventory']:UpdatePlayerDamage('head', 1, 85, true, true, true)
```

#### Notes

* This function is used internally by the system when a player takes damage
* Can be used externally to apply custom damage or synchronize states
* Changes are automatically persisted to the database

***

### Related Events

#### `lvs_injury:client:UpdatePlayerDamage`

Triggered whenever player damage is updated.

**Parameters:**

* `BodyParts` (table): Complete table with all body parts state

```lua
AddEventHandler('lvs_injury:client:UpdatePlayerDamage', function(bodyParts)
    -- Update health UI, apply effects, etc.
end)
```

#### `lvs_injury:client:ResetPlayerDamage`

Triggered when player damage is reset (e.g., after being revived).

***

### Common Use Cases

#### Check player condition

```lua
local damage = exports['lvs_inventory']:GetPlayerDamage()
local totalDamage = 0

for _, part in pairs(damage) do
    totalDamage = totalDamage + part.percent
end

if totalDamage > 300 then
    -- Player heavily injured, will need medical attention
end
```

#### Apply fall damage

```lua
local fallHeight = 15.0
if fallHeight > 10.0 then
    local damagePercent = math.floor((fallHeight - 10) * 2)
    exports['lvs_inventory']:UpdatePlayerDamage(
        'leftLeg', 
        0, 
        damagePercent, 
        false, 
        fallHeight > 20, 
        false
    )
end
```

***

#### Medical treatment system example

```lua
function TreatBleeding(playerPart)
    local damage = exports['lvs_inventory']:GetPlayerDamage()
    
    if damage[playerPart] and damage[playerPart].bleeding then
        -- Apply bandage
        exports['lvs_inventory']:UpdatePlayerDamage(
            playerPart,
            0,
            damage[playerPart].percent,
            damage[playerPart].severity,
            damage[playerPart].broken,
            false -- Stop bleeding
        )
    end
end
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://fivem.lvsoft.com.ar/qb-esx/lvs-inventory/body-damage.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
