# Typeracer

## ⚙️Installation

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

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

**✅ Using the test command:**

Type command `/test_vise_typeracer_game` in-game.

{% tabs %}
{% tab title="Video preview" %}
{% embed url="<https://youtu.be/VuuLLhcNqk4?t=30>" %}
Game can be seen at 0:30-0:47
{% 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%2FeoSiJSswhtskGJtAq3My%2Fvise_typeracer_main.png?alt=media&#x26;token=e79a0e04-065d-4177-9ef9-7df92571478e" 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%2Fl1hlk6nNY8vT1bfuAZNB%2Fvise_typeracer_win.png?alt=media&#x26;token=619b3008-4f59-4362-83e2-b649541fc0f2" 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%2FHkMJ8MCyygSNy2agHzht%2Fvise_typeracer_loss.png?alt=media&#x26;token=07f4e39a-0b8c-40ec-9ea1-7b455e4c86f0" 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_typeracer_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_typeracer_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:

* `targetScore` – How many words the player has to type to complete the game *(default: 15)*
* `wordTimeout` – How long (in seconds) the player has to type each word *(default: 3)*

**Example settings:**

```lua
local settings = {
    targetScore = 15,
    wordTimeout = 3,
}
```

## 📦 Usage Examples

**Regular usage:**

```lua
local settings = {
    targetScore = 15,
    wordTimeout = 3,
}

local result = exports.vise_typeracer_game:start(settings)

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

**Callback usage:**

```lua
local settings = {
    targetScore = 15,
    wordTimeout = 3,
}

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