# Weapon Cleaning Animation

## ⚡ Getting Started

**Be sure to read the README file for full setup instructions!**

***

## ➕ Cleaning a Weapon

You can clean a weapon with any of these methods:

#### With an Inventory Item

Use the item `"gunoil"` or any other defined in your inventory system.

#### Client-side Event

```lua
TriggerEvent("Botiv:cleanWeapon")
```

#### Command (if enabled)

Type in chat:

```
/cleanwp
```

#### Server-side Event

```lua
TriggerClientEvent("Botiv:cleanWeapon", source)
```

#### Inventory Integration Examples

**VORP Example**

```lua
-- For older VORP Inventory:
local VorpInv = exports.vorp_inventory:vorp_inventoryApi()
VorpInv.RegisterUsableItem("gunoil", function(data)
    TriggerClientEvent("Botiv:cleanWeapon", data.source)
end)

RegisterServerEvent("botiv-wpClean:itemUsed")
AddEventHandler("botiv-wpClean:itemUsed", function(used)
    if used then
        VorpInv.subItem(source, "gunoil", 1)
    end
end)

-- For newer VORP Inventory (using the export functions):
exports.vorp_inventory:registerUsableItem("gunoil", function(data)
    TriggerClientEvent("Botiv:cleanWeapon", data.source)
end, GetCurrentResourceName())

RegisterServerEvent("botiv-wpClean:itemUsed")
AddEventHandler("botiv-wpClean:itemUsed", function(used)
    if used then
        exports.vorp_inventory:subItem(source, "gunoil", 1)
    end
end)
```

**RedEM Example**

```lua
RegisterServerEvent("RegisterUsableItem:gunoil")
AddEventHandler("RegisterUsableItem:gunoil", function(source)
    TriggerClientEvent("Botiv:cleanWeapon", source)
end)

local data = {}
TriggerEvent("redemrp_inventory:getData", function(call)
    data = call
end)

RegisterServerEvent("botiv-wpClean:itemUsed")
AddEventHandler("botiv-wpClean:itemUsed", function(used)
    if used then
        local ItemData = data.getItem(source, 'gunoil')
        ItemData.RemoveItem(1)
    end
end)
```

***

## ⚙️ Configuration Example (`config.lua`)

```lua
Config = {
    -- Enable the /cleanwp command
    enable_command      = true,
    botiv_clean_cmd     = "cleanwp",          -- Command name
    enable_client_side  = true,               -- Enable client-side event call
    bt_c_function       = 'Botiv:cleanWeapon' -- Client event to trigger
}
```

> **Note:**\
> If you want to trigger cleaning with your own system, remove lines 14-28 from `client.lua` to disable the default triggers.

***

## 📌 Notes

* **Flexible Cleaning:** Weapons can be cleaned via inventory item, command, client/server events, or direct integration.
* **Configurable:** Change the command name, event, or disable automatic triggers easily in `config.lua`.
* **Supports VORP & RedEM:** Examples for both major RedM inventory frameworks.
* **No restart needed:** Any change to `config.lua` is applied instantly on resource restart.
* **Multilingual:** Interface and prompts can be adapted to your language.


---

# 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://botiv.gitbook.io/rdr2/weapon-cleaning-animation.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.
