JRS COREDocs

Client UI helpers

Text and yes/no dialogs, the styled input box, the progress bar and the animation loaders that jrs_core gives every client script.

Everything on this page runs on the client and ships inside jrs_core itself, so there is no extra resource to start. Most helpers hang off the client core object; a few are plain jrs_core exports or events for scripts that do not hold the object.

lua
local Core = exports.jrs_core:getCoreApi()

Dialogs#

Every dialog comes in a callback form and a blocking form, so pick whichever reads better in your thread. Only one dialog is open at a time: opening a new one closes the current one first.

Text Box#

Client

GetInput

#
Core.GetInput(title, subtext, cb, options?)

Opens the text box and returns at once. Your callback runs when the player submits or closes it. Core.Input is the same function under a shorter name.

lua
Core.GetInput('Name your horse', '3 to 20 letters', function(value)
    if value == 'close' then return end
    TriggerServerEvent('jrs_stable:server:rename', value)
end, { minLength = 3, maxLength = 20 })
ArgumentTypeMeaning
titlestringHeading of the box.
subtextstringHelper line under the heading, for example what format you expect.
cbfunctionCalled with the value. A closed box gives the string 'close'.
optionstableChecks and extras, see the options table below.
Returnsboolean, string?true when the box opened. false plus a reason (for example 'ui_busy') when another full screen UI holds focus.
Client

NumberInput

#
Core.NumberInput(title, subtext, cb, options?)

Same box, but the value must be a number. The callback receives a Lua number, already checked against min and max.

lua
Core.NumberInput('Sell pelts', 'How many?', function(amount)
    if amount == 'close' then return end
    TriggerServerEvent('jrs_butcher:server:sell', amount)
end, { min = 1, max = 50, integer = true })
ArgumentTypeMeaning
titlestringHeading of the box.
subtextstringHelper line under the heading.
cbfunctionCalled with the number, or 'close' when the player backs out.
optionstableUsually min, max and integer = true.
Returnsboolean, string?true when the box opened, otherwise false and a reason.
Client

InputAwait

#
Core.InputAwait(title, subtext, options?)

Blocking version of GetInput. It pauses the current thread until the player answers, so call it inside a thread or an event handler, never in the main chunk. Pass options.type = 'number' to get a number back.

lua
CreateThread(function()
    local note = Core.InputAwait('Telegram', 'Write your message', { maxLength = 120 })
    if not note or note == 'close' then return end
    TriggerServerEvent('jrs_telegram:server:send', note)
end)
ArgumentTypeMeaning
titlestringHeading of the box.
subtextstringHelper line under the heading.
optionstableSame options as GetInput.
Returnsstring|numberThe value, 'close' when cancelled, or nil plus a reason when the box could not open.

Options#

The text box checks the value before it accepts it. When a check fails the box stays open and the player sees a short notification with the reason.

Key Type Effect
minLength number Shortest allowed text.
maxLength number Longest allowed text.
type string Set to 'number' to require a number (number = true works too).
min / max number Range for number input.
integer boolean Round number input down to a whole number.
validate function Your own check: function(text) return true end, or return false, 'reason' to reject.
hint string Extra line added under the subtext.
force boolean Open even if another UI owns focus.

Yes Or No#

Client

GetAnswer

#
Core.GetAnswer(title, first, second, cb)

Shows a question with two buttons. Core.Confirm is an alias.

lua
Core.GetAnswer('Pay the $25 fine?', 'Pay', 'Refuse', function(yes)
    if yes then TriggerServerEvent('jrs_police:server:payFine') end
end)
ArgumentTypeMeaning
titlestringThe question.
firststringLabel of the button that answers true.
secondstringLabel of the button that answers false.
cbfunctionCalled with true or false. Closing the dialog counts as false.
Returnsboolean, string?true when the dialog opened, otherwise false and a reason.
Client

ConfirmAwait

#
Core.ConfirmAwait(title, first, second)

Blocking version of GetAnswer. Run it inside a thread.

