# Database Setup

### 📊 Required Tables

#### Table: `0r_multicharacterv3`

Stores additional character slot data for each player.

```sql
CREATE TABLE IF NOT EXISTS `0r_multicharacterv3` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `identifier` VARCHAR(100) NOT NULL,
    `character_slot` INT(11) NOT NULL DEFAULT 0,
    PRIMARY KEY (`id`),
    UNIQUE KEY `identifier` (`identifier`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
```

| Column          | Type         | Description                         |
| --------------- | ------------ | ----------------------------------- |
| id              | INT          | Auto-increment primary key          |
| identifier      | VARCHAR(100) | Player's license2 identifier        |
| character\_slot | INT          | Additional slots (added to default) |

#### Table: `0r_multicharacterv3_code`

Stores redeemable codes for extra character slots.

```sql
CREATE TABLE IF NOT EXISTS `0r_multicharacterv3_code` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `code` VARCHAR(100) NOT NULL,
    `slot` INT(11) NOT NULL DEFAULT 1,
    PRIMARY KEY (`id`),
    UNIQUE KEY `code` (`code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
```

| Column | Type         | Description                    |
| ------ | ------------ | ------------------------------ |
| id     | INT          | Auto-increment primary key     |
| code   | VARCHAR(100) | Unique redeemable code         |
| slot   | INT          | Number of slots the code gives |

***

### 🚀 Quick Setup

#### Using the SQL File

1. Locate `insert-me.sql` in the resource folder
2. Open your database management tool
3. Execute the entire SQL file

#### Manual Creation

Run these queries in your database:

```sql
-- Create character slot table
CREATE TABLE IF NOT EXISTS `0r_multicharacterv3` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `identifier` VARCHAR(100) NOT NULL,
    `character_slot` INT(11) NOT NULL DEFAULT 0,
    PRIMARY KEY (`id`),
    UNIQUE KEY `identifier` (`identifier`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Create redeemable codes table
CREATE TABLE IF NOT EXISTS `0r_multicharacterv3_code` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `code` VARCHAR(100) NOT NULL,
    `slot` INT(11) NOT NULL DEFAULT 1,
    PRIMARY KEY (`id`),
    UNIQUE KEY `code` (`code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
```

***

### 🎮 Framework-Specific Tables

The script also interacts with your framework's existing tables:

#### QBCore / QBox

| Table       | Usage                  |
| ----------- | ---------------------- |
| players     | Character data storage |
| playerskins | Character appearance   |

#### ESX

| Table                 | Usage                  |
| --------------------- | ---------------------- |
| users                 | Character data storage |
| (skin in users table) | Character appearance   |

{% hint style="info" %}
You don't need to modify framework tables. The script uses them as-is.
{% endhint %}

***

### 🏠 Optional: House Data (QBCore Only)

If you use `qb-houses`, the script reads from:

```sql
-- Used for house garage config
SELECT * FROM houselocations
```

Make sure your `houselocations` table exists if using housing.

***

### 🔧 Character Deletion Tables

When a character is deleted, the script removes data from configured tables. Default tables in `config/database.lua`:

#### QBCore Tables

```lua
['qb-core'] = {
    { table = 'players', column = 'citizenid', type = 'citizenid' },
    { table = 'playerskins', column = 'citizenid', type = 'citizenid' },
    { table = 'player_vehicles', column = 'citizenid', type = 'citizenid' },
    { table = 'player_houses', column = 'citizenid', type = 'citizenid' },
    { table = 'player_gangs', column = 'citizenid', type = 'citizenid' },
    -- Add more as needed
}
```

#### ESX Tables

```lua
['es_extended'] = {
    { table = 'users', column = 'identifier', type = 'citizenid' },
    { table = 'user_accounts', column = 'identifier', type = 'citizenid' },
    { table = 'user_inventory', column = 'identifier', type = 'citizenid' },
    -- Add more as needed
}
```

***

### 📝 Adding Custom Codes

To add redeemable slot codes manually:

```sql
-- Add a single-use code that gives 1 slot
INSERT INTO 0r_multicharacterv3_code (code, slot) VALUES ('FREESLOT2024', 1);

-- Add a code that gives 3 slots
INSERT INTO 0r_multicharacterv3_code (code, slot) VALUES ('VIP3SLOTS', 3);
```

Players can redeem these codes in the character selection UI.


---

# 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.0resmon.org/0resmon/0r-resources/0r-multicharacter-v3/getting-started/database-setup.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.
