Stamina limits how long players can sprint. Running drains the player's stamina and jumping costs a flat amount of it; once it runs low the player can no longer run or jump properly. Stamina regenerates after a short delay when the player stops running. The rates are set through the stam_ config keys, and other plugins can scale them per player through the StaminaAdjustDrainScale and StaminaAdjustRegenScale hooks, or stop the stamina of a player from changing through the PlayerShouldStaminaDrain and PlayerShouldStaminaRegenerate hooks. Stamina never drains for players who are noclipping or in observer mode.

Further stam_ config keys, all off by default, make wounded players tire faster, let crouching players recover faster, slow a running player down gradually as the stamina runs out and save the stamina with the character instead of refilling it whenever a character is loaded. The saved value is kept in the generic data of the character under the stamina key, which needs the Characters plugin.

Summary

Hooks

Draws the stamina bar, which fades in while stamina is below 98% of the 'stam_max' config and out otherwise.
Takes the jump penalty off the player's stamina and delays its regeneration when they jump off the ground.
Forgets that the stamina of a player belongs to the character they drop, so that it is no longer written into that character.
Keeps the cached stamina settings in sync with changes of the 'stam_' config keys.
Removes every stamina timer when the code is reloaded, and forgets what the players were doing so that the timers are started again.
Removes the stamina timers of a player who leaves the server.
Starts and stops stamina drain and regeneration depending on whether the player is running, and limits their jump power and run speed while stamina is low.
Remembers which character the stamina of the player belongs to and, if the 'stam_persistent' config is on, gives the player the stamina that was saved with the character.
Refills the player's stamina when they spawn.
Writes the stamina of the player into the generic data of their character before it is saved, under the 'stamina' key.

Methods

Checks whether the player's stamina may drain right now.
Checks whether the player's stamina may regenerate right now, which the PlayerShouldStaminaRegenerate hook decides.
Takes stamina from the player and delays its regeneration by the 'stam_regen_delay' config, the way jumping does.
Returns the player's current stamina.
Sets the player's stamina, clamped between 0 and the 'stam_max' config value, and networks it.
Pauses the player's stamina regeneration.
Pauses the player's stamina drain.

Hooks

Stamina:HUDPaint()

client plugins/stamina/plugin/cl_hooks.lua:12

Draws the stamina bar, which fades in while stamina is below 98% of the 'stam_max' config and out otherwise. The theme can take over the drawing through its DrawStaminaBar hook.

Stamina:KeyPress(actor, key)

server plugins/stamina/plugin/sv_hooks.lua:242

Takes the jump penalty off the player's stamina and delays its regeneration when they jump off the ground. Does nothing if their stamina is below the penalty.

Parameters

  • actor Player
  • key Number IN_ enum of the pressed key

Stamina:OnActiveCharacterCleared(owner, _character)

server plugins/stamina/plugin/sv_hooks.lua:182

Implements hook OnActiveCharacterCleared

Forgets that the stamina of a player belongs to the character they drop, so that it is no longer written into that character.

Parameters

  • owner Player
  • _character Character the character that is being dropped

Stamina:OnConfigSet(key, _old_value, new_value)

server plugins/stamina/plugin/sv_hooks.lua:128

Implements hook OnConfigSet

Keeps the cached stamina settings in sync with changes of the 'stam_' config keys.

Parameters

  • key String config key
  • _old_value Any
  • new_value Any

Stamina:OnReloaded()

server plugins/stamina/plugin/sv_hooks.lua:263

Removes every stamina timer when the code is reloaded, and forgets what the players were doing so that the timers are started again.

Stamina:PlayerDisconnected(actor)

server plugins/stamina/plugin/sv_hooks.lua:252

Implements hook PlayerDisconnected

Removes the stamina timers of a player who leaves the server.

Parameters

  • actor Player

Stamina:PlayerThink(actor, cur_time)

server plugins/stamina/plugin/sv_hooks.lua:210

Implements hook PlayerThink

