Timed actions: things a player does that take a while, such as picking a lock, tying someone up or searching a container. The server starts one with Flux.TimedAction:start (or Player:start_timed_action), giving it an ID, a duration and optionally a text, a cancel condition and a callback. While it runs the player's current action (Player:get_action) is the ID of the timed action, so the rest of the action system keeps working: Player:is_doing_action answers for everyone, and resetting or replacing the action cancels the timed one.

The action ends in one of two ways. It succeeds when its duration has passed. It fails when it is canceled with Flux.TimedAction:cancel, when its condition stops holding, when the player dies or leaves, or when their current action is changed by something else. Either way the callback is called with the outcome and the PlayerTimedActionFinished hook is run. PlayerCanStartTimedAction lets plugins veto an action before it starts.

actor:start_timed_action('lockpick', 5, {
  text = 'ui.hud.bar_text.lockpick',
  condition = Flux.TimedAction:all_of(
    Flux.TimedAction:looking_at(door, 96),
    Flux.TimedAction:staying_put()
  ),
  callback = function(actor, success)
    if success and IsValid(door) then
      door:Fire('unlock')
    end
  end
})

The action is networked to its owner only. Their client draws it as a progress bar in the middle of the screen through Flux.Bars (the bar's ID is timed_action, so the bar hooks apply to it) and runs PlayerTimedActionStarted and PlayerTimedActionFinished for the local player. On the client Flux.TimedAction:get therefore only knows the action of the local player.

Summary

Methods

Combines several cancel conditions into one that holds while all of them do.
Cancels the timed action of a player.
Returns the timed action a player is doing.
Makes a cancel condition that holds while the player keeps looking at an entity from close enough.
Returns how far the timed action of a player has progressed.
Starts a timed action for a player.
Makes a cancel condition that holds while the player stays where they were when the action started.

Methods

Flux.TimedAction:all_of(...)

shared packages/flow/lib/sh_timed_action.lua:85

Combines several cancel conditions into one that holds while all of them do.

Parameters

  • ... Vararg condition functions

Returns

  • Function condition for the options of Flux.TimedAction#start

Flux.TimedAction:cancel(actor, id)

server packages/flow/lib/sh_timed_action.lua:262

Cancels the timed action of a player. The callback of the action is called with a failure. Serverside only.

Parameters

  • actor Player
  • id String optional, defaults to nil only cancel the action if it has this ID

Returns

  • Boolean true if an action was canceled

Flux.TimedAction:get(actor)

shared packages/flow/lib/sh_timed_action.lua:275

Returns the timed action a player is doing.

Parameters

  • actor Player on the client only the local player has one

Returns

  • Map the action with the id, text, arguments, duration, start_time and end_time (both CurTime() based) fields, on the server also condition, callback and options; nil if the player is not doing a timed action

Defined in

Flux.TimedAction:looking_at(entity, distance)

shared packages/flow/lib/sh_timed_action.lua:48

Makes a cancel condition that holds while the player keeps looking at an entity from close enough. Fails once the entity is removed.

Parameters

  • entity Entity the entity the player has to look at
  • distance Number optional, defaults to 96 how far from the player's eyes the point they look at may be

Returns

  • Function condition for the options of Flux.TimedAction#start

Flux.TimedAction:progress(actor)

shared packages/flow/lib/sh_timed_action.lua:412

Returns how far the timed action of a player has progressed.

Parameters

  • actor Player on the client only the local player has a timed action

Returns

  • Number fraction from 0 to 1, nil if the player is not doing a timed action

Flux.TimedAction:start(actor, id, duration, options)

server packages/flow/lib/sh_timed_action.lua:193

Starts a timed action for a player. Refused if the player is already doing something (their current action is not 'none'), unless forced; a forced start cancels the timed action that is running and puts the previous action of the player back when it ends. It gives way if the callback of the action it cancels starts another timed action. Serverside only.

Parameters

  • actor Player
  • id String action ID, which becomes the current action of the player
  • duration Number seconds the action takes
  • options Map optional, defaults to nil optional settings: text (String text or language phrase shown on the progress bar), arguments (Map values to substitute into the text), condition (Function called with the player and the action on every tick; the action is canceled as soon as it returns false or nil), callback (Function called with the player, a success Boolean and the action when the action ends) and force (Boolean start even if the player is doing something else)

Returns

  • Boolean true if the action has started

See also

Flux.TimedAction:staying_put(distance)

shared packages/flow/lib/sh_timed_action.lua:67

Makes a cancel condition that holds while the player stays where they were when the action started. The condition remembers that position, so make a new one for every action.

Parameters

  • distance Number optional, defaults to 16 how far the player may move away

Returns

  • Function condition for the options of Flux.TimedAction#start

Defined in