Screen Effects adds the effects that tie the local player's screen and view to the state of their character. There are four of them, known by these IDs:

  • 'low_health': the colors drain and a slight motion blur sets in as health drops; the screen is gray while the player is dead.
  • 'heartbeat': a heartbeat is heard at low health and speeds up as health drops further.
  • 'underwater': the picture is distorted and blurred while the view is under water.
  • 'headbob': the view sways while the player walks or runs and shakes when they land after a fall.

An effect is applied when the server allows it, the player has it turned on and no plugin suppresses it. The server allows the effects with the 'allow_low_health_effect', 'allow_heartbeat_effect', 'allow_underwater_effect' and 'allow_headbob_effect' configs, all on by default. With the Settings plugin loaded, every player gets a switch and a strength slider for each effect in the Settings tab: the 'low_health_effect', 'heartbeat_effect', 'underwater_effect' and 'headbob_effect' settings and the settings of the same names ending in '_strength'; without that plugin the effects are on at full strength. A plugin or the schema suppresses an effect by returning false from the ShouldApplyScreenEffect hook.

function MyPlugin:ShouldApplyScreenEffect(id)
  if id == 'heartbeat' and PLAYER:get_nv('observer') then
    return false
  end
end

Nothing is applied while the local player has not been initialized, has no character loaded or is looking at the intro or the main menu.

What ends up on the screen can be changed every frame. AdjustScreenEffects receives the values of the screen passes after the effects of this plugin have set them, and AdjustViewEffects receives the angles that are added to the view; both run whether the effects of the plugin are turned on or not, so other plugins can use the passes for effects of their own. AdjustHeadbob, AdjustHeartbeat and AdjustFallShake change the built-in effects themselves.

function Drunkenness:AdjustScreenEffects(screen)
  local level = PLAYER:get_nv('drunk', 0)

  screen.motion_blur = math.max(screen.motion_blur, level * 0.8)
end

function Drunkenness:AdjustHeadbob(info)
  info.yaw = info.yaw + PLAYER:get_nv('drunk', 0) * 2
end

The color pass of the plugin is folded into the color modification of the Color Modify plugin, on top of the look a schema sets through that plugin, so the screen is only color corrected once; without that plugin the low health effect does not drain the colors. The numbers the effects are built from are in ScreenEffects.defaults, which a schema may change.

A schema turns the plugin on by adding screeneffects to its depends.

Summary

Hooks

Adds the headbob and the fall shake to the view angles.
Looks up the settings of the effects and what the Adjust hooks make of them eight times a second while the local player is in the game with a character.
Registers a switch and a strength slider for every effect with the Settings plugin.
Draws the distortion, the blur and the motion blur of the effects.
Think()client
Advances the effects once a frame, or resets them while the local player is not in the game with a character.

Methods

Draws the screen passes from the values in ScreenEffects.screen: the distortion, the blur and the motion blur, each of them only if it would change the picture.
Checks whether screen effects make sense right now: the local player has been initialized, has a character loaded if the Characters plugin is there, and neither the intro nor the main menu is open.
Returns the strength the local player has set for an effect.
Returns how much of their health the local player has left.
Checks whether the server allows an effect.
Checks whether an effect is applied to the local player: the server allows it, the player has not turned it off and the ShouldApplyScreenEffect hook does not suppress it.
Puts everything back to where nothing is drawn, nothing is added to the view and no heartbeat is heard, and gives the color modification table back to the schema.
Starts the shake of the view that follows a landing.
Stops the heartbeat if it has been playing.
Works out what the headbob should be for the way the local player moves right now and runs the AdjustHeadbob hook; the view follows the result smoothly every frame.
Plays the next beat of the heartbeat when it is due, or stops the heartbeat when the local player is dead, has enough health or the effect is not applied.
Works out what the screen passes draw this frame: fades the low health and the underwater effect towards where they should be, writes their values to ScreenEffects.screen with what the AdjustScreenEffects hook has last replaced, and hands the color pass to the Color Modify plugin.
Looks up what the effects are allowed to do: whether each of them is applied and how strong the player wants it, what the headbob should be for the way the local player moves, and what the AdjustScreenEffects and AdjustViewEffects hooks make of the effects.
Works out what is added to the view angles this frame: notices landings, advances the headbob towards what ScreenEffects:update_headbob_target has last asked for and the fall shake, and writes the result to ScreenEffects.view with what the AdjustViewEffects hook has last added.

Hooks

ScreenEffects:CalcView(client, _origin, angles, _fov)

client plugins/screeneffects/plugin/cl_hooks.lua:64

Adds the headbob and the fall shake to the view angles. The angles are changed in place and nothing is returned, so the handlers of other plugins and the gamemode still build the view from them. Nothing is added while the local player is seen in third person or looks through another entity.

Parameters

  • client Player
  • _origin Vector
  • angles Angle
  • _fov Number

ScreenEffects:LazyTick()

client plugins/screeneffects/plugin/cl_hooks.lua:28

Implements hook LazyTick

Looks up the settings of the effects and what the Adjust hooks make of them eight times a second while the local player is in the game with a character.

ScreenEffects:RegisterClientSettings()

