> For the complete documentation index, see [llms.txt](https://mole-resource.gitbook.io/mole-resource-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mole-resource.gitbook.io/mole-resource-docs/scripts/recycling-system/faq.md).

# FAQ

> **Note on `examples.lua`:** this resource does **not** ship an `examples.lua` file. The integration snippets below are derived directly from the resource's real net events and ESX server callbacks (see [Configuration → Developer API](broken://pages/1f8c151f135d0a78c1c31482bb8a7ef03077bc12#developer-api)). They are ready to drop into your own resource.

***

## Integration examples

### 1. Trigger a bin search from your own code

The search flow (including the mini-game and cooldown/busy checks) starts by triggering the client event `mr_recycling:searchBin` with a bin entity:

```lua
-- CLIENT (your resource)
local bin = GetClosestObjectOfType(
    GetEntityCoords(PlayerPedId()), 2.0, GetHashKey("prop_bin_05a"), false, false, false
)

if bin ~= 0 then
    TriggerEvent('mr_recycling:searchBin', { binObject = bin })
    -- binConfig is auto-resolved from the entity's model if omitted
end
```

### 2. Sell recyclables at a machine / bin

```lua
-- CLIENT: open the "sell everything sellable" flow
TriggerEvent('mr_recycling:useRecyclingMachine', { machineObject = someMachineEntity })
TriggerEvent('mr_recycling:useRecyclingBin',     { binObject = someBinEntity })
```

Both scan the player's inventory (via server callbacks) and pay out instantly. If the player has nothing sellable they get the `item_missing` notification.

### 3. Add a custom target option (ox\_target) that reuses the flow

If you run your own targeting and set `Config.UseTarget = false`, you can still bind the events yourself:

```lua
-- CLIENT
exports.ox_target:addModel(GetHashKey("prop_bin_09a"), {
    {
        name  = "my_search_bin",
        icon  = "fas fa-search",
        label = "Search this bin",
        event = "mr_recycling:searchBin",   -- reuses the built-in flow
    }
})
```

### 4. Check a bin's cooldown / busy state from another script

```lua
-- CLIENT
local coords = GetEntityCoords(someBinEntity)

ESX.TriggerServerCallback('mr_recycling:checkBinCooldown', function(result)
    if result.isOnCooldown then
        print(("Bin on cooldown for %d more seconds"):format(result.remainingTime))
    end
end, coords)

ESX.TriggerServerCallback('mr_recycling:checkBinBusy', function(isBusy)
    print("Bin busy:", isBusy)
end, coords)
```

### 5. List what a player can currently recycle

```lua
-- CLIENT
ESX.TriggerServerCallback('mr_recycling:getRecyclableBinItems', function(items)
    for _, it in ipairs(items) do
        print(("%s x%d @ $%d each"):format(it.label, it.count, it.sellPrice))
    end
end)
```

### 6. Grant items/money directly (server-side style flows)

These are the events the reward system uses internally; you can trigger them from the client too (they resolve the player from `source`):

```lua
-- CLIENT
TriggerServerEvent('mr_recycling:giveItem', 'scrap_metal', 2)  -- adds 2 scrap_metal
TriggerServerEvent('mr_recycling:giveMoney', 150)              -- adds $150
```

> ⚠️ **Security:** these are unvalidated net events (as shipped). If you expose them to untrusted clients, players could self-grant items/money. Keep them internal, or add server-side validation before using them in production.

***

## Troubleshooting

### No blips / no props appear

* Object spawning waits for ESX player data (`ESX.GetPlayerData().job`) and for `esx:playerLoaded`. Make sure ESX is fully started and your character has loaded.
* Confirm `Config.RecyclingLocations` models exist. The default `mr_recyclingmachine` and `mr_recyclingbin` models are **custom** — install the stream resource or switch to base-game props.
* On resource restart the client deletes and re-spawns everything; a `refresh` + `ensure mr_recycling` cycle should re-create them.

### "Press E" doesn't show, but I have ox\_target installed

* If `Config.UseTarget = false`, targeting is ignored and only the help-notification loops run. Set `Config.UseTarget = true` to use targets.
* If `Config.UseTarget = true` but no target resource is started, the code falls back to `useTargetSystem = false` and **neither** targets nor the E-prompt loops run for world bins reliably — install/enable `ox_target` or `qtarget`, or set `Config.UseTarget = false`.

### Items are found but don't appear in inventory

* The item must exist in your inventory database (`items` table) or `ox_inventory` items file. Missing items make `addInventoryItem` silently fail. See [Installation → database](broken://pages/47bdf541feba8bec6aa6d05b53822c3ec54c1279#3-add-the-items-to-your-database). The shipped `recycling_items.sql` only covers 4 of the \~17 items.

### The mini-game is impossible to win / rewards feel halved

* Check `Config.GameDifficulty.successThreshold`. At `100`, anything below a perfect run is treated as failed (`0.5×`). Lower it (e.g. `80`) for a smoother payout curve.

### The trash icon or font look wrong

* `index.html` pulls Font Awesome from a CDN and `style.css` imports Roboto from Google Fonts. On offline clients these won't load — bundle them locally and add to `files`.

### Cooldown length doesn't match my config

* The **client** reads `Config.CooldownTime`, but the **server** enforces its own hard-coded `COOLDOWN_TIME = 300` (`server.lua`). Change both to keep them in sync.

### Two players can search the same bin at once

* This shouldn't happen: the server tracks `busyBins` and the client checks `mr_recycling:checkBinBusy` before starting. Busy state is also cleared on `playerDropped`. If it persists, verify the client isn't erroring mid-flow (which could skip the `setBinBusy(false)` cleanup).

### Discord logs aren't sending

* `Config.DiscordLogs.enabled` must be `true` **and** the relevant category webhook (`system` / `sales` / `finds` / `cooldowns`) must contain a real URL. Empty strings and the placeholder `TWOJ_DISCORD_WEBHOOK_URL_TUTAJ` are skipped.

***

## Frequently asked questions

**Q: Do I need a database / oxmysql?** A: Not for cooldowns — bin cooldown, busy, and temporary-lock state are all kept in server memory and reset on resource restart. You **do** need your inventory's item definitions in the DB (or ox\_inventory items file). The `@oxmysql/lib/MySQL.lua` line in the manifest is commented out.

**Q: Which frameworks are supported?** A: ESX Legacy (`es_extended`). The resource uses ESX-specific player methods and callbacks throughout.

**Q: Can I add my own bins/machines?** A: Yes. Add entries to `Config.RecyclingLocations` (spawned machines/bins) and/or `Config.Bins` (searchable world prop models with reward tables). See [Configuration](broken://pages/1f8c151f135d0a78c1c31482bb8a7ef03077bc12#world-locations).

**Q: Can I disable the mini-game and just sell items?** A: The mini-game only applies to **searching bins** (`Config.Bins`). Recycling machines and recycling bins (`Config.RecyclingLocations`) already sell instantly with no mini-game. If you don't want searchable bins, simply don't place any and don't trigger `mr_recycling:searchBin`.

**Q: Does the mini-game pause the player / lock movement?** A: While searching, the player is teleported to face the bin and plays the `PROP_HUMAN_BUM_BIN` scenario; NUI focus is taken until the game ends or Esc is pressed.
