Weapon Selector replaces the default weapon selection HUD with a scrolling list of the player's weapons. The invprev, invnext and slot binds move the highlight, and attack selects the highlighted weapon through the selectweapon console command. The selector closes after five seconds without input. Plugins can keep it from reacting with the ShouldOpenWepselect hook and follow it through OnWeaponIndexChange and OnWeaponSelected.

Summary

Hooks

Draws the weapon selector while it is open and animates its entries scrolling toward the highlighted weapon.
Hides the default weapon selection HUD.
Opens the weapon selector and starts scrolling it from the old index to the new one.
Closes the weapon selector and clears its entries once a weapon has been selected.
Handles the weapon selection binds: invprev, invnext and slot binds move the highlight, attack selects the highlighted weapon while the selector is open.
Think()shared
Fades the weapon selector in while it is in use, and fades it out and closes it after five seconds without input.

Methods

Builds the five selector entries (two above and two below) around a weapon index.

Hooks

PLUGIN:HUDPaint()

shared plugins/sh_weaponselect.lua:59

Draws the weapon selector while it is open and animates its entries scrolling toward the highlighted weapon.

PLUGIN:HUDShouldDraw(element)

shared plugins/sh_weaponselect.lua:51

Hides the default weapon selection HUD.

Parameters

  • element String name of the HUD element

Returns

  • Boolean false for 'CHudWeaponSelection', nil otherwise

PLUGIN:OnWeaponIndexChange(old_index, index)

shared plugins/sh_weaponselect.lua:277

Implements hook OnWeaponIndexChange

Opens the weapon selector and starts scrolling it from the old index to the new one.

Parameters

  • old_index Number previously highlighted index in the player's weapon list
  • index Number newly highlighted index

PLUGIN:OnWeaponSelected(_index)

shared plugins/sh_weaponselect.lua:296

Implements hook OnWeaponSelected

Closes the weapon selector and clears its entries once a weapon has been selected.

Parameters

  • _index Number index of the selected weapon in the player's weapon list

PLUGIN:PlayerBindPress(client, bind, pressed)

shared plugins/sh_weaponselect.lua:192

Handles the weapon selection binds: invprev, invnext and slot binds move the highlight, attack selects the highlighted weapon while the selector is open. Ignored in vehicles, while attack is held and when ShouldOpenWepselect returns false.

Parameters

  • client Player
  • bind String the bind's command
  • pressed Boolean whether the bind was pressed rather than released

Returns

  • Boolean true if the bind was consumed, nil otherwise

PLUGIN:Think()

shared plugins/sh_weaponselect.lua:168

Fades the weapon selector in while it is in use, and fades it out and closes it after five seconds without input.

Methods

PLUGIN:make_display(index, tab)

shared plugins/sh_weaponselect.lua:307

Builds the five selector entries (two above and two below) around a weapon index. Each entry is a table with the fields weapon, scale, x, y and highlight.

Parameters

  • index Number index in the local player's weapon list; wraps around
  • tab Boolean optional, defaults to false return the entries instead of storing them in self.display

Returns

  • List<Map> the entries if tab is set, nil otherwise

Defined in