Shared hooks of the Third Person plugin: reads the aim and fire input out of the commands of a player in third person control, keeps track of how long their weapon is to stay raised and takes the secondary attack away from the weapons whose secondary attack the aim takes. On the client it also predicts the raised state of the local player's weapon, so that the Raise Weapon plugin lets the first shot through. On both realms it turns the model of every player in third person control apart from their view angles.

A command is sent to the server before the client runs it through StartCommand, so the server sees the secondary attack the way the player pressed it and learns of the aim from it; the client takes the key out of its own copy of the command only so that the weapon does not predict a secondary attack.

Summary

Hooks

Tints the crosshair while the local player's weapon is being raised in third person and cannot fire yet.
Places the camera while the third person view is on, and while it eases back into the first person view after being turned off.
Turns the camera with the mouse and points the eyes of the local player at what the middle of the screen shows while the camera orbits the character (see is_orbiting).
Draws the weapon state feedback of third person control: a faint dot in the middle of the screen while the crosshair is hidden, so that the player sees what they would use or spawn something at, unless another plugin hides the crosshair as well, during a cinematic or while running for example; a ring around the crosshair that runs down while the weapon stays raised after the player has stopped aiming and firing; and a label under it for a moment after the weapon has been raised or lowered.
Lowers the weapon of a player in third person control once their raise window has run out, and raises a weapon they have switched to while it is still open.
Registers the client settings of the camera with the Settings plugin: 'thirdperson_shoulder', the shoulder the camera aims over when the view is turned on, and 'thirdperson_distance', how far behind the character it is while not aiming.
Hides the crosshair while the third person control is in effect and the model of the local player does not face their aim, that is while their weapon is lowered and they neither aim nor fire.
Predicts the raised state of the local player's weapon while third person control is in effect: the weapon counts as raised while the aim or fire key is held and for ThirdPerson.raise_grace seconds after it was last held, which the server makes true shortly after.
Reads the aim and fire input out of the commands of a player in third person control and takes the secondary attack out of them for the weapons whose secondary attack the aim takes, so that aiming never fires it.
Turns the model of a player in third person control on its own, apart from their view angles, which follow the camera: towards where they aim while their weapon is raised (see ThirdPerson:faces_aim), towards the way they move otherwise, and not at all while they stand still.

Methods

Checks whether the model of a player in third person control faces where they aim rather than the way they move: while their weapon is raised, which includes the tools that are always raised, such as the physgun and the tool gun.
Works out the view angles that point the eyes of a player at what the middle of the screen shows: a trace is run from the camera along its forward direction, and the angles point from the eyes of the player at what it hits.
Checks whether the third person control of a player is in effect: the view is on and the player is alive and on foot, outside a vehicle, not noclipping or observing, seeing through their own eyes rather than another entity and not playing an animation of the Animations plugin.
Checks whether a player has the third person view turned on.
Checks whether the aim takes the secondary attack of a weapon: whether the weapon can be raised and lowered.
Reads the aim input out of the buttons of a user command.
Raises or lowers the active weapon of a player in third person control to match their raise window: raised until the fl_tp_raise_until field of the player, lowered after it.

Hooks

ThirdPerson:AdjustCrosshairColor(_trace, _distance)

client plugins/thirdperson/plugin/cl_plugin.lua:421

Implements hook AdjustCrosshairColor

Tints the crosshair while the local player's weapon is being raised in third person and cannot fire yet.

Parameters

  • _trace Map trace result of the local player's aim
  • _distance Number distance from the local player to the trace hit position

Returns

  • Color the tint, or nil to leave the color alone

ThirdPerson:CalcView(client, pos, angles, fov)

client plugins/thirdperson/plugin/cl_plugin.lua:293

Places the camera while the third person view is on, and while it eases back into the first person view after being turned off. The camera orbits the eyes of the character from straight behind them, with the camera angles while it orbits on its own (see is_orbiting) and the view angles otherwise. While aiming it moves in over a shoulder and narrows the field of view. Every offset eases towards its target, and the view eases between the first and the third person over 0.15 seconds. A box is traced from the eyes to the camera so that it stops in front of walls, and the view becomes first person when the camera ends up too close to the eyes. Picks up the shoulder from the thirdperson_shoulder client setting whenever the view is turned on.

Parameters

  • client Player
  • pos Vector
  • angles Angle
  • fov Number

Returns

  • Map view table, or nil while the first person view is shown or the player looks through another entity

ThirdPerson:CreateMove(user_cmd)

client plugins/thirdperson/plugin/cl_plugin.lua:208