lua
CreateThread(function()
    if Core.ConfirmAwait('Leave the gang?', 'Leave', 'Stay') then
        TriggerServerEvent('jrs_organizations:server:leave')
    end
end)
ArgumentTypeMeaning
titlestringThe question.
firststringLabel of the true button.
secondstringLabel of the false button.
Returnsbooleantrue for the first button, false for the second, for closing, or when the dialog could not open.

Dialog State#

Client

IsInputOpen

#
Core.IsInputOpen()

Tells you whether a text box or question is on screen right now. Useful before you open your own menu.

lua
if Core.IsInputOpen() then return end
Returnsbooleantrue while a dialog is waiting for the player.
Client

CloseInput

#
Core.CloseInput()

Closes the open dialog from code. The pending callback still fires, with 'close' for a text box or false for a question.

lua
-- drop any open dialog before moving the player
if Core.IsInputOpen() then Core.CloseInput() end
DoScreenFadeOut(500)
Returnsbooleantrue when the call went through.

Dialog Events#

These events open the same dialogs. They are meant for client scripts that cannot hold the core object. Because they carry a Lua function, trigger them with TriggerEvent on the client, not from the server.

Client

jrs_inputs:getInput

#
TriggerEvent('jrs_inputs:getInput', title, subtext, cb)

Opens the text box with no extra options. Works like GetInput.

lua
TriggerEvent('jrs_inputs:getInput', 'Camp name', 'Shown on your map', function(text)
    print('camp:', text)
end)
ArgumentTypeMeaning
titlestringHeading of the box.
subtextstringHelper line.
cbfunctionReceives the text or 'close'.
Client

jrs_inputs:getAnswer

#
TriggerEvent('jrs_inputs:getAnswer', title, first, second, cb)

Opens the yes or no dialog. Works like GetAnswer.

lua
TriggerEvent('jrs_inputs:getAnswer', 'Light the campfire?', 'Yes', 'No', function(yes)
    if yes then ExecuteCommand('campfire') end
end)
ArgumentTypeMeaning
titlestringThe question.
firststringTrue button label.
secondstringFalse button label.
cbfunctionReceives true or false.

Styled Input Box#

A second, separate dialog drawn from html/modules/extinput in jrs_core. It takes a config table whose attributes are copied onto the HTML field, so the browser does the format checks for you. It has its own export and events and does not share state with the dialogs above.

Client

advancedInput

#
exports.jrs_core:advancedInput(config)

Opens the styled box and waits for the result, so call it in a thread. Escape or the close button give back an empty string.

Every key in attributes is copied onto the HTML field, so type, pattern, title, min, max, maxlength and value all work. The special key inputHeader sets the heading text instead.

lua
-- stable owner sets the sale price of a horse
CreateThread(function()
    local raw = exports.jrs_core:advancedInput({
        type = 'enableinput',
        style = 'block',
        inputType = 'input',
        button = 'List horse',
        placeholder = '1 - 5000',
        attributes = { inputHeader = 'Horse price', type = 'number', min = 1, max = 5000 },
    })
    local price = tonumber(raw)
    if not price then return end -- closed or empty
    TriggerServerEvent('jrs_stable:server:listForSale', horseId, price)
end)

The result is always a string, so convert it yourself and check it again on the server. For several values in one go, use Core.InputAwait with a validate function, or open one box per value.

ArgumentTypeMeaning
configtableBox setup. Also accepts the same data as a JSON string. Fields: type = 'enableinput', style = 'block', inputType ('input' or 'textarea'), button (submit label), placeholder, and attributes.
ReturnsstringWhat the player typed, or "" when closed.
Client

jrsinputs:getInput

#
TriggerEvent('jrsinputs:getInput', button, placeholder, cb)

Quick styled box with a single text field.

lua
TriggerEvent('jrsinputs:getInput', 'Save', 'Outfit name', function(name)
    if name ~= '' then print('saved outfit', name) end
end)
ArgumentTypeMeaning
buttonstringSubmit button label.
placeholderstringGrey hint inside the field.
cbfunctionReceives the text, or "" when closed.
Client

jrsinputs:getInputsWithInputType

