Raise Weapon keeps weapons lowered until the player raises them by holding the reload key for a second. Holding the key again lowers the weapon, and so does switching weapons. A lowered weapon cannot fire and is held in a lowered pose; the physgun, gravity gun, tool gun and camera always count as raised. The state is read and changed with Player:is_weapon_raised, Player:set_weapon_raised and Player:toggle_weapon_raised, and plugins take part through the CanPlayerRaiseWeapon, ShouldWeaponBeRaised, OnWeaponRaised, WeaponRaised, WeaponLowered, CanPlayerAttack and AdjustWeaponLoweredView hooks.

A weapon can fix its own state and its lowered pose with fields, which are read from the item that gives the weapon (the item template whose weapon_class is the class of the weapon) and, where the item does not set them, from the weapon itself:

-- In an item file. The weapon is held in the lowered pose and cannot be raised, but it
-- can still be used.
ITEM.never_raised = true
-- The weapon cannot be lowered, like the physgun.
ITEM.always_raised = true
-- The lowered pose: how far the view model is turned and moved.
ITEM.lowered_angles = Angle(0, 45, 0)
ITEM.lowered_origin = Vector(3, 0, -4)

-- The same in a scripted weapon.
SWEP.NeverRaised = true
SWEP.AlwaysRaised = true
SWEP.LoweredAngles = Angle(0, 45, 0)
SWEP.LoweredOrigin = Vector(3, 0, -4)

The angles turn the view model around its up (pitch field), forward (yaw field) and right (roll field) axes, and the origin moves it to the right (x), forward (y) and up (z). RaiseGun:get_fixed_state tells what the fields make of a weapon.

The plugin has three configs, whose defaults leave it working the way it does without them: weapon_raise_enabled turns the lowering of weapons off altogether, sprint_lowers_weapon lowers the weapon of a running player, and weapon_raise_fire_delay is the time a weapon cannot fire for after it has been raised.

Summary

Hooks

Turns and moves the view model into the lowered pose while the local player's weapon is not raised, then lets the weapon's GetViewModelPosition and CalcViewModelView adjust it.
Prevents the local player from attacking while their weapon is lowered, unless it is a weapon that is never raised: such a weapon is used in the lowered pose.
Starts a one second timer that toggles the player's weapon raise when reload is pressed.
Cancels the pending weapon raise toggle when reload is released.
Tells the animation code whether to use the raised weapon animations for the player.
Forgets which items give which weapons, so that they are looked up again among the items of the schema and the plugins that have just been loaded.
Runs the UpdateWeaponRaised hook with the current time if the weapon is valid.
Registers the WeaponRaised data table boolean on the player.
Lowers the player's weapon whenever they switch weapons.
Keeps the player's active weapon from firing for as long as it is lowered, and lets it fire again when it stops being lowered without Player:set_weapon_raised having been called: the player has stopped running, a ShouldWeaponBeRaised handler no longer keeps it down or the weapon_raise_enabled config has been turned off.
Removes the attack keys from the command when the CanPlayerAttack hook returns false.
Lets the weapon fire again (raised, or a weapon that cannot be lowered) or blocks its fire until it is raised (lowered).

Methods

Keeps a weapon from firing, for a day unless RaiseGun:release_fire lets it fire again before that, and marks it as blocked by the plugin.
Finds the item that gives a weapon: the item template whose weapon_class is the class of the weapon.
Returns the time a weapon that has just been raised cannot fire for.
Tells whether the raised state of a weapon is fixed by the weapon itself.
Tells whether a weapon that RaiseGun:block_fire has blocked has moved its own next fire closer since, on a reload for example, so that it could fire although it is lowered.
Lets a weapon fire again from the given time on and clears the mark left by RaiseGun:block_fire.
Reads one of the raise settings of a weapon: from the item that gives the weapon if the item sets it, from the weapon itself otherwise.

Hooks

RaiseGun:CalcViewModelView(weapon, view_model, old_eye_pos, old_eye_angles, eye_pos, eye_angles)

client plugins/raisegun/plugin/cl_hooks.lua:60

