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
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.Methods
RaiseGun:release_fire lets it fire again before that, and marks it as blocked by the plugin.weapon_class is the class of the weapon.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.RaiseGun:block_fire.Hooks
RaiseGun:CalcViewModelView(weapon, view_model, old_eye_pos, old_eye_angles, eye_pos, eye_angles)
client plugins/raisegun/plugin/cl_hooks.lua:60Turns 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
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
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
Cancels the pending weapon raise toggle when reload is released.
Parameters
- actor Player
- key Number IN_ enum of the released key
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
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.
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
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:8Lowers the player's weapon whenever they switch weapons.
Parameters
- actor Player
- _old_weapon Weapon
- _new_weapon Weapon
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
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:42Implements 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
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
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
Returns the time a weapon that has just been raised cannot fire for.
Returns
- Number seconds from the
weapon_raise_fire_delayconfig; 0 while theweapon_raise_enabledconfig is off
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
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
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:99Reads 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