> For the complete documentation index, see [llms.txt](https://botiv.gitbook.io/rdr2/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://botiv.gitbook.io/rdr2/weapon-cleaning-animation.md).

# 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.