Turns and moves the view model into the lowered pose while the local player's weapon is not raised, then lets the weapon's GetViewModelPosition and CalcViewModelView adjust it. The pose eases in and out over PLAYER.fl_raised_fraction, from 0 (raised) to 100 (lowered), and snaps to either end once it is close; while the weapon is fully raised the view model is left as it is, apart from what the weapon itself adjusts.

Parameters

  • weapon Weapon
  • view_model Entity
  • old_eye_pos Vector
  • old_eye_angles Angle
  • eye_pos Vector
  • eye_angles Angle

Returns

  • Vector view model position
  • Angle view model angles; nothing if the weapon is not valid

RaiseGun:CanPlayerAttack()

client plugins/raisegun/plugin/cl_hooks.lua:138

Implements hook CanPlayerAttack

Prevents the local player from attacking while their weapon is lowered, unless it is a weapon that is never raised: such a weapon is used in the lowered pose.

Returns

  • Boolean false if the weapon is lowered, nil otherwise

RaiseGun:KeyPress(actor, key)

shared plugins/raisegun/plugin/sh_plugin.lua:182

Starts a one second timer that toggles the player's weapon raise when reload is pressed. Does nothing while the weapon_raise_enabled config is off.

Parameters

  • actor Player
  • key Number IN_ enum of the pressed key

RaiseGun:KeyRelease(actor, key)

shared plugins/raisegun/plugin/sh_plugin.lua:195

Cancels the pending weapon raise toggle when reload is released.

Parameters

  • actor Player
  • key Number IN_ enum of the released key

RaiseGun:ModelWeaponRaised(actor, _model)

shared plugins/raisegun/plugin/sh_plugin.lua:205

Implements hook ModelWeaponRaised

Tells the animation code whether to use the raised weapon animations for the player.

Parameters

  • actor Player
  • _model String the player's model

Returns

  • Boolean whether the player's weapon is raised

RaiseGun:OnSchemaLoaded()

shared plugins/raisegun/plugin/sh_plugin.lua:174

Implements hook OnSchemaLoaded

Forgets which items give which weapons, so that they are looked up again among the items of the schema and the plugins that have just been loaded.

RaiseGun:OnWeaponRaised(actor, weapon, raised)

server plugins/raisegun/plugin/sv_hooks.lua:16

Implements hook OnWeaponRaised

Runs the UpdateWeaponRaised hook with the current time if the weapon is valid.

Parameters

  • actor Player
  • weapon Weapon the player's active weapon
  • raised Boolean whether the weapon is now raised

RaiseGun:PlayerSetupDataTables(target)

shared plugins/raisegun/plugin/sh_plugin.lua:211

Implements hook PlayerSetupDataTables

Registers the WeaponRaised data table boolean on the player.

Parameters

  • target Player

RaiseGun:PlayerSwitchWeapon(actor, _old_weapon, _new_weapon)

server plugins/raisegun/plugin/sv_hooks.lua:8

Lowers the player's weapon whenever they switch weapons.

Parameters

  • actor Player
  • _old_weapon Weapon
  • _new_weapon Weapon

RaiseGun:PlayerThink(actor, cur_time)

server plugins/raisegun/plugin/sv_hooks.lua:94

Implements hook PlayerThink

Keeps the player's active weapon from firing for as long as it is lowered, and lets it fire again when it stops being lowered without Player:set_weapon_raised having been called: the player has stopped running, a ShouldWeaponBeRaised handler no longer keeps it down or the weapon_raise_enabled config has been turned off. The fire is touched when the state of the weapon flips, which the fl_fire_blocked mark on the weapon keeps track of, when the player has switched to the weapon, since deploying it may have let it fire again, and when a lowered weapon has moved its own next fire closer, which a weapon does on a reload for example; the last is a comparison on every tick. A weapon that is never raised is not kept from firing.

Parameters

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

RaiseGun:StartCommand(_actor, user_cmd)

client plugins/raisegun/plugin/cl_hooks.lua:124