#
TriggerEvent('jrsinputs:getInputsWithInputType', button, placeholder, inputType, cb)

Same as above but lets you switch to a multi line field.

lua
TriggerEvent('jrsinputs:getInputsWithInputType', 'Post', 'Notice board text', 'textarea', function(body)
    if body ~= '' then TriggerServerEvent('jrs_announce:server:post', body) end
end)
ArgumentTypeMeaning
buttonstringSubmit button label.
placeholderstringGrey hint inside the field.
inputTypestring'input' or 'textarea'.
cbfunctionReceives the text, or "" when closed.
Client

jrsinputs:advancedInput

#
TriggerEvent('jrsinputs:advancedInput', config, cb)

Callback form of advancedInput, for code that should not block.

lua
TriggerEvent('jrsinputs:advancedInput', {
    type = 'enableinput', style = 'block', inputType = 'input',
    button = 'Set', placeholder = 'Price',
    attributes = { inputHeader = 'Shop price', type = 'number', min = 1 },
}, function(price)
    print('price', tonumber(price))
end)
ArgumentTypeMeaning
configtableSame table as advancedInput.
cbfunctionReceives the text, or "" when closed.
Tip

If a styled box ever gets stuck on screen, type /closeinput in the console or chat to close it and give mouse control back.

Progress Bar#

The bar is drawn by jrs_core. Call it through the jrs_core exports or through the core object; both reach the same code. Only one bar runs at a time, and starting a new one replaces the old one.

Showing A Bar#

Client

DisplayProgressBar

#
exports.jrs_core:DisplayProgressBar(time, description, cb?, shouldCancel?, options?)

Shows the bar and blocks the calling thread until it ends, then tells you how it ended. This is the one to use when the next line of your code depends on the result. Also available as Core.DisplayProgressBar.

lua
CreateThread(function()
    local ped = PlayerPedId()
    local start = GetEntityCoords(ped)

    local done = exports.jrs_core:DisplayProgressBar(8000, 'Skinning the deer', function()
        TaskStartScenarioInPlace(ped, `WORLD_HUMAN_CROUCH_INSPECT`, 0, true)
    end, function()
        return #(GetEntityCoords(ped) - start) > 2.0
    end)

    ClearPedTasks(ped)
    if done then TriggerServerEvent('jrs_hunting:server:skin') end
end)
ArgumentTypeMeaning
timenumberLength in ms. Values below 100 are raised to 100.
descriptionstringText shown on the bar.
cbfunctionRuns in its own thread as soon as the bar appears. Good for starting an animation.
shouldCancelfunctionChecked every step. Return true to stop the bar early, for example when the player walks away.
optionstablebrand (small title above the label, defaults to the server name), canCancel (default true; ESC or Backspace stop the bar), useWhileDead (default false; dying stops the bar).
Returnsbooleantrue when the bar ran to the end, false when it was cancelled by any means.
Client

Progress

#
exports.jrs_core:Progress(action, finish?)

Non blocking form that takes one settings table. It returns at once and calls finish later. Also available as Core.Progress.

lua
exports.jrs_core:Progress({ label = 'Filling the canteen', duration = 4000, canCancel = false }, function(cancelled)
    if not cancelled then TriggerServerEvent('jrs_metabolism:server:fillCanteen') end
end)

-- short form: duration and label only
exports.jrs_core:Progress(2500, 'Checking the map')
ArgumentTypeMeaning
actiontableduration (or time, ms, default 1000), label (or description, default 'Working...'), brand, canCancel, useWhileDead. You may also pass the duration as a number and the label as the second argument.
finishfunctionCalled with one boolean: true when the bar was cancelled, false when it completed.
Warning

The two callbacks read the result the opposite way. DisplayProgressBar returns true for success, while the finish callback of Progress gets true for cancelled.

Stopping A Bar#

Client

CancelProgressBar

#
exports.jrs_core:CancelProgressBar()

Hides the running bar right away. A waiting DisplayProgressBar then returns false and a Progress callback gets cancelled = true. Nothing happens when no bar is shown. Also available as Core.CancelProgressBar.

