> ## Documentation Index
> Fetch the complete documentation index at: https://docs.jaksam-scripts.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Optimization

> Hook into your inventory's item events to improve Trackers Creator performance.

This page shows you how to optimize the script. Following all the instructions below will improve the script's performance.

## Item check

Use these **server-side** events right after any item addition/removal. They can be used anywhere, as long as you replace the parameters with the proper ones.

```lua theme={null}
TriggerEvent("framework:onItemAdded", playerId, itemName, itemCount)
```

```lua theme={null}
TriggerEvent("framework:onItemRemoved", playerId, itemName, itemCount)
```

### Examples

<Note>
  If you use something that is not listed in the examples, editing it is up to you — the events listed above work anywhere if used properly.
</Note>

#### ESX

<Info>
  Default ESX already has `esx:onAddInventoryItem` and `esx:onRemoveInventoryItem`, which means you won't need to add anything. Only follow the example below if you don't have those events for any reason.
</Info>

Go to `es_extended/server/classes/player.lua` and add the following code:

<Frame>
  <img src="https://mintcdn.com/jaksam/cS_rA3IcGZ7NTj0G/images/immagine-2-1.png?fit=max&auto=format&n=cS_rA3IcGZ7NTj0G&q=85&s=d88303125c9d955b51c94f033f3d6f5b" alt="ESX item added/removed hook example 1" width="652" height="299" data-path="images/immagine-2-1.png" />
</Frame>

<Frame>
  <img src="https://mintcdn.com/jaksam/cS_rA3IcGZ7NTj0G/images/immagine-3.png?fit=max&auto=format&n=cS_rA3IcGZ7NTj0G&q=85&s=fb86973babfb7820b9cd00faf766d37d" alt="ESX item added/removed hook example 2" width="777" height="379" data-path="images/immagine-3.png" />
</Frame>

#### OX Inventory (ESX)

Go to `es_extended/server/classes/overrides/oxinventory.lua` and add the following code:

<Frame>
  <img src="https://mintcdn.com/jaksam/cS_rA3IcGZ7NTj0G/images/immagine-4-1.png?fit=max&auto=format&n=cS_rA3IcGZ7NTj0G&q=85&s=a36548992235d59e7918f046332d6745" alt="OX Inventory hook example 1" width="626" height="166" data-path="images/immagine-4-1.png" />
</Frame>

<Frame>
  <img src="https://mintcdn.com/jaksam/cS_rA3IcGZ7NTj0G/images/immagine.png?fit=max&auto=format&n=cS_rA3IcGZ7NTj0G&q=85&s=68b0a99ae22a608fb20c10e6a3931907" alt="OX Inventory hook example 2" width="645" height="171" data-path="images/immagine.png" />
</Frame>

#### QBCore (latest version)

Go to `qb-inventory/server/main.lua` and add the following code:

<Frame>
  <img src="https://mintcdn.com/jaksam/cS_rA3IcGZ7NTj0G/images/immagine-5-1.png?fit=max&auto=format&n=cS_rA3IcGZ7NTj0G&q=85&s=4af8bc5666aa514902387070cfb17def" alt="QBCore hook example 1" width="913" height="666" data-path="images/immagine-5-1.png" />
</Frame>

<Frame>
  <img src="https://mintcdn.com/jaksam/cS_rA3IcGZ7NTj0G/images/immagine-6.png?fit=max&auto=format&n=cS_rA3IcGZ7NTj0G&q=85&s=041507c082406954f7b070ad611878d6" alt="QBCore hook example 2" width="822" height="525" data-path="images/immagine-6.png" />
</Frame>


## Related topics

- [FAQ](/trackers-creator/faq.md)
- [Trackers Creator](/trackers-creator/home.md)
