Extensions of the Player metatable that the gamemode package adds to every player. Names go through the GetPlayerName hook so that plugins can replace them, Player:SetModel announces model changes with the PlayerModelChanged hook, and the permission checks (Player:can, Player:is_root) are answered by hooks that an admin plugin implements. The rest covers the initialization state, the data table of a player, client-side notifications and sounds, freezing, and actions: every player has one current action, registered with Flux.register_action, which the gamemode runs on each PlayerThink; Flux.TimedAction builds actions that take time on top of it. The server-only half adds saving and restoring of the player's database record.

Summary

Methods

Checks whether the player has a permission.
Cancels the timed action of the player.
Runs the callback of an action registered with Flux.register_action.
Looks for unobstructed spots around the player that the player can be moved to.
Stops the player from firing their active weapon for an hour and freezes the weapon.
Stops the player from moving by setting their move type to MOVETYPE_NONE.
Returns the action the player is currently doing.
Returns the ammo the player has.
Returns the data table of the player.
Returns a value from the data table of the player.
Returns the timed action the player is doing.
Returns how far the timed action of the player has progressed.
Returns the weapons the player has: their classes alone, or together with what is loaded in them and the reserve ammo of the player, in the shape that Player:give_weapons takes to give everything back.
Gives several weapons to the player: the classes that Player:get_weapons_list returns, or its tables with clips, which the weapons are loaded with once they are given.
Checks whether the player has finished loading in and has been initialized by Flux.
Checks whether the player is currently doing the specified action.
is_root()shared
Checks whether the player has root access, that is can do anything.
Returns the name of the player.
Sends a notification to the player.
Sends a light red notification to the player.
Plays a gesture on top of the player's regular animations in the custom gesture slot.
Plays a sound once on the client of the player, at full volume and without a position.
Resets the action of the player to 'none'.
Loads the database record of the player by their SteamID, creating and saving a new one if they have joined for the first time.
running()shared
Checks whether the player is alive and moving on foot faster than the walk speed.
Saves the database record of the player, together with their data table.
Sets the action the player is currently doing.
Makes the player play the specified sequence instead of their regular animations.
Replaces the data table of the player.
Sets whether the player has been initialized by Flux.
Sets a value in the data table of the player.
Sets the model of the player.
Starts a named looping sound on the client of the player.
Starts a timed action for the player.
Returns the Steam name of the player.
Stops the animation that was set with Player#set_animation.
Stops a named sound on the client of the player.
Lets the player fire their active weapon again and unfreezes the weapon.
Lets the player move again by setting their move type to MOVETYPE_WALK.
Moves the player to the closest unobstructed spot nearby.

Methods

Player:can(action, object)

shared packages/flow/lib/meta/sh_player.lua:343

Checks whether the player has a permission. The decision is made by the 'PlayerHasPermission' hook, which admin plugins implement.

if !actor:can('spawn_props') then
  return false
end

Parameters

  • action String permission ID
  • object Any optional, defaults to nil object the permission is checked against, passed to the hook

Returns

  • Boolean nil if nothing handles the hook

Player:cancel_timed_action(id)

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

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

Parameters

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

Returns

  • Boolean true if an action was canceled

Player:do_action(id)

shared packages/flow/lib/meta/sh_player.lua:305

Runs the callback of an action registered with Flux.register_action.

Parameters

  • id String optional, defaults to nil action ID, the current action of the player if omitted

Player:find_best_position(margin, filter)

server packages/flow/lib/meta/sv_player.lua:228

Looks for unobstructed spots around the player that the player can be moved to.

Parameters

  • margin Number optional, defaults to 3 how far to search: spots are checked on a grid of this many steps in every direction, margin * 10 units apart
  • filter Entity/List<Entity>/Function optional, defaults to nil trace filter, the player by default

Returns

  • List<Vector> free positions, closest first

Player:freeze_gun()

shared packages/flow/lib/meta/sh_player.lua:244

Stops the player from firing their active weapon for an hour and freezes the weapon.