lua
RegisterCommand('stopwork', function()
    exports.jrs_core:CancelProgressBar()
end, false)

Progress Events#

Both events are network events, so a server script can drive the bar on one client.

Client

jrs_core:client:progress

#
TriggerClientEvent('jrs_core:client:progress', target, action)

Starts a bar with the same action table as Progress. From the server you cannot pass a callback; from another client script you can use TriggerEvent and add finish as a third value.

lua
-- server: show a bar while a wagon is loaded
TriggerClientEvent('jrs_core:client:progress', source, { label = 'Loading crates', duration = 6000 })
ArgumentTypeMeaning
targetnumberPlayer server id (server side trigger only).
actiontableSettings table, see Progress.
Client

jrs_core:client:cancelProgress

#
TriggerClientEvent('jrs_core:client:cancelProgress', target)

Stops whatever bar the player has open, the same as CancelProgressBar.

lua
TriggerClientEvent('jrs_core:client:cancelProgress', source)
ArgumentTypeMeaning
targetnumberPlayer server id.

Standalone Progressbar Resource#

Some JRS servers also run a resource named progressbar. It does not draw anything itself any more: while jrs_core is started every call is passed to DisplayProgressBar. It exists so older scripts that call it keep working. During its bar it sets the inv_busy state bag on the player to true, which blocks the inventory until the bar ends.

Note

The animation, prop and propTwo fields of its action table are accepted but not played. Start your own animation, for example in onStart. The onTick function only runs when jrs_core is stopped.

Client

Progress

#
exports.progressbar:Progress(action, finish?)

Starts a bar unless the player is dead (and useWhileDead is false) or a bar from this resource is already running.

lua
exports.progressbar:Progress({ label = 'Picking the lock', duration = 5000 }, function(cancelled)
    if not cancelled then TriggerServerEvent('jrs_theftsystem:server:lockOpened') end
end)
ArgumentTypeMeaning
actiontablelabel, duration, canCancel, useWhileDead, brand.
finishfunctionReceives true when cancelled, false when completed.
Client

ProgressWithStartEvent

#
exports.progressbar:ProgressWithStartEvent(action, start, finish)

Like Progress, with a function that runs once when the bar begins.

lua
exports.progressbar:ProgressWithStartEvent({ label = 'Washing up', duration = 4000 }, function()
    TaskStartScenarioInPlace(PlayerPedId(), `WORLD_HUMAN_WASH_FACE_BUCKET_GROUND`, 0, true)
end, function(cancelled)
    ClearPedTasks(PlayerPedId())
end)
ArgumentTypeMeaning
actiontableSettings table.
startfunctionRuns at the start.
finishfunctionReceives the cancelled flag.
Client

ProgressWithTickEvent

#
exports.progressbar:ProgressWithTickEvent(action, tick, finish)

Like Progress, with a per frame function. See the note above: the tick only runs when jrs_core is stopped.

lua
exports.progressbar:ProgressWithTickEvent({ label = 'Waiting', duration = 3000 }, function() end, function() end)
ArgumentTypeMeaning
actiontableSettings table.
tickfunctionPer frame function.
finishfunctionReceives the cancelled flag.
Client

ProgressWithStartAndTick

#
exports.progressbar:ProgressWithStartAndTick(action, start, tick, finish)

Both extra hooks at once.

lua
exports.progressbar:ProgressWithStartAndTick(action, onStart, onTick, onFinish)
ArgumentTypeMeaning
actiontableSettings table.
startfunctionRuns at the start.
tickfunctionPer frame function.
finishfunctionReceives the cancelled flag.
Client

isDoingSomething

#
exports.progressbar:isDoingSomething()

Lets other scripts check whether a bar from this resource is running.

lua
if exports.progressbar:isDoingSomething() then return end
Returnsbooleantrue while a bar is active.

The resource also listens for the client events progressbar:client:progress, progressbar:client:ProgressWithStartEvent, progressbar:client:ProgressWithTickEvent and progressbar:client:ProgressWithStartAndTick (same arguments as the exports), progressbar:client:cancel to stop the bar, progressbar:client:ToggleBusyness with a boolean to set the busy flag by hand, and progressbar:client:hud with label, duration to show a plain bar from the server.

