Main file of the Hunger plugin, which makes players need food, water and sleep; includes the plugin's server and client files and defines the shared PlayerHasNeeds hook.

PlayerHasNeeds gives needs to everyone but the Combine, except that Civil Protection (FACTION_MPF) have them too.

Summary

Hooks

Called to add HUD bars; adds the hunger bar, with thirst as its second value, below 90 hunger.
Called every second for each player; drains the needs of players with needs and applies their effects.
Called to check whether a player gets hungry, thirsty and tired.
Called when character data is restored; defaults hunger and thirst to 100 and fatigue to 0.
Called when character data is saved; rounds the hunger, thirst and fatigue values.
Called to check whether a player's health regenerates; blocks it below 65 hunger.
Called to check whether a player's stamina regenerates; blocks it below 30 thirst.
Called every player think; jumping and running in the air tire a player with needs and drain thirst.
Called after a player uses an item; feeds them when it is food or drink.
Called after a player spawns; resets their needs on a respawn that is neither the first nor a light spawn.

Hooks

Implements hook GetBars

Called to add HUD bars; adds the hunger bar, with thirst as its second value, below 90 hunger.

Parameters

  • bars Map The HUD bars being built

PLUGIN:OnePlayerSecond(player, curTime, infoTable)

server gamemodes/cwhl2rp/plugins/hunger/plugin/sv_hooks.lua:120

Implements hook OnePlayerSecond

Called every second for each player; drains the needs of players with needs and applies their effects.

Hunger and thirst fall so that they empty over the hunger_tick and thirst_tick configs in seconds, and hunger is never above thirst. Fatigue rises over 20000 seconds. Starving players slowly lose health down to 50 (below 15 hunger) or 20 (below 5), and players above 85 fatigue fall asleep for 30 seconds while alive. The values are networked as the Hunger, Thirst and Fatigue net vars.

Parameters

  • player Player The player
  • curTime Number The current time
  • infoTable Map The player's info table

PLUGIN:PlayerHasNeeds(player)

shared gamemodes/cwhl2rp/plugins/hunger/plugin/sh_plugin.lua:18

Implements hook PlayerHasNeeds

Called to check whether a player gets hungry, thirsty and tired.

Everyone but the Combine has needs; Civil Protection have them too.

Parameters

  • player Player The player to check

Returns

  • Boolean Whether the player has needs

PLUGIN:PlayerRestoreCharacterData(player, data)

server gamemodes/cwhl2rp/plugins/hunger/plugin/sv_hooks.lua:31

Implements hook PlayerRestoreCharacterData

Called when character data is restored; defaults hunger and thirst to 100 and fatigue to 0.

Parameters

  • player Player The player whose character is loading
  • data Character The character data, modified in place

PLUGIN:PlayerSaveCharacterData(player, data)

server gamemodes/cwhl2rp/plugins/hunger/plugin/sv_hooks.lua:13

Implements hook PlayerSaveCharacterData

Called when character data is saved; rounds the hunger, thirst and fatigue values.

Parameters

  • player Player The player being saved
  • data Character The character data to save, modified in place

PLUGIN:PlayerShouldHealthRegenerate(player)

server gamemodes/cwhl2rp/plugins/hunger/plugin/sv_hooks.lua:160

Implements hook PlayerShouldHealthRegenerate

Called to check whether a player's health regenerates; blocks it below 65 hunger.

Parameters

  • player Player The player to check

Returns

  • Boolean false to block regeneration, otherwise nil

PLUGIN:PlayerShouldStaminaRegenerate(player)

server gamemodes/cwhl2rp/plugins/hunger/plugin/sv_hooks.lua:173

Implements hook PlayerShouldStaminaRegenerate

Called to check whether a player's stamina regenerates; blocks it below 30 thirst.

Parameters

  • player Player The player to check

Returns

  • Boolean false to block regeneration, otherwise nil

PLUGIN:PlayerThink(player, curTime, infoTable)

server gamemodes/cwhl2rp/plugins/hunger/plugin/sv_hooks.lua:95

Implements hook PlayerThink

Called every player think; jumping and running in the air tire a player with needs and drain thirst.

Thirst drains by the thirst_drain_scale config, in hundredths, per think.

Parameters

  • player Player The player thinking
  • curTime Number The current time
  • infoTable Map The player's info table for this think, with isJumping and isRunning

PLUGIN:PlayerUseItem(player, itemTable)

server gamemodes/cwhl2rp/plugins/hunger/plugin/sv_hooks.lua:61

Implements hook PlayerUseItem

Called after a player uses an item; feeds them when it is food or drink.

Applies to items with a hunger, thirst or fatigue field and to items in a consumables, alcohol, UU-branded or food category. Missing values default to the hunger_default_refill config. Drinks (a thirst field or "water" in the name) refill thirst and only 40% of the hunger value; a fatigue field reduces fatigue. Saves the character afterwards.

Parameters

  • player Player The player who used the item
  • itemTable Item The item used

PLUGIN:PostPlayerSpawn(player, lightSpawn, changeClass, firstSpawn)

server gamemodes/cwhl2rp/plugins/hunger/plugin/sv_hooks.lua:43

Implements hook PostPlayerSpawn

Called after a player spawns; resets their needs on a respawn that is neither the first nor a light spawn.

Parameters

  • player Player The player that spawned
  • lightSpawn Boolean Whether this was a light spawn
  • changeClass Boolean Whether the player changed class
  • firstSpawn Boolean Whether this is the character's first spawn

Defined in