opx_infinityprogress
Client
Last updated on
The progress contract on the client — put a bar up, take it down, read whether one is up.
local progress = OPX.Api.Get('progress')From client code inside opx_infinity. Each function answers a Result. None yields.
Start
Puts a bar up. Answers whether the bar is up, not whether the action happened: the outcome arrives on opx:on:progress:done.
progress.Start(owner, spec)Parameters
- owner:
string- Your module name; needed for
Stop.
- Your module name; needed for
- spec:
table- label:
string- Required. Cut to 64 bytes. Your own text.
- durationMs:
number- Required. Between
MIN_MSandMAX_MS.
- Required. Between
- animation?:
table{ name, variant? }. Played throughanimations.Play(looped, not cancellable) and stopped with the bar. Ignored ifanimationsis not running or refuses it.
- cancelable?:
boolean- Default
false. Lets the player cancel the bar withCANCEL_KEY.
- Default
- label:
Returns
Result—{ owner, durationMs }; errorsinvalid_caller,invalid_spec,progress_busy,invalid_duration,invalid_label
local r = progress.Start('mymodule', { label = 'Eating', durationMs = 4000 })
AddEventHandler('opx:on:progress:done', function(done)
if done.owner == 'mymodule' and done.finished then --[[ apply the effect ]] end
end)Stop
Takes the owner's bar down early.
progress.Stop(owner, ending)Parameters
- owner:
string - ending?:
string'cancelled'reportscancelled; anything else reportsstopped.
Returns
Result—true; errorsprogress_not_active,not_owner
State
Whether a bar is up, and whose.
progress.State()Returns
Result{ open = false, cancelledAtMs? }- or
{ open = true, owner, label, remainingMs, cancelable, cancelKey?, cancelledAtMs? }- cancelable:
boolean— the player may cancel it with the key - cancelKey?:
string— the key the cancel is bound to now, whencancelable - cancelledAtMs?:
integer—OPX.Now()of the last cancel by key. For a module sharing the key: a press within a few hundred ms of it was the bar's.
- cancelable:
local bar = OPX.Api.Get('progress').State().value
if bar.open and bar.cancelable then return end
if bar.cancelledAtMs and OPX.Now() - bar.cancelledAtMs < 300 then return end