> For the complete documentation index, see [llms.txt](https://lunex-scripts.gitbook.io/lunex-scripts/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lunex-scripts.gitbook.io/lunex-scripts/lunex-scripts/lunex-mining-job.md).

# Lunex Mining Job

`lunex_mining` is a target-based mining job resource for FiveM ESX Legacy servers. It uses an NPC to open a custom NUI panel where players can start mining, create or join a team, request a work vehicle, process ores, buy required tools and sell processed materials on a changing market.

The resource is designed for ox-based servers and includes server-side checks against common client trigger abuse.

***

### Resource Name

```cfg
lunex_mining
```

Recommended location:

```txt
resources/[lunex]/[lunex]/lunex_mining
```

***

### Dependencies

Make sure these resources are installed and started before `lunex_mining`:

```cfg
ensure oxmysql
ensure ox_lib
ensure ox_target
ensure ox_inventory
ensure es_extended
ensure lunex_mining
```

Required dependencies:

| Dependency     | Purpose                                  |
| -------------- | ---------------------------------------- |
| `es_extended`  | ESX Legacy framework                     |
| `ox_lib`       | callbacks, dialogs and optional progress |
| `ox_target`    | NPC and rock target interactions         |
| `ox_inventory` | item handling                            |
| `oxmysql`      | saving mining XP                         |

***

### Installation

1. Put the resource folder into your server resources folder.
2. Add the ox\_inventory items from the item section below.
3. Copy item images into ox\_inventory.
4. Configure `config.lua`.
5. Add the resource to `server.cfg`.
6. Restart the server.

Example `server.cfg`:

```cfg
ensure oxmysql
ensure ox_lib
ensure ox_target
ensure ox_inventory
ensure es_extended
ensure lunex_mining
```

***

### SQL

No manual SQL import is required.

The script automatically creates this table on start:

```sql
CREATE TABLE IF NOT EXISTS lunex_mining_xp (
    identifier VARCHAR(64) NOT NULL PRIMARY KEY,
    xp INT NOT NULL DEFAULT 0,
    updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);
```

This table stores each player's mining XP.

***

### ox\_inventory Items

Add these items to:

```txt
ox_inventory/data/items.lua
```

```lua
['mining_pickaxe'] = {
    label = 'Csakany',
    weight = 1500,
    stack = false,
    close = true,
    description = 'Banyaszathoz szukseges eszkoz.'
},

['mining_mould'] = {
    label = 'Onto forma',
    weight = 1000,
    stack = false,
    close = true,
    description = 'Erc kiegetesehez szukseges forma.'
},

['mining_stone'] = {
    label = 'Ko',
    weight = 250,
    stack = true,
    close = false,
    description = 'Kibanyaszott ko.'
},

['mining_coal_ore'] = {
    label = 'Szen erc',
    weight = 350,
    stack = true,
    close = false,
    description = 'Nyers szen erc.'
},

['mining_copper_ore'] = {
    label = 'Rez erc',
    weight = 400,
    stack = true,
    close = false,
    description = 'Nyers rez erc.'
},

['mining_iron_ore'] = {
    label = 'Vas erc',
    weight = 450,
    stack = true,
    close = false,
    description = 'Nyers vas erc.'
},

['mining_gold_ore'] = {
    label = 'Arany erc',
    weight = 500,
    stack = true,
    close = false,
    description = 'Nyers arany erc.'
},

['mining_diamond_ore'] = {
    label = 'Gyemant nyersanyag',
    weight = 550,
    stack = true,
    close = false,
    description = 'Nyers gyemant erc.'
},

['smelted_coal'] = {
    label = 'Kiegetett szen',
    weight = 280,
    stack = true,
    close = false,
    description = 'Feldolgozott szen.'
},

['smelted_copper'] = {
    label = 'Kiegetett rez',
    weight = 320,
    stack = true,
    close = false,
    description = 'Feldolgozott rez.'
},

['smelted_iron'] = {
    label = 'Kiegetett vas',
    weight = 360,
    stack = true,
    close = false,
    description = 'Feldolgozott vas.'
},

['smelted_gold'] = {
    label = 'Kiegetett arany',
    weight = 400,
    stack = true,
    close = false,
    description = 'Feldolgozott arany.'
},

['cut_diamond'] = {
    label = 'Csiszolt gyemant',
    weight = 250,
    stack = true,
    close = false,
    description = 'Csiszolt gyemant.'
},
```

#### Item Images

The resource includes item images here:

```txt
lunex_mining/inventory_images
```

Copy the PNG images into:

```txt
ox_inventory/web/images
```

The file names must match the item names, for example:

```txt
mining_pickaxe.png
mining_mould.png
mining_coal_ore.png
smelted_gold.png
cut_diamond.png
```

***

### Basic Player Flow

1. Player targets the mining NPC with ox\_target.
2. Player opens the mining panel.
3. Player buys a pickaxe from the shop if needed.
4. Player starts the mining job solo or as a team.
5. Player can request a work vehicle.
6. Rocks spawn in the configured mining zone.
7. Player mines rocks using target interaction.
8. Player receives random ores based on config and level.
9. Player processes ores using the processing tab.
10. Player sells processed ores on the market.
11. XP is saved into SQL.

***

### Main Config Sections

Main config file:

```txt
lunex_mining/config.lua
```

#### Language

```lua
Config.Language = 'HU' -- 'HU' or 'EN'
```

Available languages:

| Code | Language  |
| ---- | --------- |
| `HU` | Hungarian |
| `EN` | English   |

Locale files:

```txt
locales/hu.lua
locales/en.lua
```

***

### Notification System

```lua
Config.Notify = 'lunex' -- 'lunex', 'esx', 'ox'
```

Options:

| Value   | Description                  |
| ------- | ---------------------------- |
| `lunex` | Uses Lunex notify resource   |
| `esx`   | Uses ESX notification        |
| `ox`    | Uses ox\_lib notify fallback |

Lunex notify resource name:

```lua
Config.NotifyOptions = {
    lunexResource = 'lunex_notify',
    duration = 5000
}
```

***

### Progressbar System

```lua
Config.Progress = {
    system = 'lunex',
    canCancel = true,
    color = '#38BDF8',
    position = 'bottom'
}
```

Supported values:

| Value            | Description                |
| ---------------- | -------------------------- |
| `lunex`          | Built-in Lunex progressbar |
| `ox_lib`         | ox\_lib progress circle    |
| `esx`            | ESX progressbar            |
| `mythic_progbar` | mythic progressbar         |
| `progressBars`   | progressBars resource      |
| `rprogress`      | rprogress resource         |

***

### NPC Config

```lua
Config.NPC = {
    coords = vector4(2952.72, 2745.31, 43.43, 19.0),
    model = 's_m_m_dockwork_01',
    scenario = 'WORLD_HUMAN_CLIPBOARD',
    labelKey = 'npc_label',
    targetIcon = 'fa-solid fa-helmet-safety',
    blip = {
        enabled = true,
        nameKey = 'npc_blip',
        sprite = 618,
        color = 46,
        scale = 0.82
    }
}
```

This NPC opens the mining panel through ox\_target.

***

### Vehicle Config

```lua
Config.Vehicle = {
    enabled = true,
    model = 'rebel',
    spawn = vector4(2961.91, 2746.62, 43.21, 284.0),
    plate = 'LUNEX',
    deleteOnJobEnd = true
}
```

Players can request the work vehicle from the panel after starting a job.

***

### Team System

```lua
Config.Team = {
    enabled = true,
    maxMembers = 4,
    inviteExpireSeconds = 45,
    teamXpBonusPercent = 15
}
```

Players can invite online players from the panel and mine together. Team members can receive an XP bonus based on config.

***

### XP System

```lua
Config.XP = {
    enabled = true,
    maxLevel = 30,
    xpPerLevel = 350,
    mineXP = 1,
    processXP = 18,
    sellXP = 10,
    levelBasedRewards = true
}
```

Mining XP can be configured per item:

```lua
mineXPByItem = {
    mining_stone = 1,
    mining_coal_ore = 3,
    mining_copper_ore = 5,
    mining_iron_ore = 8,
    mining_gold_ore = 15,
    mining_diamond_ore = 25
}
```

If `levelBasedRewards` is enabled, higher levels increase the chance of receiving more valuable ores through the `levelBonus` value in mining rewards.

***

### Required Tools

```lua
Config.Tools = {
    pickaxeItem = 'mining_pickaxe',
    mouldItem = 'mining_mould'
}
```

* Pickaxe is required for mining.
* Mould is required for processing if enabled.

***

### Mining Config

```lua
Config.Mining = {
    rockCount = 18,
    respawnDelay = 12000,
    mineDuration = 6500,
    serverCooldown = 5500,
    targetDistance = 2.0,
    objectiveBlip = true
}
```

#### Mining Zones

```lua
zones = {
    {
        center = vector3(2946.36, 2793.28, 40.75),
        radius = 45.0
    }
}
```

Rocks spawn randomly inside the configured zone.

#### Rock Props

```lua
rockProps = {
    'prop_rock_4_big2',
    'prop_rock_4_big',
    'prop_rock_3_b',
    'prop_rock_2_a'
}
```

#### Rewards

Each reward supports:

| Option       | Description              |
| ------------ | ------------------------ |
| `item`       | Item name                |
| `min`        | Minimum amount           |
| `max`        | Maximum amount           |
| `weight`     | Base chance weight       |
| `levelBonus` | Extra chance from levels |

Example:

```lua
{ item = 'mining_gold_ore', min = 1, max = 1, weight = 6, levelBonus = 4 }
```

***

### Processing / Smelting

```lua
Config.Processing = {
    enabled = true,
    requireMould = true,
    duration = 4500
}
```

Example recipe:

```lua
{
    raw = 'mining_iron_ore',
    rawAmount = 2,
    processed = 'smelted_iron',
    processedAmount = 1
}
```

If `requireMould` is true, the player must have the configured mould item.

***

### Shop System

```lua
Config.Shop = {
    enabled = true,
    account = 'money'
}
```

The panel allows players to select cash or bank payment.

Default shop items:

| Item    | Price |
| ------- | ----: |
| Pickaxe |   350 |
| Mould   |   450 |

***

### Market System

```lua
Config.Market = {
    enabled = true,
    account = 'money',
    priceUpdateMinutes = 15
}
```

Market prices update automatically every configured interval.

Players can:

* sell a custom amount,
* sell all of one selected item,
* keep other ores in their inventory.

Default market items:

| Item           | Min Price | Max Price |
| -------------- | --------: | --------: |
| Smelted coal   |        45 |        85 |
| Smelted copper |        80 |       150 |
| Smelted iron   |       120 |       210 |
| Smelted gold   |       320 |       560 |
| Cut diamond    |       750 |      1300 |

***

### Security / Anti Exploit Checks

The resource includes server-side validation for important actions:

* Mining reward cannot be given without a valid server session token.
* Mining checks active job state.
* Mining checks pickaxe ownership.
* Mining checks player distance to the mining zone.
* Mining has a server cooldown.
* Processing uses a server session token.
* Processing checks mould requirement.
* Processing checks required raw items.
* Shop, market and processing are restricted to NPC distance.
* Player session data is cleaned on disconnect.

This helps prevent simple client-side event abuse.

***

### Files That Can Be Edited

The following files are safe to edit for configuration and translation:

```txt
config.lua
locales/hu.lua
locales/en.lua
html/**/*
```

***

### Troubleshooting

#### NPC does not appear

Check:

* `ox_target` is started before `lunex_mining`.
* NPC model exists.
* Coords are correct.
* Resource has no console errors.

#### Panel does not open

Check:

* You are targeting the NPC.
* `ox_target` is running.
* `html/index.html`, `html/style.css`, `html/script.js` exist.

#### Items are not received

Check:

* Items are added to `ox_inventory/data/items.lua`.
* `ox_inventory` was restarted after adding items.
* Inventory is not full.

#### Item images are missing

Copy images from:

```txt
lunex_mining/inventory_images
```

to:

```txt
ox_inventory/web/images
```

Then restart ox\_inventory.

#### Bank payment does not work

Check your ESX bank account setup. The script supports standard ESX account methods, but your framework must have a working `bank` account.

#### XP is not saving

Check:

* `oxmysql` is started before the mining resource.
* Database connection is working.
* Console has no MySQL errors.

***

### Recommended Restart Order

After editing items or config:

```cfg
restart ox_inventory
restart lunex_mining
```

After editing only `config.lua`:

```cfg
restart lunex_mining
```

***

### Support Notes

Before asking for support, please check:

* server console errors,
* F8 client console errors,
* dependency start order,
* item names in ox\_inventory,
* config syntax.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://lunex-scripts.gitbook.io/lunex-scripts/lunex-scripts/lunex-mining-job.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