See also

Player:freeze_move()

shared packages/flow/lib/meta/sh_player.lua:232

Stops the player from moving by setting their move type to MOVETYPE_NONE.

See also

Player:get_action()

shared packages/flow/lib/meta/sh_player.lua:287

Returns the action the player is currently doing.

Returns

  • String action ID, 'none' if the player is not doing anything

Player:get_ammo_table()

server packages/flow/lib/meta/sv_player.lua:152

Returns the ammo the player has.

Returns

  • Map amounts of ammo by ammo type ID, only for the types the player has

Player:get_data()

shared packages/flow/lib/meta/sh_player.lua:26

Returns the data table of the player. The server keeps the table of every player, while a client is only sent the table of its own local player: for anyone else it gets an empty table there.

Returns

  • Map

Player:get_player_data(key, default)

server packages/flow/lib/meta/sv_player.lua:98

Returns a value from the data table of the player. Values that were saved during an earlier session are available once the PlayerRestored hook has run for the player.

Parameters

  • key String
  • default Any optional, defaults to nil returned if the value is not set or is false

Returns

  • Any

Player:get_timed_action()

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

Returns the timed action the player is doing. On the client only the local player has one.

Returns

  • Map the action (see Flux.TimedAction#get), nil if there is none

Player:get_timed_action_progress()

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

Returns how far the timed action of the player has progressed. 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

Player:get_weapons_list(with_ammo)

shared packages/flow/lib/meta/sh_player.lua:104

Returns the weapons the player has: their classes alone, or together with what is loaded in them and the reserve ammo of the player, in the shape that Player:give_weapons takes to give everything back.

local weapons, ammo = actor:get_weapons_list(true)
actor:StripWeapons()
actor:StripAmmo()
actor:give_weapons(weapons, ammo)

Parameters

  • with_ammo Boolean optional, defaults to false true to list the clips of the weapons and the reserve ammo of the player as well

Returns

  • List<String> weapon classes; when with_ammo is true
  • List<Map> tables with the class, clip1 and clip2 fields instead, followed by Map the reserve ammo of the player, a count by ammo type name

Player:give_weapons(weapons_table, ammo)

server packages/flow/lib/meta/sv_player.lua:311

Gives several weapons to the player: the classes that Player:get_weapons_list returns, or its tables with clips, which the weapons are loaded with once they are given. The weapons come with their default ammo unless the second argument says otherwise.

actor:give_weapons({ 'weapon_pistol', 'weapon_crowbar' })
actor:give_weapons(weapons, true)
actor:give_weapons(weapons, ammo)

Parameters

  • weapons_table List<String/Map> weapon classes, or tables with the class, clip1 and clip2 fields as Player:get_weapons_list lists them with ammo; a clip that is nil is left as the weapon spawns with it
  • ammo Boolean/Map optional, defaults to nil what reserve ammo comes with the weapons: nil for the default ammo of every weapon, true for none, or counts by ammo type name as Player:get_weapons_list returns them, which are set on the player once the weapons are given and replace what they hold of those types

Player:has_initialized()

shared packages/flow/lib/meta/sh_player.lua:18

Checks whether the player has finished loading in and has been initialized by Flux.

Returns

  • Boolean

Player:is_doing_action(id)

shared packages/flow/lib/meta/sh_player.lua:294

Checks whether the player is currently doing the specified action.

Parameters

  • id String action ID

Returns

  • Boolean

Checks whether the player has root access, that is can do anything. The decision is made by the 'PlayerIsRoot' hook.

Returns

  • Boolean nil if nothing handles the hook

Player:Name(force_true_name)

shared packages/flow/lib/meta/sh_player.lua:45

Returns the name of the player. Overrides the engine function, so that plugins can provide their own names (e.g. character names) with the 'GetPlayerName' hook. Also available as Player#name.

Parameters

  • force_true_name Boolean optional, defaults to false ignore the 'GetPlayerName' hook

Returns

  • String

Player:notify(message, arguments, color)

shared packages/flow/lib/meta/sv_player.lua:114

On the server

Sends a notification to the player. Serverside variant.

Parameters

  • message String text or language phrase
  • arguments Map optional, defaults to nil values to substitute into the phrase
  • color Color optional, defaults to nil

On the client

Displays a notification to the local player, both as a popup and in the chat. Clientside variant.

Parameters

  • message String text or language phrase
  • arguments Map optional, defaults to nil values to substitute into the phrase; strings are translated, entities are replaced with their names
  • color Color optional, defaults to color_white

Defined in

Player:notify_admin(message, arguments)

server packages/flow/lib/meta/sv_player.lua:121

Sends a light red notification to the player.

Parameters

  • message String text or language phrase
  • arguments Map optional, defaults to nil values to substitute into the phrase

Player:play_gesture(animation)

shared packages/flow/lib/sh_animation.lua:720

Plays a gesture on top of the player's regular animations in the custom gesture slot. Called serverside, the gesture is sent to every client through the animation event system, so this is the way to make everyone see a one-off animation such as a punch, a wave or a weapon draw.

Parameters

  • animation Number activity (ACT_ enum) or String sequence name

Returns

  • Boolean false if the player's model has no such sequence

Player:play_sound(path)

shared packages/flow/lib/meta/sv_player.lua:129

On the server

Plays a sound once on the client of the player, at full volume and without a position. Serverside variant.

Parameters

  • path String path of the sound file, relative to the sound/ folder

See also

On the client

Plays a sound once for the local player, at full volume and without a position. Clientside variant: does nothing when called on another player.

Parameters

  • path String path of the sound file, relative to the sound/ folder

Defined in

Player:reset_action()

shared packages/flow/lib/meta/sh_player.lua:299

Resets the action of the player to 'none'.

Player:restore_player()

server packages/flow/lib/meta/sv_player.lua:172

Loads the database record of the player by their SteamID, creating and saving a new one if they have joined for the first time. The query is asynchronous: the record is put into self.record, the saved data table of the player is loaded from it (values set during this session before the record arrived are kept) and the 'PlayerRestored' hook is run once it has loaded. Nothing happens if the player has left by then. Bots get a blank record that is never saved here.

Checks whether the player is alive and moving on foot faster than the walk speed.

Returns

  • Boolean

Player:save_player()

server packages/flow/lib/meta/sv_player.lua:34

Saves the database record of the player, together with their data table. Does nothing for bots. Can be prevented by returning true from the 'PreSavePlayerData' hook. Runs the 'PostSavePlayerData' hook afterward. The data table is taken from the server's own copy and never from the networked variables, which are gone once the entity of a leaving player has been removed: without that copy the record keeps the data it already has.

Player:set_action(id, force)

shared packages/flow/lib/meta/sh_player.lua:277

Sets the action the player is currently doing. Does nothing if the player is already doing something, unless forced.

Parameters

  • id String action ID
  • force Boolean optional, defaults to false replace the current action

Returns

  • Boolean true if the action was set, nil otherwise

Player:set_animation(animation, duration_override, callback)

shared packages/flow/lib/sh_animation.lua:515

Makes the player play the specified sequence instead of their regular animations. The override is removed once the sequence has finished, and also when the player dies, spawns or gets another model. Called on the server, the animation is shown by every client, including the clients of players who join while it lasts; called on a client, it is only seen on that client. Setting an animation replaces the one that was set before.

target:set_animation('idle_to_sit_ground', nil, function(target, completed)
  if completed then
    target:set_animation('sit_ground', 0)
  end
end)

Parameters

  • animation String name of the sequence
  • duration_override Number optional, defaults to nil seconds to keep the override for instead of the duration of the sequence, 0 keeps it until Player#stop_animation is called
  • callback Function optional, defaults to nil called with the player and a Boolean when the override is removed: true if it was kept for its whole duration, false if it was stopped or replaced before that, which includes the death, the spawn and the model change of the player. Called in the realm the animation was set in

Returns

  • Boolean false if the model of the player has no such sequence, in which case nothing changes and the callback is not called

Player:set_data(data)

server packages/flow/lib/meta/sv_player.lua:64

Replaces the data table of the player. The table is networked to the player it belongs to, and to nobody else, and written to the database record of the player, which stores it the next time the record is saved.

Parameters

Player:set_initialized(initialized)

server packages/flow/lib/meta/sv_player.lua:104

Sets whether the player has been initialized by Flux.

Parameters

  • initialized Boolean optional, defaults to true

Player:set_player_data(key, value)

server packages/flow/lib/meta/sv_player.lua:85

Sets a value in the data table of the player. The value is networked to the player it belongs to, and to nobody else, and persistent: it is saved with the database record of the player (when they disconnect, when their character is saved and when the server shuts down) and is there again the next time they join. Keep the values to what table.serialize can store.

target:set_player_data('tutorial_seen', true)

Parameters

  • key String
  • value Any nil removes the value

Player:SetModel(path)

shared packages/flow/lib/meta/sh_player.lua:69

Sets the model of the player. Overrides the engine function to run the 'PlayerModelChanged' hook and, on the server, to tell the clients about the change.

Parameters

  • path String path to the model

Player:start_sound(id, path, volume)

shared packages/flow/lib/meta/sv_player.lua:138

On the server

Starts a named looping sound on the client of the player. Serverside variant.

Parameters

  • id String name to stop the sound by
  • path String path of a looping sound file, relative to the sound/ folder
  • volume Number optional, defaults to 0.75 volume from 0 to 1

See also

On the client

Starts a named looping sound for the local player. Starting another sound under a name that is in use replaces the old one, and starting the same sound again while it plays does nothing. Clientside variant: does nothing when called on another player.

Parameters

  • id String name to stop the sound by
  • path String path of a looping sound file, relative to the sound/ folder
  • volume Number optional, defaults to 0.75 volume from 0 to 1

Defined in

Player:start_timed_action(id, duration, options)

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

Starts a timed action for the player. Serverside only.

actor:start_timed_action('search', 3, {
  text = 'ui.hud.bar_text.search',
  condition = Flux.TimedAction:looking_at(container),
  callback = function(actor, success)
    if success then
      open_container(actor, container)
    end
  end
})

Parameters

  • id String action ID, which becomes the current action of the player
  • duration Number seconds the action takes
  • options Map optional, defaults to nil text, arguments, condition, callback and force, see Flux.TimedAction#start

Returns

  • Boolean true if the action has started

See also

Player:steam_name()

shared packages/flow/lib/meta/sh_player.lua:62

Returns the Steam name of the player.

Returns

  • String

Player:stop_animation()

shared packages/flow/lib/sh_animation.lua:552

Stops the animation that was set with Player#set_animation. Called on the server, it stops on every client as well. The finish callback of the animation is called with false.

Player:stop_sound(id, fade_out)

shared packages/flow/lib/meta/sv_player.lua:146

On the server

Stops a named sound on the client of the player. Serverside variant.

Parameters

  • id String name the sound was started under
  • fade_out Number optional, defaults to 0 seconds over which the sound fades out

See also

On the client

Stops a sound that was started with Player#start_sound. Clientside variant: does nothing when called on another player.

Parameters

  • id String name the sound was started under
  • fade_out Number optional, defaults to 0 seconds over which the sound fades out; 0 cuts it off

Defined in

Player:unfreeze_gun()

shared packages/flow/lib/meta/sh_player.lua:259

Lets the player fire their active weapon again and unfreezes the weapon.

See also

Player:unfreeze_move()

shared packages/flow/lib/meta/sh_player.lua:238

Lets the player move again by setting their move type to MOVETYPE_WALK.

See also

Player:unstuck(filter)

server packages/flow/lib/meta/sv_player.lua:282

Moves the player to the closest unobstructed spot nearby.

Parameters

  • filter Entity/List<Entity>/Function optional, defaults to nil trace filter, the player by default

Defined in