client plugins/screeneffects/plugin/cl_hooks.lua:76

Implements hook RegisterClientSettings

Registers a switch and a strength slider for every effect with the Settings plugin. The settings stay on the client: the effects are worked out there.

ScreenEffects:RenderScreenspaceEffects()

client plugins/screeneffects/plugin/cl_hooks.lua:52

Draws the distortion, the blur and the motion blur of the effects. The color pass is folded into the color modification of the Color Modify plugin, which draws it.

ScreenEffects:Think()

client plugins/screeneffects/plugin/cl_hooks.lua:36

Advances the effects once a frame, or resets them while the local player is not in the game with a character.

Methods

ScreenEffects:draw_screen()

client plugins/screeneffects/plugin/cl_plugin.lua:510

Draws the screen passes from the values in ScreenEffects.screen: the distortion, the blur and the motion blur, each of them only if it would change the picture. The color pass is drawn by the Color Modify plugin.

ScreenEffects:effects_active()

client plugins/screeneffects/plugin/cl_plugin.lua:345

Checks whether screen effects make sense right now: the local player has been initialized, has a character loaded if the Characters plugin is there, and neither the intro nor the main menu is open.

Returns

  • Boolean

ScreenEffects:get_effect_strength(id)

client plugins/screeneffects/plugin/cl_plugin.lua:259

Returns the strength the local player has set for an effect.

Parameters

  • id String effect ID: 'low_health', 'heartbeat', 'underwater' or 'headbob'

Returns

  • Number multiplier of the effect, 1 being the default; always 1 without the Settings plugin, 0 if there is no such effect

ScreenEffects:get_health_fraction()

client plugins/screeneffects/plugin/cl_plugin.lua:361

Returns how much of their health the local player has left.

Returns

  • Number 1 at full health or above, 0 with no health left or dead

ScreenEffects:is_effect_allowed(id)

client plugins/screeneffects/plugin/cl_plugin.lua:220

Checks whether the server allows an effect.

Parameters

  • id String effect ID: 'low_health', 'heartbeat', 'underwater' or 'headbob'

Returns

  • Boolean true if the config of the effect is on, false if it is off or there is no such effect

ScreenEffects:is_effect_enabled(id)

client plugins/screeneffects/plugin/cl_plugin.lua:234

Checks whether an effect is applied to the local player: the server allows it, the player has not turned it off and the ShouldApplyScreenEffect hook does not suppress it.

Parameters

  • id String effect ID: 'low_health', 'heartbeat', 'underwater' or 'headbob'

Returns

  • Boolean

ScreenEffects:reset_effects()

client plugins/screeneffects/plugin/cl_plugin.lua:374

Puts everything back to where nothing is drawn, nothing is added to the view and no heartbeat is heard, and gives the color modification table back to the schema. Called every frame while the effects are not active.

ScreenEffects:start_fall_shake(speed)

client plugins/screeneffects/plugin/cl_plugin.lua:606

Starts the shake of the view that follows a landing. Does nothing if the local player came down slower than ScreenEffects.defaults.fall_min_speed.

Parameters

  • speed Number downward speed right before the landing, in units per second

ScreenEffects:stop_heartbeat()

client plugins/screeneffects/plugin/cl_plugin.lua:592

Stops the heartbeat if it has been playing.

ScreenEffects:update_headbob_target()

client plugins/screeneffects/plugin/cl_plugin.lua:639

Works out what the headbob should be for the way the local player moves right now and runs the AdjustHeadbob hook; the view follows the result smoothly every frame. Called eight times a second while the effects are active.

ScreenEffects:update_heartbeat()

client plugins/screeneffects/plugin/cl_plugin.lua:533

Plays the next beat of the heartbeat when it is due, or stops the heartbeat when the local player is dead, has enough health or the effect is not applied. The lower the health, the sooner the next beat follows and the louder it is. The sound of the heartbeat is a loop of a single beat that would repeat at its own pace, so every beat starts the sound over and the sound is cut off once that beat has been heard.

ScreenEffects:update_screen(frame_time)

client plugins/screeneffects/plugin/cl_plugin.lua:482

Works out what the screen passes draw this frame: fades the low health and the underwater effect towards where they should be, writes their values to ScreenEffects.screen with what the AdjustScreenEffects hook has last replaced, and hands the color pass to the Color Modify plugin.

Parameters

  • frame_time Number seconds since the last frame

ScreenEffects:update_settings()

client plugins/screeneffects/plugin/cl_plugin.lua:422

Looks up what the effects are allowed to do: whether each of them is applied and how strong the player wants it, what the headbob should be for the way the local player moves, and what the AdjustScreenEffects and AdjustViewEffects hooks make of the effects. Called eight times a second while the effects are active; the frames in between only move the effects towards these values.

ScreenEffects:update_view(frame_time)

client plugins/screeneffects/plugin/cl_plugin.lua:684

Works out what is added to the view angles this frame: notices landings, advances the headbob towards what ScreenEffects:update_headbob_target has last asked for and the fall shake, and writes the result to ScreenEffects.view with what the AdjustViewEffects hook has last added.

Parameters

  • frame_time Number seconds since the last frame

Defined in