# Functions/Events

## server/editable-main.lua

### Server event: AssignIllness

`enyo-medical:AssignIllness`

```lua
RegisterNetEvent('enyo-medical:AssignIllness', function(targetId, condition)
    local src = source
    AssignIllness(targetId,  GetIllnessByName(condition))
end)
```

**Description:**\
Assigns a specific illness to a target player.\
This event can be triggered from other resources.

**Parameters:**

* `targetId`: Server ID of the target player.
* `condition`: Illness name to assign.

**Usage Example:**

```lua
TriggerEvent('enyo-medical:AssignIllness', playerId, "flu")
```

***

### Export: `TriggerIllness`

```lua
function TriggerIllness(playerId, illnessName, chance)
    if math.random() <= (chance / 100) then
        for _, condition in ipairs(Config.Conditions) do
            if condition.name == illnessName then
                AssignIllness(playerId, condition)
                return true
            end
        end
    end
    return false
end

exports('TriggerIllness', TriggerIllness)
```

**Description:**\
Triggers an illness on a player based on a percentage chance.

**Parameters:**

* `playerId`: Target player ID.
* `illnessName`: Name of the illness (must match `Config.Conditions`).
* `chance`: Probability of infection (0–100).

**Usage Example:**

```lua
exports['enyo-medical']:TriggerIllness(playerId, "cold", 50)
```

***

### Function: `RegisterTreatmentAsUsable`

```lua
function RegisterTreatmentAsUsable(itemName)
    -- Registers usable items for different inventory systems
end
```

**Description:**\
Registers treatment items (e.g., medicine) as usable based on the configured inventory system.\
When used, it triggers the treatment server event and removes the item.

**Parameter:**

* `itemName`: The name of the treatment item.

***

### Event: `onResourceStart`

```lua
AddEventHandler('onResourceStart', function(resourceName)
    if GetCurrentResourceName() == resourceName then
        for name, treatment in pairs(Config.Treatments) do
            RegisterTreatmentAsUsable(treatment.name)
        end
    end
end)
```

**Description:**\
Automatically registers all treatment items from `Config.Treatments` when the resource starts.


---

# 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://enyo-scripts.gitbook.io/documentations/fivem-scripts/illness-and-treatment-system/functions-events.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.
