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
Methods
Hooks
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.
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
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
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
Removes every stamina timer when the code is reloaded, and forgets what the players were doing so that the timers are started again.
Implements hook PlayerDisconnected
Removes the stamina timers of a player who leaves the server.
Parameters
- actor Player
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
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
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
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
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
Checks whether the player's stamina may regenerate right now, which the PlayerShouldStaminaRegenerate hook decides. Serverside only.
Parameters
- target Player
Returns
- Boolean
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
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
Sets the player's stamina, clamped between 0 and the 'stam_max' config value, and networks it. Serverside only.
Parameters
- target Player
- stamina Number
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
falseonly pause the regeneration
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
falsedo not start the regeneration