# Categories

> This is a step by step guide on how to create and configure new categories and packages correctly. Make sure to read and understand everything before you start modifying or adding any kind of code to the script.

{% hint style="info" %}
*If you feel that something is missing or unclear, please leave your feedback in my Discord's Support Channel.*
{% endhint %}

### Register your Category

* Go to **config/\_config.lua > Config.Categories** and add your new category (name and label).

<figure><img src="/files/jqDzYQw4C8lBHSwj7aLf" alt=""><figcaption></figcaption></figure>

* Create your **category.json** file in **categories folde**r and make sure is named exactly like the name you set in the previous step (for this example is weapons):

<figure><img src="/files/jmig5Fau75Yomj9JIrQ3" alt=""><figcaption></figcaption></figure>

* Start adding your products to the .json file, your package needs to contain the following fields (some are optional):
  * **value:** `string` same as key index, needs to be an unique identifier as string.
  * **label:** `string` package name, how the player will see it in the shop panel.
  * **moneySymbol (optional):** `string` currency symbol to display alongside the price.
  * **account:** `string` money account used to buy a package, the script currency is "tokens" but you can use your own as long as you edit the `removeMoney` function in server/editable/\_framework.lua.
  * **account\_label:** `string` used for the UI.
  * **price:** `number` the product price, needs to be a number.
  * **stock:** `number` product current stock, needs to be a number higher than 0 or the Buy button will be blocked.
  * **vip:** `boolean` only players with an active VIP membership will be allowed to buy from this category.
  * **preview (optional):** `boolean` allows the player to click the product image and zoom it.
  * **website (optional):** `string` the Buy Product button will redirect the player to a website, use a valid website URL like your Tebex store, etc.
  * **image (optional):** `string` Set a custom image for your package, don't use Discord or Imgur as hosting, use services like Fivemerr, Fivemanage, etc.

> Your .json should look *something* like this:

```json
{
    "weapon_assaultrifle": { // this is a key index, should be unique
        "value": "weapon_assaultrifle", // value should be same as key index
        "label": "Assault Rifle",
        "account": "tokens",
        "account_label": "Tokens",
        "price": 50,
        "stock": 999,
        "vip": true,
        "image": "https://www.gtabase.com/images/jch-optimize/ng/images_gta-5_weapons_assault-rifles_assault-rifle-mk2.webp"
    }
}
```

{% hint style="info" %}
You can add custom fields if needed. In **business.json**, you can see that I added the **job name** and **grade** the player will receive after purchasing the package, this fields are used in my **processBusiness()** function.
{% endhint %}

### Create your custom function

* Now we need to create our custom function, this function will be triggered when a player clicks the Buy Button and the money is debited from his account.
* Go to **av\_vip/server/editable** and create a new lua file, for this example I'll name it **\_weapons.lua**
* Inside this new file create a custom function, this function will receive 3 parameters: **source, category and product name**. I'll simply name it *processWeapon(source,category,product)*, should look something like this:

<figure><img src="/files/W8nOsqjnDTJinXZa6oQ4" alt=""><figcaption></figcaption></figure>

* Now go to **server/editable/buy.lua** and add your function in the **buyFunctions table**, like this:

<figure><img src="/files/12O51gxZ18D0zjlsAtZi" alt=""><figcaption></figcaption></figure>

<pre class="language-lua"><code class="lang-lua"><strong>['weapons'] = function(...) -- 'weapons' is the category name
</strong>    return processWeapons(...) -- processWeapons(...) is the name of your function
end,
</code></pre>

{% hint style="danger" %}
Don't remove the dots or your function will NOT receive any of the parameters (source, category, product).
{% endhint %}

* Now go back to your function and add your own logic, what do you want the code to trigger when a player buy your product?, for this example we are using weapons, in my server weapons are items so I need to add the weapon to the player inventory, something like this *works for this example*:

```lua
function processWeapons(source,category,product)
    dbug("processWeapons(source,category,product)", source, category, product)
    -- We need to access the product info by using Categories table > category name > product name
    local itemInfo = Categories[category] and Categories[category][product]
    if itemInfo then -- this contain the whole product info from the .json file
        -- print(json.encode(itemInfo, {indent = true}))
        local metadata = {
            ammo = 100
        }
        -- addItem needs the playerId, item name, amount and metadata (optional)
        addItem(source, product, 1, metadata)
    end
end
```

### Final Result

* After a script restart, our new category will look like this:

<figure><img src="/files/pMSAD9rB9VUrvs2emiHG" alt=""><figcaption></figcaption></figure>

* After buying my rifle, I get it with the amount of ammo I set in the metadata field:

<figure><img src="/files/P1QyYkZq3MMhWpf9BoaH" alt=""><figcaption><p>durability, ammo type and serial fields are defined by ox_inventory not my script</p></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://docs.av-scripts.com/guides/vip-script/categories.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.
