Usage
Call the minigames from your own scripts and handle the result.
Exports
All four are client-side. Call them from any client script.
StartAwait
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.
local success = exports['pixel-minigames']:StartAwait('lockpick', 'hard')
if success then
print('cracked it')
endReturns false immediately, without opening anything, if the game id is unknown or
another minigame is already running.
Start
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.
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
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
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.
if exports['pixel-minigames']:IsPlaying() then
exports['pixel-minigames']:Stop()
endAll parameters
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
falseand 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
falseas "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.
-- 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()
endgame is the id you passed to Start / StartAwait.
Example
A safe crack, three stages, any failure aborts the job.
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