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
Methods
ScreenEffects.screen: the distortion, the blur and the motion blur, each of them only if it would change the picture.ScreenEffects.screen with what the AdjustScreenEffects hook has last replaced, and hands the color pass to the Color Modify plugin.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:64Adds 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
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.
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.
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.
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. The color
pass is drawn by the Color Modify plugin.
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
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
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
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
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
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.
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
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. Called eight times a second while the effects are active.
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.
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
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.
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