Starts and stops stamina drain and regeneration depending on whether the player is running, and limits their jump power and run speed while stamina is low.

Parameters

  • actor Player
  • cur_time Number CurTime() of the tick

Stamina:PostCharacterLoaded(owner, character)

server plugins/stamina/plugin/sv_hooks.lua:164

Implements hook PostCharacterLoaded

Remembers which character the stamina of the player belongs to and, if the 'stam_persistent' config is on, gives the player the stamina that was saved with the character. A character without saved stamina keeps the full stamina it spawned with. Only runs when the Characters plugin is loaded.

Parameters

  • owner Player
  • character Character the character that has been loaded

Stamina:PostPlayerSpawn(actor)

server plugins/stamina/plugin/sv_hooks.lua:154

Implements hook PostPlayerSpawn

Refills the player's stamina when they spawn. When a character is loaded, the stamina saved with it is applied afterwards.

Parameters

  • actor Player

See also

Stamina:SaveCharacterData(owner, character)

server plugins/stamina/plugin/sv_hooks.lua:195

Implements hook SaveCharacterData

Writes the stamina of the player into the generic data of their character before it is saved, under the 'stamina' key. Nothing is kept for a dead player, so that the character is loaded with full stamina next time, or while the 'stam_persistent' config is off: a value that was saved before is then cleared once, and nothing is written as long as there is none. A player counts as dead once their health is gone, because the save that follows a death runs while Player:Alive still returns true. Only runs when the Characters plugin is loaded.

Parameters

  • owner Player
  • character Character the character that is being saved

Methods

Stamina:can_drain(target)

server plugins/stamina/plugin/sv_hooks.lua:298

Checks whether the player's stamina may drain right now. It never drains for players who are dead, noclipping or in observer mode, and the PlayerShouldStaminaDrain hook can keep it from draining for anyone else. Serverside only.

Parameters

  • target Player

Returns

  • Boolean

Stamina:can_regenerate(target)

server plugins/stamina/plugin/sv_hooks.lua:322

Checks whether the player's stamina may regenerate right now, which the PlayerShouldStaminaRegenerate hook decides. Serverside only.

Parameters

  • target Player

Returns

  • Boolean

Stamina:drain(target, amount)

server plugins/stamina/plugin/sv_hooks.lua:344

Takes stamina from the player and delays its regeneration by the 'stam_regen_delay' config, the way jumping does. Nothing is taken when the stamina may not drain. Serverside only.

if Stamina:get_stamina(actor) >= 10 then
  Stamina:drain(actor, 10)
end

Parameters

  • target Player
  • amount Number stamina points to take

Returns

  • Boolean whether the stamina was taken

See also

Stamina:get_stamina(target)

server plugins/stamina/plugin/sv_hooks.lua:289

Returns the player's current stamina. Serverside only.

Parameters

  • target Player

Returns

  • Number current stamina, or the 'stam_max' config value if it was never set

Stamina:set_stamina(target, stamina)

server plugins/stamina/plugin/sv_hooks.lua:282

Sets the player's stamina, clamped between 0 and the 'stam_max' config value, and networks it. Serverside only.

Parameters

  • target Player
  • stamina Number

Stamina:start_running(target, prevent_drain)

server plugins/stamina/plugin/sv_hooks.lua:361

Pauses the player's stamina regeneration. Unless prevent_drain is set, it also runs the PlayerStartRunning hook on the server and on the player's client, and starts draining stamina every 0.2 seconds. Serverside only.

Parameters

  • target Player
  • prevent_drain Boolean optional, defaults to false only pause the regeneration

Stamina:stop_running(target, prevent_regen)

server plugins/stamina/plugin/sv_hooks.lua:401

Pauses the player's stamina drain. With prevent_regen set it runs the PlayerStopRunning hook on the server and on the player's client; without it, it starts regenerating stamina every 0.2 seconds instead, until the stamina is full. Serverside only.

Parameters

  • target Player
  • prevent_regen Boolean optional, defaults to false do not start the regeneration

Defined in