# Data Miner

## ⚙️Installation

1. Download `vise_data_miner_game` resource from Cfx.re Keymaster
2. Extract `vise_data_miner_game` into your server's resources directory
3. Add `ensure vise_data_miner_game` to your `resources.cfg`

## 🕹️ Starting the Game

You can either **start the game through your own scripts** or use **the test command.**

**✅ Starting through your own scripts:**

```lua
local result = exports.vise_data_miner_game:start()

print('game ended with result:', result)
```

**✅ Using the test command:**

Type command `/test_vise_data_miner_game` in-game.

{% tabs %}
{% tab title="Video preview" %}
{% embed url="<https://youtu.be/VuuLLhcNqk4?t=116>" %}
Game can be seen at 1:56-2:07
{% endembed %}
{% endtab %}

{% tab title="Image preview" %}

<div><figure><img src="https://624746648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3LzeOMV7JHxsxfU16ab1%2Fuploads%2FWVqAWDO3d92piE9pqDYL%2Fvise_data_miner_main.png?alt=media&#x26;token=f980a0d3-0491-4a19-be0e-a1795d610183" alt=""><figcaption><p>Game main screen</p></figcaption></figure> <figure><img src="https://624746648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3LzeOMV7JHxsxfU16ab1%2Fuploads%2Fscy6Yci4KWvw8NFbA57y%2Fvise_data_miner_win.png?alt=media&#x26;token=0affd646-b2bb-4523-9638-8afdcf04a91d" alt=""><figcaption><p>Success screen</p></figcaption></figure> <figure><img src="https://624746648-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3LzeOMV7JHxsxfU16ab1%2Fuploads%2FasozUdOPygiEfZK2MNYe%2Fvise_data_miner_loss.png?alt=media&#x26;token=42f9a142-00bc-438d-82f3-dc52466ed59d" alt=""><figcaption><p>Failure screen</p></figcaption></figure></div>
{% endtab %}
{% endtabs %}

🔄 **Result (return value)**

The `start()` function will return `true` if the player finishes the game, or `false` if they fail or run out of time.\
\
If you're using a **callback**, the same `true` or `false` will be passed into the callback function.

```lua
local result = exports.vise_data_miner_game:start()

if result then
    print('game completed')
else
    print('game failed')
end

-- You can also optionally use a callback to determine if game was completed or not
exports.vise_data_miner_game:start(settings, function(result)
    if result then
        print('game completed')
    else
        print('game failed')
    end
end)
```

## 🔧 Settings

When starting the game, you can pass a **settings table** to customize how the game works.

Here are the available setting options:

* `gridWidth` – The number of columns in the game grid. A wider grid gives the player more horizontal space to navigate *(default: 9)*
* `gridHeight` – The number of rows in the game grid. A taller grid gives the player more vertical space to navigate *(default: 9)*
* `hazardCount` – The total number of hidden hazards placed randomly on the grid. The player must avoid these while uncovering safe tiles. *(default: 5)*
* `timeout` – How long (in seconds) the player has to complete the game *(default: 60)*

**Example settings:**

```lua
local settings = {
    gridWidth = 9,
    gridHeight = 9,
    hazardCount = 5,
    timeout = 60,
}
```

## 📦 Usage Examples

**Regular usage:**

```lua
local settings = {
    gridWidth = 9,
    gridHeight = 9,
    hazardCount = 5,
    timeout = 60,
}

local result = exports.vise_data_miner_game:start(settings)

if result then
    print('game completed')
else
    print('game failed')
end
```

**Callback usage:**

```lua
local settings = {
    gridWidth = 9,
    gridHeight = 9,
    hazardCount = 5,
    timeout = 60,
}

exports.vise_data_miner_game:start(settings, function(result)
    if result then
        print('game completed')
    else
        print('game failed')
    end
end)
```