Animation Loaders#

These helpers request the dictionary, wait for it with a timeout and call TaskPlayAnim for you, so your script only describes the clip.

The Anim Table#

The two play helpers take the clip as a small table. These are the fields they read:

Field Type Used for
dict string Animation dictionary, for example amb_work@world_human_box_pickup@1@male_a@stand_exit_withprop.
name string Clip inside that dictionary.
blendInSpeed number How fast the clip fades in.
blendOutSpeed number How fast the clip fades out.
duration number Length in ms. -1 plays the clip to its end (or forever when it loops).
flag number Native animation flags, for example 1 to loop or 31 for upper body, loop and keep control.
playbackRate number Playback speed.
keepDict boolean Core.Utils.PlayAnimation only: keep the dictionary in memory after the call.
Warning

Core.PlayAnimation passes every field straight to the native, with no defaults. Fill in all speed, duration, flag and rate fields, or use Core.Utils.PlayAnimation, which fills the gaps for you.

Playing A Clip#

Client

PlayAnimation

#
Core.PlayAnimation(ped, anim)

Loads anim.dict (waits up to 10 seconds) and starts the clip on ped. The dictionary is released right after the task starts. Use it when you already know every value you want to pass.

lua
local Core = exports.jrs_core:getCoreApi()

local ok = Core.PlayAnimation(PlayerPedId(), {
    dict = 'mech_inventory@crafting@fallbacks',
    name = 'full_craft_and_stow',
    blendInSpeed = 8.0,
    blendOutSpeed = -8.0,
    duration = 4500,
    flag = 31,
    playbackRate = 0.0,
})
if not ok then print('crafting clip missing') end
ArgumentTypeMeaning
pednumberPed handle that should play the clip, usually PlayerPedId().
animtableClip description. See the anim table above; all fields should be set.
Returnsbooleanfalse when the dictionary does not exist or did not load in time, true once the task was started.
Client

Utils.PlayAnimation

#
Core.Utils.PlayAnimation(ped, anim, timeoutMs?)

The forgiving version. Missing fields fall back to blend 1.0, duration -1, flag 0 and rate 1.0. It also checks that dict and name are present before doing anything.

lua
local Core = exports.jrs_core:getCoreApi()

-- loop a washing clip until the player moves
Core.Utils.PlayAnimation(PlayerPedId(), {
    dict = 'amb_misc@world_human_wash_face_bucket@ground@male_a@idle_d',
    name = 'idle_l',
    flag = 1,
}, 5000)
ArgumentTypeMeaning
pednumberPed handle. When it is not a number the local player ped is used.
animtableClip description. Only dict and name are required. Set keepDict = true if you will replay the clip soon.
timeoutMsnumberHow long to wait for the dictionary, in ms. Default 10000.
Returnsbooleantrue when the clip started, false on a bad table or a dictionary that would not load.

Loading Dictionaries#

Client

LoadAnimDict

#
Core.LoadAnimDict(dict, timeoutMs?)

Requests a dictionary and waits until it is in memory. Handy when you want to play the clip yourself with your own native call, or preload it before a cutscene. The same function is also reachable as Core.Utils.LoadAnimDict.

lua
local Core = exports.jrs_core:getCoreApi()
local dict = 'script_rc@chain_gang@ig@ig_1_pick_lock'

if Core.LoadAnimDict(dict, 3000) then
    TaskPlayAnim(PlayerPedId(), dict, 'pick_lock_loop', 4.0, -4.0, -1, 1, 0.0, false, false, false, '', false)
end
ArgumentTypeMeaning
dictstringDictionary name.
timeoutMsnumberMaximum wait in ms. Default 10000.
Returnsbooleantrue when the dictionary is loaded (or already was), false for an empty or unknown name or a timeout.
Tip

To stop a clip early, call StopAnimTask(ped, dict, name, 1.0) or ClearPedTasks(ped). The helpers do not keep any state you need to clean up.