# Pair Matching

## ⚙️Installation

1. Download `vise_pair_matching_game` resource from Cfx.re Keymaster
2. Extract `vise_pair_matching_game` into your server's resources directory
3. Add `ensure vise_pair_matching_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_pair_matching_game:start()

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

**✅ Using the test command:**

Type command `/test_vise_pair_matching_game` in-game.

{% tabs %}
{% tab title="Video preview" %}
{% embed url="<https://youtu.be/VuuLLhcNqk4?t=98>" %}
Game can be seen at 1:38-1:52
{% 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%2F0zUYyIRkVx41ZJPfseb2%2Fchrome_kxtYHLSqPZ.png?alt=media&#x26;token=26f6ea3d-0a14-4e48-ac33-e6ddb1905865" 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%2Fc6sLrPZQ9y21hjjFf8kj%2Fchrome_ViPet4Uxpq.png?alt=media&#x26;token=acb4473b-5922-4394-9821-ffd2c82d6c3f" 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%2FuInOipDtppzraYt8ucuJ%2Fchrome_ba0FpUqkX1.png?alt=media&#x26;token=3926b200-aa35-4b1c-96b1-40f5db0eed8b" 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_pair_matching_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_pair_matching_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:

* `numberOfPairs` – How many matching pairs the game should have *(default: 6)*
* `timeout` – How long (in seconds) the player has to finish the game *(default: 35)*

**Example settings:**

```lua
local settings = {
  numberOfPairs = 6,
  timeout = 35,
}
```

## 📦 Usage Examples

**Regular usage:**

```lua
local settings = {
  numberOfPairs = 6,
  timeout = 35,
}

local result = exports.vise_pair_matching_game:start(settings)

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

**Callback usage:**

```lua
local settings = {
  numberOfPairs = 6,
  timeout = 35,
}

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