Turns the camera with the mouse and points the eyes of the local player at what the middle of the screen shows while the camera orbits the character (see is_orbiting). The engine turns the view angles of every command by the mouse, starting from the angles the previous command was given. The camera therefore takes the difference between the view angles of the command and the angles it saw or set last time, which is the mouse movement with the player's own sensitivity and acceleration, and anything else that has turned the view, such as a server that has set the angles of the player. The view angles are only set, and the aim and fire input only read, in the commands that are sent to the server. The commands that the engine builds between them to sample the mouse every frame (whose command number is 0) only turn the camera, so that nothing depends on whether the engine keeps what is done to them. While the control is in effect the view angles point from the eyes at the hit of a trace from the camera (see ThirdPerson:get_aim_angles). During an animation of the Animations plugin, which locks the character, they are the camera angles. While the camera does not orbit the command is left alone and the camera angles follow its view angles, so that the camera does not jump when the orbit starts. When the orbit ends with the player on foot, for example when the view is turned off, the view angles are set to the camera angles so that the first person view looks where the camera did.

Parameters

  • user_cmd CUserCmd

ThirdPerson:HUDPaint()

client plugins/thirdperson/plugin/cl_plugin.lua:433

Draws the weapon state feedback of third person control: a faint dot in the middle of the screen while the crosshair is hidden, so that the player sees what they would use or spawn something at, unless another plugin hides the crosshair as well, during a cinematic or while running for example; a ring around the crosshair that runs down while the weapon stays raised after the player has stopped aiming and firing; and a label under it for a moment after the weapon has been raised or lowered.

ThirdPerson:PlayerThink(actor, cur_time)

server plugins/thirdperson/plugin/sv_plugin.lua:62

Implements hook PlayerThink

Lowers the weapon of a player in third person control once their raise window has run out, and raises a weapon they have switched to while it is still open. Raising on input is done at once by the StartCommand handler; this catches what happens between inputs. When the control starts with the weapon raised, the raise window is opened so that the weapon stays up for ThirdPerson.raise_grace seconds rather than being lowered at once.

Parameters

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

ThirdPerson:RegisterClientSettings()

client plugins/thirdperson/plugin/cl_plugin.lua:528

Implements hook RegisterClientSettings

Registers the client settings of the camera with the Settings plugin: 'thirdperson_shoulder', the shoulder the camera aims over when the view is turned on, and 'thirdperson_distance', how far behind the character it is while not aiming. Only called when the Settings plugin is loaded.

ThirdPerson:ShouldHUDPaintCrosshair()

client plugins/thirdperson/plugin/cl_plugin.lua:408

Implements hook ShouldHUDPaintCrosshair

Hides the crosshair while the third person control is in effect and the model of the local player does not face their aim, that is while their weapon is lowered and they neither aim nor fire. The tools that are always raised, such as the physgun and the tool gun, keep it. A faint dot is drawn in its place by the HUDPaint handler. Nothing is answered while that handler asks the other plugins whether they hide the crosshair.

Returns

  • Boolean false to hide the crosshair, nil otherwise

ThirdPerson:ShouldWeaponBeRaised(actor, _weapon)

client plugins/thirdperson/plugin/sh_hooks.lua:36

Implements hook ShouldWeaponBeRaised

Predicts the raised state of the local player's weapon while third person control is in effect: the weapon counts as raised while the aim or fire key is held and for ThirdPerson.raise_grace seconds after it was last held, which the server makes true shortly after. The keys are taken from ThirdPerson.aiming and ThirdPerson.firing, which the CreateMove handler reads out of every command before any StartCommand handler sees it. They cannot be read in this plugin's own StartCommand handler: the Raise Weapon plugin loads first, and its handler takes the attack keys out of the command while the weapon counts as lowered. Answering true as soon as a key is held keeps the keys in the command, so that the first shot is not lost. Nothing is answered for other players, outside of the control, while the weapon_raise_enabled config is off or while the player is running and the sprint_lowers_weapon config keeps the weapon lowered, so that the normal state applies.

Parameters

  • actor Player
  • _weapon Weapon active weapon of the player, one that can be raised and lowered

Returns

  • Boolean true while the weapon is predicted to be raised, nil otherwise

ThirdPerson:StartCommand(actor, user_cmd)

shared plugins/thirdperson/plugin/sh_hooks.lua:57

Reads the aim and fire input out of the commands of a player in third person control and takes the secondary attack out of them for the weapons whose secondary attack the aim takes, so that aiming never fires it. The fists, physgun, gravity gun, tool gun, camera and the weapons the Raise Weapon plugin marks as always or never raised keep it. While the player aims or fires, the raise window is opened again: on the server the fl_tp_raise_until field of the player is set to ThirdPerson.raise_grace seconds from now and a lowered weapon is raised at once (see ThirdPerson:update_raise), on the client ThirdPerson.local_raise_until is set for the local player.

