# Optimization

This page will show you how to optimize the script, following all the instructions will improve the script performance

## Item check

Use these **server-side** events right after any item addition/removal, they can be used anywhere (if you replace the parameters with the proper ones)

```lua
TriggerEvent("framework:onItemAdded", playerId, itemName, itemCount)
```

```lua
TriggerEvent("framework:onItemRemoved", playerId, itemName, itemCount)
```

### Examples

Note: if you use something that is not listed in the examples, editing it is down to you, the events listed above works anywhere if used properly

#### ESX

**Note: default ESX already has `esx:onAddInventoryItem` and `esx:onRemoveInventoryItem` which will allow you to not add anything, so follow the example only if you don't have those events for any reason**

Go in `es_extended/server/classes/player.lua` and add the following codes

<figure><img src="https://3735039044-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFH9TH8An8XLjMiOMvVGb%2Fuploads%2Fgit-blob-9e92b91cc004e049da74ade3f0dc74fb3cfd0212%2Fimmagine.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3735039044-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFH9TH8An8XLjMiOMvVGb%2Fuploads%2Fgit-blob-8bc3619a9b4716d22dc33a4c9ca5bf5d3a6d4839%2Fimmagine.png?alt=media" alt=""><figcaption></figcaption></figure>

#### OX Inventory (ESX)

Go in `es_extended/server/classes/overrides/oxinventory.lua` and add the following codes

<figure><img src="https://3735039044-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFH9TH8An8XLjMiOMvVGb%2Fuploads%2Fgit-blob-35fb9b52c2d90f308fc87b8820daa17f198a5001%2Fimmagine.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3735039044-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFH9TH8An8XLjMiOMvVGb%2Fuploads%2Fgit-blob-4ca32b70f370bcd9f531243cb0d0676347a45ec5%2Fimmagine.png?alt=media" alt=""><figcaption></figcaption></figure>

#### QBCore (latest version)

Go in `qb-inventory/server/main.lua` and add the following codes

<figure><img src="https://3735039044-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFH9TH8An8XLjMiOMvVGb%2Fuploads%2Fgit-blob-204caf892148003c1c8db79c98d8761e6ec3e19e%2Fimmagine.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3735039044-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFH9TH8An8XLjMiOMvVGb%2Fuploads%2Fgit-blob-554ba2ce92c8a30e5d7535362c27c56d8aa81150%2Fimmagine.png?alt=media" alt=""><figcaption></figcaption></figure>

##


---

# 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://documentation.jaksam-scripts.com/trackers-creator/optimization.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.
