# Documentation

## Setup your framework

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

#### Config

```
Config.framework = "esx"
```

{% endtab %}

{% tab title="QB-Core" %}

#### Config

```
Config.framework = "qbcore"
```

{% endtab %}
{% endtabs %}

## Setup your inventory system

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

#### Config

```
Config.inventoryType = "esx"
```

{% endtab %}

{% tab title="QB-Core" %}

#### Config

```
Config.inventoryType = "qbcore"
```

{% endtab %}
{% endtabs %}

## Config

#### Money type

```
Config.moneyType            = "money" -- Money type from your framework
```

{% hint style="info" %}
After each sell you get $$, chose your

It's 'money' by default
{% endhint %}

#### Use ox\_target

```
Config.useOxTarget          = true -- Use ox_target or not
```

{% hint style="info" %}
This script can works with ox\_target
{% endhint %}

{% hint style="info" %}
If you don't use ox\_target, you can configure IN-GAME, the keybind.\
By default **T**

<pre class="language-lua"><code class="lang-lua"><strong>RegisterKeyMapping('sellDrugs', 'Sell Drugs', 'keyboard', 't')
</strong></code></pre>

{% endhint %}

#### Cops required and Count

```
Config.copsCountRefreshTime = 5     -- Time in minutes to refresh cops count
Config.minCopsOnline        = 0         -- Cops required to sell drugs
```

#### Ped reject and Ped Call Cops

```lua
Config.pedReject            = 25    -- Percent chance that the ped will reject the drugs
Config.pedCallCops          = 25    -- Percent chance that the ped will call the cops
```

{% hint style="info" %}
You can configure the percentage of chance that the ped will refuse your drugs and the percentage that he will call the police after the refusal
{% endhint %}

#### BlacklistedJobs and CallCopsJobs

```lua
Config.blacklistedJobs      = { "police", "bcso", "ambulance" } -- Job that can't sell drugs
Config.callCopsJos          = { "police", "bcso" }   -- Job who receive alert when ped call cops
```

{% hint style="info" %}
**BlacklistestJobs** are not allowed to sell drugs

**CallCopsJobs** will receive alerte after peds call him
{% endhint %}

#### Max drugs to sell

```lua
Config.maxDrugsToSell       = 10    -- Max drugs to sell at once
```

{% hint style="info" %}
Tha maxium amount of drugs you can sell at once
{% endhint %}

#### Drugs amount for price variation and PriceVariation

```lua
Config.drugsSellQttyForVariation = 10 --Qtty of drugs to sell for price variation
Config.drugsPriceVariation       = 0.05   -- 0.5% of variation
```

{% hint style="info" %}
**drugsSellQttyForVariation** represents the amount of drugs that all players must sell for a price variation to occur\
**drugsPriceVariation** represents the variation in % which will be applied to the current price
{% endhint %}

### Drugs

```lua
Config.Drugs = {
    weed = {            -- Item name
        price = 60,     -- Price of the item
        min = 40,       -- Min price of the item
        max = 80,        -- Max price of the item
        variation = {   -- Item variation when you sell more than Config.drugsSellQttyForVariation
            'meth'      -- Item name
        }
    },
    coke = {
        price = 80,
        min = 60,
        max = 100,
        variation = {
            'weed',
            'meth'
        }
    },
    meth = {
        price = 70,
        min = 50,
        max = 90,
        variation = {
            'cook'
        }
    }
}
```

{% hint style="info" %}
Here you can add your own drugs

* The array must be the name item name in your database (Not the label)
* price : The default price of the item
* min : The minimum price of the item (cannot go under after variation)
* max : The maximum price of the item (cannot go upper after variation)
* variation : The list of other drugs which impacted by the variation (see exemple above)
  {% endhint %}

## Client : Notify.lua

#### Notify

{% hint style="info" %}
You can change the lib.notify by your own notification system
{% endhint %}

```lua
---@param message string
---@param type 'success' | 'error'
function notify(message, type)
    lib.notify({
        title = locale('sell_drugs'),
        description = message,
        type = type,
    })
end
```

#### Call cops event

{% hint style="info" %}
You can implemente your system for cops notification after peds calling them
{% endhint %}

```lua
---@param streetName string
---@param coords vector3
---@param pedMugshot image
RegisterNetEvent('axio_sellDrugs:client:callCops', function(streetName, coords, pedMugshot)
 ...
end)
```

## Client : inventory.lua

{% hint style="info" %}
Si vous n'utilisez pas les inventaires ESX ou QB par default, vous pouvez configurer le votre ici
{% endhint %}

{% hint style="info" %}
**You must respect the format indicated in the file**
{% endhint %}

## Server : functions.lua

#### removeItemAndGiveMoney

{% hint style="info" %}
Here is the function call for remove the item from player inventory and give him money after selling drugs\
You can change for your own system with the param
{% endhint %}

<pre class="language-lua"><code class="lang-lua">---@param source int
---@param drug string
---@param qtty int
---@param price int
<strong>function removeItemAndGiveMoney(source, drug, qtty, price)
</strong>    if Config.framework == "esx" then
        player = ESX.GetPlayerFromId(source)
    elseif Config.framework == "qbcore" then
        player = QB.Functions.GetPlayer(source)
    end

    --[[ Remove item ]]
    if Config.inventoryType == "esx" then
        player.removeInventoryItem(drug, qtty)
    elseif Config.inventoryType == "qbcore" then
        player.Functions.RemoveItem(drug, qtty)
    end

    --[[ Give money ]]
    if Config.framework == "esx" then
        player.addAccountMoney(Config.moneyType, price)
    elseif Config.framework == "qbcore" then
        player.Functions.AddMoney(Config.moneyType, price)
    end
end
</code></pre>

#### call Cops Event

{% hint style="info" %}
This event is trigger when a ped call the cops
{% endhint %}

```lua
---@param streetName string
---@param coords vector3
---@param pedMugshot image
RegisterNetEvent('axio_sellDrugs:server:callCops', function(streetName, coords, pedMugshot)
 ...
end)
```


---

# 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://derass.gitbook.io/derass-script/sell-drugs-to-npc/documentation.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.
