# Server Settings

***

## 🔧 Configuration Options

All server settings are located in `shared/config.lua` under the **SERVER SETTINGS** section.

```lua
-- ════════════════════════════════════════════════════════════════════════════════════
--  SERVER SETTINGS
-- ════════════════════════════════════════════════════════════════════════════════════

Config.CreateAutoTable = true
Config.CraftingItemsRecovery = true
Config.SharedTables = false
```

***

## 📝 Setting Descriptions

### Automatic Database Creation

```lua
Config.CreateAutoTable = true
```

**Purpose**: Automatically create required database tables when the resource starts for the first time.

**Options**:

* `true` - Database tables are created automatically (recommended for easy setup)
* `false` - Tables must be created manually using `koja-crafting.sql`

**How it works**: When enabled, the script will execute SQL queries on first startup to create three tables:

{% stepper %}
{% step %}

### koja-crafting

Stores player data

Fields:

* `identifier` - Player identifier (steam, license, etc.)
* `blueprints` - JSON array of unlocked blueprints
* `level` - Current crafting level
* `exp` - Current experience points
  {% endstep %}

{% step %}

### koja-crafting-objects

Stores placed crafting stations

Fields:

* `id` - Unique object ID
* `craftingId` - Reference to crafting station config
* `model` - Prop model name
* `x`, `y`, `z`, `heading` - Object position and rotation
  {% endstep %}

{% step %}

### koja-crafting-queue

Stores crafting queue data

Fields:

* `id` - Unique queue item ID
* `identifier` - Player identifier
* `craftingTableId` - Which table is being used
* `itemName` - Item being crafted
* `itemImage` - Item image path
* `amount` - Quantity being crafted
* `craftingAmount` - Items per craft
* `exp` - Experience gained on completion
* `startTime`, `endTime` - Crafting timestamps
* `craftingTime` - Duration in seconds
* `completed` - Whether crafting is finished
  {% endstep %}
  {% endstepper %}

When to use each option:

✅ Use `true` (Auto-Create) when:

* First time installing the script
* Want quick and easy setup
* Don't have direct database access
* Prefer automated setup

✅ Use `false` (Manual Import) when:

* You have custom database naming conventions
* Want more control over table structure
* Already have tables from previous version
* Prefer manual database management

{% hint style="warning" %}
Auto-creation only runs if tables don't exist. It is safe to keep enabled — it won't overwrite existing tables. If manual import fails, enable auto-create and restart the resource. Requires `oxmysql` to be running before koja-crafting starts.
{% endhint %}

***

### Crafting Items Recovery

```lua
Config.CraftingItemsRecovery = true
```

**Purpose**: Save crafting progress to database, allowing players to recover items after disconnect, server crash, or restart.

**Options**:

* `true` - Crafting progress is saved to database (recommended)
* `false` - Crafting progress is lost on disconnect/restart

**How it works**:

{% stepper %}
{% step %}

### When enabled (true)

* Player starts crafting an item
* Progress is saved to `koja-crafting-queue` table
* If player disconnects, data remains in database
* When player reconnects, they can claim completed items
* Items show in queue menu with "CLAIM" button when ready
  {% endstep %}

{% step %}

### When disabled (false)

* Player starts crafting an item
* Progress stored only in memory (RAM)
* If player disconnects, crafting is lost
* If server restarts, all active crafts are cancelled
* No persistent storage
  {% endstep %}
  {% endstepper %}

Example Scenarios:

| Scenario                              | Recovery Enabled      | Recovery Disabled    |
| ------------------------------------- | --------------------- | -------------------- |
| Player crafts item, logs out normally | ✅ Can claim when back | ❌ Lost forever       |
| Server crashes during crafting        | ✅ Items recoverable   | ❌ All progress lost  |
| Player crashes/timeout                | ✅ Progress saved      | ❌ Must restart craft |
| Server restart for update             | ✅ Queue preserved     | ❌ Queue wiped        |

Recommendation:

* ✅ Keep enabled for player satisfaction — prevents frustration from lost items. Adds minimal performance impact (one INSERT per craft start and updates on completion).

**Performance Considerations**:

* Minimal database writes
* Negligible impact on modern MySQL servers
* Benefits outweigh the small overhead

***

### Shared Crafting Tables

```lua
Config.SharedTables = false
```

**Purpose**: Control whether crafting queues are shared between all players or personal to each player.

**Options**:

* `false` - Each player has their own private queue (default)
* `true` - All players share the same queue per crafting station

**How it works**:

Personal Queues (`false` - Default):

* Each player sees only their own crafting items
* Other players can't interact with your queue
* Items are bound to your character
* Prevents griefing

Shared Queues (`true`):

* All players see the same queue at each station
* Anyone can claim completed items (first come, first served)
* Promotes teamwork and collaboration
* Risk of item theft if not managed

Use Cases:

| Server Type           | Recommended Setting | Reason                |
| --------------------- | ------------------- | --------------------- |
| Public Server         | `false` (Personal)  | Prevents griefing     |
| Roleplay Server       | `true` (Personal)   | More realistic        |
| Gang/Faction Server   | `true` (Shared)     | Team collaboration    |
| Whitelisted Community | `true` (Shared)     | Trust between players |

{% hint style="info" %}
Advantages of Shared Tables:

* Gang members can craft for each other
* Multiple players can contribute to large crafts
* Faster production with team effort
* Promotes cooperation

Disadvantages:

* Players can steal others' items
* Requires trust and rules
* Can cause player conflicts
* Needs active moderation
  {% endhint %}

***

## 🔍 Troubleshooting

<details>

<summary>Tables not created automatically</summary>

* Check if `oxmysql` is running
* Verify database connection in server.cfg
* Check console for SQL errors
* Try manual import if auto-create fails

</details>

<details>

<summary>Recovery not working</summary>

* Verify `Config.CraftingItemsRecovery = true`
* Check if `koja-crafting-queue` table exists
* Look for database errors in console
* Ensure oxmysql is up to date

</details>

<details>

<summary>Shared tables not functioning</summary>

* Confirm `Config.SharedTables = true`
* Restart resource after config change
* Check if multiple players are at same station ID
* Verify station IDs match in config

</details>

<details>

<summary>Database permissions error</summary>

* Grant CREATE, INSERT, UPDATE, DELETE permissions
* Check MySQL user has table creation rights
* Verify connection credentials

</details>

***

## 📊 Monitoring Database Health (FOR EMERGENCY)

Check active crafting entries:

```sql
SELECT COUNT(*) FROM `koja-crafting-queue` WHERE completed = 0;
```

Check player progression:

```sql
SELECT identifier, level, exp FROM `koja-crafting` ORDER BY level DESC LIMIT 10;
```

Find stuck/old crafting items:

```sql
SELECT * FROM `koja-crafting-queue` 
WHERE completed = 0 
AND endTime < UNIX_TIMESTAMP(NOW()) * 1000;
```

***

## 📚 Related Settings

* For player data configuration, see [Player Progression](broken://pages/97dcc938d684589e8bf3d4cc3f52a50c8a513708)
* For queue behavior, see [Crafting Queue Settings](broken://pages/baa36ea91ce24d7e46c93259cd23f6549f3c81a6)
* For installation guide, see [Installation](broken://pages/6a0cb55688884f112e92be9d2da5b49be5732a40)


---

# 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.kojascripts.eu/new/crafting/configuration/server-settings.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.
