Skip to content

Usage

Call the minigames from your own scripts and handle the result.

On this page9

Exports

All four are client-side. Call them from any client script.

ExportReturnsDescription
StartAwaitbooleanOpens a minigame, yields, returns whether the player won.
StartbooleanNon-yielding version. Fires a callback when the game ends.
StopnothingForce-closes the running minigame.
IsPlayingbooleanWhether a minigame is currently open.

StartAwait

lua
exports['pixel-minigames']:StartAwait(game, difficulty, speed, size, title, count, time, threshold, maxErrors)

Yields the current thread until the player wins, loses or presses Esc. Returns true only on a win. Everything after game is optional, omit it all and the game tunes itself off difficulty alone.

lua
local success = exports['pixel-minigames']:StartAwait('lockpick', 'hard')
 
if success then
    print('cracked it')
end

Returns false immediately, without opening anything, if the game id is unknown or another minigame is already running.

Start

lua
exports['pixel-minigames']:Start(game, cb, difficulty, speed, size, title, count, time, threshold, maxErrors)

The non-yielding form. The callback is the second argument; every parameter after it follows the same order as StartAwait.

lua
exports['pixel-minigames']:Start('wires', function(success)
    if success then
        TriggerServerEvent('myheist:doorOpened')
    end
end, 'hard')

cb receives true on a win and false on a loss or cancel. Start itself returns true if the minigame opened, or false if it was rejected, in which case cb is still called once with false.

Stop

lua
exports['pixel-minigames']:Stop()

Closes whatever is on screen and releases NUI focus. The pending callback resolves as a failure. Safe to call when nothing is running. Use it to abort the active minigame.

IsPlaying

lua
exports['pixel-minigames']:IsPlaying()

true from the moment a minigame opens until its callback has fired. Use it to guard against opening a second game on top of the first or do other checks.

lua
if exports['pixel-minigames']:IsPlaying() then
    exports['pixel-minigames']:Stop()
end

All parameters

ParameterTypeDescription
gamestringThe game id.
difficultystring|number15, or 'easy', 'normal', 'medium', 'hard', 'expert'. Default 2.
speednumberHow fast the game moves.
sizenumberBoard / target / gap size.
titlestringHeader text on the panel.
countnumberHow many of the thing, pins, notes, rounds, tiles.
timenumberTime limit in seconds.
thresholdnumberTolerance / hit window / target value.
maxErrorsnumberMistakes allowed before failing.

Pass nil for anything you don't want to override. Meanings are per-game, and not every game reads every parameter, see the game reference for what each one uses.

Behaviour

  • One at a time. Starting a minigame while another is open returns false and leaves the running one alone. An unknown game id does the same.
  • Escape cancels. The player can always press Esc. That resolves as a failure, treat false as "didn't complete it", not necessarily "got it wrong".

Hooks

client/editable.lua runs two hooks around every minigame. It's outside the escrow, so edit it freely.

lua
-- Runs right before a minigame opens (NUI focus has just been grabbed).
function Minigames.Editable.OnStart(game)
    -- ToggleHud()
end
 
-- Runs right after a minigame closes (NUI focus has just been released).
function Minigames.Editable.OnFinish(game, success)
    -- ToggleHud()
end

game is the id you passed to Start / StartAwait.

Example

A safe crack, three stages, any failure aborts the job.

lua
local function crackSafe(safeId)
    if exports['pixel-minigames']:IsPlaying() then return end
 
    local success = exports['pixel-minigames']:StartAwait('locksmith', 'hard', nil, nil, 'Cracking Safe')
 
    if success then
        TriggerServerEvent('myheist:safeCracked', safeId)
    end
end