Removes the attack keys from the command when the CanPlayerAttack hook returns false.

Parameters

  • _actor Player
  • user_cmd CUserCmd

RaiseGun:UpdateWeaponRaised(actor, weapon, raised, cur_time)

server plugins/raisegun/plugin/sv_hooks.lua:42

Implements hook UpdateWeaponRaised

Lets the weapon fire again (raised, or a weapon that cannot be lowered) or blocks its fire until it is raised (lowered). Then calls the weapon's OnRaised or OnLowered method and runs the WeaponRaised or WeaponLowered hook. A weapon that has just been raised can fire once the weapon_raise_fire_delay config has passed; a weapon that cannot be lowered can fire at once. A weapon that has been raised while something else still keeps it lowered (the player is running and the sprint_lowers_weapon config is on, or a ShouldWeaponBeRaised handler holds it down) stays blocked, and PlayerThink lets it fire once that is over. The fire of a weapon that is never raised is not blocked when it is lowered.

Parameters

  • actor Player
  • weapon Weapon
  • raised Boolean whether the weapon is now raised
  • cur_time Number CurTime() of the change

Methods

RaiseGun:block_fire(weapon, cur_time)

shared plugins/raisegun/plugin/sh_plugin.lua:143

Keeps a weapon from firing, for a day unless RaiseGun:release_fire lets it fire again before that, and marks it as blocked by the plugin.

Parameters

  • weapon Weapon
  • cur_time Number CurTime() of the call

RaiseGun:find_weapon_item(class)

shared plugins/raisegun/plugin/sh_plugin.lua:69

Finds the item that gives a weapon: the item template whose weapon_class is the class of the weapon. Base items are skipped, and of several items that give the same weapon the one whose ID comes first alphabetically is taken, so that the server and the clients agree. The answer is remembered for every class until the schema is loaded again.

Parameters

  • class String weapon class

Returns

  • Item item template, or nil if no item gives the weapon or the items plugin is not loaded

RaiseGun:get_fire_delay()

shared plugins/raisegun/plugin/sh_plugin.lua:131

Returns the time a weapon that has just been raised cannot fire for.

Returns

  • Number seconds from the weapon_raise_fire_delay config; 0 while the weapon_raise_enabled config is off

RaiseGun:get_fixed_state(weapon)

shared plugins/raisegun/plugin/sh_plugin.lua:116

Tells whether the raised state of a weapon is fixed by the weapon itself. The physgun, gravity gun, tool gun and camera are always raised, and so is a weapon with the always_raised item field or the AlwaysRaised weapon field. A weapon with the never_raised item field or the NeverRaised weapon field is never raised.

Parameters

  • weapon Weapon

Returns

  • Boolean true if the weapon is always raised, false if it is never raised, nil if it can be raised and lowered

RaiseGun:is_fire_unblocked(weapon, cur_time)

shared plugins/raisegun/plugin/sh_plugin.lua:155

Tells whether a weapon that RaiseGun:block_fire has blocked has moved its own next fire closer since, on a reload for example, so that it could fire although it is lowered.

Parameters

  • weapon Weapon
  • cur_time Number CurTime() of the call

Returns

  • Boolean true if either fire is less than an hour away

RaiseGun:release_fire(weapon, next_fire)

shared plugins/raisegun/plugin/sh_plugin.lua:165

Lets a weapon fire again from the given time on and clears the mark left by RaiseGun:block_fire.

Parameters

  • weapon Weapon
  • next_fire Number CurTime() based time of the first shot that is allowed

RaiseGun:weapon_option(weapon, class, item_key, weapon_key)

shared plugins/raisegun/plugin/sh_plugin.lua:99

Reads one of the raise settings of a weapon: from the item that gives the weapon if the item sets it, from the weapon itself otherwise.

Parameters

  • weapon Weapon
  • class String class of the weapon
  • item_key String name of the field of the item, e.g. 'never_raised'
  • weapon_key String name of the field of the weapon, e.g. 'NeverRaised'

Returns

  • Any value of the field, nil if neither the item nor the weapon sets it

Defined in