Parameters

  • actor Player
  • user_cmd CUserCmd

ThirdPerson:UpdateAnimation(actor, velocity, _max_seq_ground_speed)

shared plugins/thirdperson/plugin/sh_hooks.lua:109

Turns the model of a player in third person control on its own, apart from their view angles, which follow the camera: towards where they aim while their weapon is raised (see ThirdPerson:faces_aim), towards the way they move otherwise, and not at all while they stand still. Runs on the server and on every client from the same networked state, so that everyone sees the model turned the same way. The movement pose parameters (move_yaw, move_x and move_y) are worked out against the way the model faces instead of the view angles, so that the legs match the movement. While the model does not face the aim, the aim and head pose parameters are set straight, so that the upper body does not twist towards the camera; while it does, aim_yaw makes up for the part of the turn the model has not made yet. The turn is timed with UnPredictedCurTime() per player, so that a player animated twice in a frame does not turn twice as fast.

Parameters

  • actor Player
  • velocity Vector velocity of the player
  • _max_seq_ground_speed Number ground speed of the current sequence

Methods

ThirdPerson:faces_aim(client)

shared plugins/thirdperson/plugin/sh_plugin.lua:129

Checks whether the model of a player in third person control faces where they aim rather than the way they move: while their weapon is raised, which includes the tools that are always raised, such as the physgun and the tool gun. On the client the local player also faces their aim as soon as they aim or fire, before the server has raised the weapon. Without the Raise Weapon plugin only the aim and fire input of the local player counts.

Parameters

  • client Player

Returns

  • Boolean

ThirdPerson:get_aim_angles(client)

client plugins/thirdperson/plugin/cl_plugin.lua:158

Works out the view angles that point the eyes of a player at what the middle of the screen shows: a trace is run from the camera along its forward direction, and the angles point from the eyes of the player at what it hits. When the hit is closer to the camera than the player is, which is when something is between them, the camera angles are used instead. The camera position is rebuilt from the offset the last CalcView left, turned with the current camera angles.

Parameters

  • client Player

Returns

  • Angle

ThirdPerson:is_controlling(client)

shared plugins/thirdperson/plugin/sh_plugin.lua:64

Checks whether the third person control of a player is in effect: the view is on and the player is alive and on foot, outside a vehicle, not noclipping or observing, seeing through their own eyes rather than another entity and not playing an animation of the Animations plugin. Only then does the camera orbit on its own, the character face the way they move and the aim take over the secondary attack.

Parameters

  • client Player

Returns

  • Boolean

ThirdPerson:is_enabled(client)

shared plugins/thirdperson/plugin/sh_plugin.lua:53

Checks whether a player has the third person view turned on. The camera is shown for as long as this is true, whatever the player is doing.

Parameters

  • client Player

Returns

  • Boolean

ThirdPerson:owns_secondary_attack(weapon)

shared plugins/thirdperson/plugin/sh_plugin.lua:92

Checks whether the aim takes the secondary attack of a weapon: whether the weapon can be raised and lowered. Without a valid weapon the aim takes it. The fists keep theirs, since the Pickup Objects plugin picks things up with it.

Parameters

  • weapon Weapon active weapon of the player, which may not be valid

Returns

  • Boolean false for the fists, the physgun, gravity gun, tool gun and camera and for the weapons the Raise Weapon plugin marks as always or never raised

ThirdPerson:read_input(buttons, weapon)

shared plugins/thirdperson/plugin/sh_plugin.lua:115

Reads the aim input out of the buttons of a user command. Aiming is the secondary attack held with a weapon whose secondary attack the aim takes; firing is the primary attack held with any weapon. Both raise the weapon and make the model face where the player aims, only the first moves the camera in over the shoulder.

Parameters

  • buttons Number IN_ button bits of the command
  • weapon Weapon active weapon of the player, which may not be valid

Returns

  • Boolean aiming
  • Boolean firing

ThirdPerson:update_raise(actor, cur_time)

server plugins/thirdperson/plugin/sv_plugin.lua:36

Raises or lowers the active weapon of a player in third person control to match their raise window: raised until the fl_tp_raise_until field of the player, lowered after it. Player:set_weapon_raised is only called when the networked state differs from the wanted one, so that the gestures and the fire blocking of the Raise Weapon plugin run once per change, and a change that the CanPlayerRaiseWeapon hook refuses is not asked for again for half a second. Does nothing without the Raise Weapon plugin, while its weapon_raise_enabled config is off, without a valid weapon and for the weapons whose state is fixed (the physgun, gravity gun, tool gun, camera and the weapons marked as always or never raised). The caller checks that the control is in effect.

Parameters

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

Defined in