# Item Probability

{% tabs %}
{% tab title="client" %}

```lua
RegisterNetEvent('gusti-lootcrate:openCrate')
AddEventHandler('gusti-lootcrate:openCrate', function()
    ESX.TriggerServerCallback('gusti-lootcrate:openCrate', function(success)
        if success then
            ESX.ShowNotification('You received an item!')
        else
            ESX.ShowNotification('You cannot carry more items.')
        end
    end)
end)
```

{% endtab %}

{% tab title="server" %}

```lua
ESX.RegisterServerCallback('gusti-lootcrate:openCrate', function(source, cb)
    local xPlayer = ESX.GetPlayerFromId(source)
    local item

    local chance = math.random(100)

    if chance <= 50 then
        item = 'legendary_item'
    elseif chance <= 80 then
        item = 'special_item'
    else
        item = 'epic_item'
    end

    if xPlayer.canCarryItem(item, 1) then
        xPlayer.addInventoryItem(item, 1)
        cb(true)
    else
        cb(false)
    end
end)
```

{% endtab %}
{% endtabs %}


---

# 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://aklgaming.gitbook.io/documentation/code-snippets/item-probability.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.
