# 💊 Sell Drugs

## INSTALLATION GUIDE

### <mark style="color:red;">Step 0 - First Steps</mark>

{% hint style="info" %}
Download [**is\_selldrugs**](https://keymaster.fivem.net/) from KeyMaster and install [**is\_bridge & is\_lib**](/documentation/free-scripts/bridge-and-library/usage-and-installation.md).
{% endhint %}

### <mark style="color:red;">Step 1 - Configure Resource</mark>

{% hint style="info" %}
You must read and configure the `config.lua` file in **is\_selldrugs** to meet your needs.
{% endhint %}

### <mark style="color:red;">Step 2 - Adding Items</mark>

{% hint style="info" %}
For the script to function correctly, it's essential to add specific items to your game's database. This section guides you through adding these items, particularly focusing on the phone item and new drugs.
{% endhint %}

### <mark style="color:purple;">**- Adding a Phone Item**</mark>

To use the Trap Phone and receive wholesale orders, you first need to **add the phone to your engine** (**QBCore/ESX**). The item name for the Trap Phone should match the one specified in `config.lua` (default `trap_phone`). [You can download the image for the Trap Phone that we use from here.](https://drive.google.com/file/d/1nSJVRzNsqxHEQLVYs163YUkLmyZ7UtJ3/view)

> #### Adding a Trap Phone to <mark style="color:green;">ESX Framework</mark>

1. **Access the Database**: Log in to your server's database management tool (like phpMyAdmin).
2. **Navigate to the `items` Table**: In your database, find the `items` table. This is where all the items for the game are defined.
3. **Insert New Item**: Add a new entry for the `trap_phone`. You can do this manually using the tool's interface, or you can run an SQL command.
4. **SQL Command for Adding Trap Phone**: To quickly add the item, execute the following SQL command:

   ```sql
   INSERT INTO `items` (`name`, `label`, `weight`, `rare`, `can_remove`) VALUES
   ('trap_phone', 'Trap Phone', 1, 0, 1);
   ```

   * `name`: 'trap\_phone' (This is the identifier used in your script)
   * `label`: 'Trap Phone' (The display name for the item)
   * `weight`: 1 (The weight of the item)
   * `rare`: 0 (Indicates the rarity, 0 for common)
   * `can_remove`: 1 (Whether the item can be removed from inventory)

> #### Adding a Trap Phone to <mark style="color:green;">QB-Core Framework</mark>

1. **Edit the QB-Core Shared File**:
   * Navigate to the `qb-core` folder.
   * Open the `shared/items.lua` file.
   * Add a line for the new item in the items list. For example:

     ```lua
     ['trap_phone'] = {['name'] = 'trap_phone', ['label'] = 'Trap Phone', ['weight'] = 500, ['type'] = 'item', ['image'] = 'trapPhone.png', ['unique'] = true, ['useable'] = true, ['shouldClose'] = true, ['combinable'] = nil, ['description'] = 'Maybe you will find more serious clients to talk to here.'},
     ```
   * This line defines the item's properties like name, label, weight, and image file.
2. **Add Image to QB-Inventory**:
   * Go to the `qb-inventory` folder.
   * Place the image for the item in the appropriate directory (usually in `html/img`).
   * Ensure the image file name matches the one specified in the shared file (`trapPhone.png`).

### <mark style="color:purple;">-</mark> <mark style="color:purple;">**Adding a Drugs Item**</mark>

In the `config.lua` file, you need to configure the list of items that players can sell. You need to provide data such as the item name, wholesale price, and retail price. When adding a new drug, you also need to add its image, for example, from your inventory system. To do this, you need to obtain the item image (**.png**), then name it the same as the drug name, and move it to `is_selldrugs/html/img/inventory`.

### <mark style="color:red;">Step 3 - SQL Database</mark>

{% hint style="info" %}
For the script to work correctly, it needs integration with the database. You can add it using the following SQL command or import the SQL file provided with the script.
{% endhint %}

```sql
CREATE TABLE `selldrugs_players` (
  `player` varchar(255) DEFAULT NULL,
  `respect` int(11) NOT NULL DEFAULT 0,
  `sale_skill` int(11) NOT NULL DEFAULT 0,
  `mole` varchar(1000) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
```

```sql
CREATE TABLE `selldrugs_phone` (
  `player` varchar(255) NOT NULL,
  `settings` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
```

### <mark style="color:red;">Step 4 - Install Dependencies</mark>

{% hint style="info" %}
To use the script, the following resources are required:
{% endhint %}

* [**is\_lib**](https://github.com/inside-scripts/is_lib) **-** and resources [**compatible with this library**](https://inside-scripts.gitbook.io/documentation/free-scripts/library), such as **framework**, **inventory**, **target**
* [**oxmysql**](https://github.com/overextended/oxmysql)

### Using a Trigger instead of a Command

In `config.lua`, set the value in the `cfg.commands.status` table to `nil` to disable the command. Once you've done that, use a Trigger to activate/deactivate retail sales.

{% tabs %}
{% tab title="Client-Side" %}

```lua
TriggerServerEvent("is_selldrugs:changeRetailStatus")
```

{% endtab %}

{% tab title="Server-Side" %}

```lua
TriggerEvent("is_selldrugs:changeRetailStatus", source)
```

{% endtab %}
{% endtabs %}

### Adding to Radial Menu

The above triggers may not work because some scripts, such as **qb-radialmenu**, send information about a table in the argument instead of the arguments or player ID we send. This can be solved by adding the following code to `config.lua`. We use it with the trigger type `client` and paste the trigger name, which is `is_selldrugs:radialMenu`.

```lua
RegisterNetEvent("is_selldrugs:radialMenu", function()
    TriggerServerEvent("is_selldrugs:changeRetailStatus")
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://inside-scripts.gitbook.io/documentation/paid-scripts/sell-drugs.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.
