Player Core
scripts/vscripts/alyxlib/player/core.lua
Global variables
| PLAYER WEAPON | |
|---|---|
PLAYER_WEAPON_HAND |
"hand_use_controller" |
PLAYER_WEAPON_ENERGYGUN |
"hlvr_weapon_energygun" |
PLAYER_WEAPON_RAPIDFIRE |
"hlvr_weapon_rapidfire" |
PLAYER_WEAPON_SHOTGUN |
"hlvr_weapon_shotgun" |
PLAYER_WEAPON_MULTITOOL |
"hlvr_multitool" |
PLAYER_WEAPON_GENERIC_PISTOL |
"hlvr_weapon_generic_pistol" |
Properties
HMDAvatar
Default value
nil
HMDAnchor
Default value
nil
Hands
Default value
table
LeftHand
Default value
nil
RightHand
Default value
nil
PrimaryHand
Default value
nil
SecondaryHand
Default value
nil
IsLeftHanded
Default value
false
LastItemDropped
Default value
nil
LastClassDropped
Default value
""
LastItemGrabbed
Default value
nil
LastClassGrabbed
Default value
""
CurrentlyEquipped
Default value
PLAYER_WEAPON_HAND
PreviouslyEquipped
Default value
PLAYER_WEAPON_HAND
Items
Default value
table
ItemHeld
Default value
nil
LastItemDropped
Default value
nil
LastClassDropped
Default value
""
LastItemGrabbed
Default value
nil
LastClassGrabbed
Default value
""
Literal
Default value
nil
WristItem
Default value
nil
Opposite
Default value
nil
Methods
DropByHandle
Force the player to drop an entity if held.
Parameters
handle
EntityHandle
Handle of the entity to drop
DropLeftHand
Force the player to drop any item held in their left hand.
DropRightHand
Force the player to drop any item held in their right hand.
DropPrimaryHand
Force the player to drop any item held in their primary hand.
DropSecondaryHand
Force the player to drop any item held in their secondary/off hand.
DropCaller
Force the player to drop the caller entity if held.
Parameters
data
IOParams
DropActivator
Force the player to drop the activator entity if held.
Parameters
data
IOParams
GrabByHandle
Force the player to grab handle with hand.
Parameters
handle
EntityHandlehand(optional)
CPropVRHand,0,1
GrabCaller
Force the player to grab the caller entity.
Parameters
data
IOParams
GrabActivator
Force the player to grab the activator entity.
Parameters
data
IOParams
GetMoveType
Get VR movement type.
Returns
- PlayerMoveType
SetMoveType
Sets the VR movement type.
Parameters
movetype
PlayerMoveType
GetLookingAt
Returns the entity the player is looking at directly.
Parameters
maxDistance(optional)
number
Max distance the trace can search.
Returns
- EntityHandle?
DisableFallDamage
Disables fall damage for the player.
EnableFallDamage
Enables fall damage for the player.
AddResources
Adds resources to the player.
Parameters
pistol_ammo(optional)
numberrapidfire_ammo(optional)
numbershotgun_ammo(optional)
numberresin(optional)
number
SetResources
Sets resources for the player.
Parameters
pistol_ammo(optional)
numberrapidfire_ammo(optional)
numbershotgun_ammo(optional)
numberresin(optional)
number
SetItems
Set the items that player has manually.
This is purely for scripting and does not modify the actual items the player has in game.
Use Player:AddResources to modify in-game items.
Parameters
energygun_ammo(optional)
integergeneric_pistol_ammo(optional)
integerrapidfire_ammo(optional)
integershotgun_ammo(optional)
integerresin(optional)
integer
AddPistolAmmo
Add pistol ammo to the player.
Parameters
amount
number
AddShotgunAmmo
Add shotgun ammo to the player.
Parameters
amount
number
AddRapidfireAmmo
Add rapidfire ammo to the player.
Parameters
amount
number
AddResin
Add resin to the player.
Parameters
amount
number
GetImmediateItems
Gets the items currently held or in wrist pockets.
Returns
- EntityHandle[]
GetGrenades
Gets the grenades currently held or in wrist pockets.
Use #Player:GetGrenades() to get number of grenades player has access to.
Returns
- EntityHandle[]
GetHealthPens
Gets the health pens currently held or in wrist pockets.
Use #Player:GetHealthPens() to get number of health pens player has access to.
Returns
- EntityHandle[]
MergePropWithHand
Marges an existing prop with a given hand.
Parameters
hand
CPropVRHand,0,1
The hand handle or index.prop
EntityHandle,string
The prop handle or targetname.hide_hand
boolean
If the hand should turn invisible after merging.
HasWeaponEquipped
Return if the player has a gun equipped.
Returns
- boolean
GetCurrentWeaponReserves
Get the amount of ammo stored in the backpack for the currently equipped weapon.
This is not accurate if ammo was given through special means like info_hlvr_equip_player.
Returns
- number
The amount of ammo, or 0 if no weapon equipped
HasItemHolder
Player has item holder equipped.
Returns
- boolean
HasGrabbityGloves
Player has grabbity gloves equipped.
Returns
- boolean
GetFlashlight
GetFlashlightPointedAt
Get the first entity the flashlight is pointed at (if the flashlight exists).
If flashlight does not exist, both returns will be nil.
Parameters
maxDistance
number
Max tracing distance, default is 2048.
Returns
EntityHandle|nil
The entity that was hit, or nil.
Vector|nil
The position the trace hit, regardless of entity found.
GetResin
Gets the current resin from the player.
This is can be more accurate than Player.Items.resin
Calling this will update Player.Items.resin
Returns
- number
IsHolding
Gets if player is holding an entity in either hand.
Parameters
entity
EntityHandle
Returns
- boolean
GetWeapon
Get the entity handle of the currently equipped weapon/item. If nothing is equipped this will return the primary hand entity.
Returns
- EntityHandle|nil
GetPistolUpgrades
Get the current upgrades for the player's pistol.
Parameters
weapon(optional)
EntityHandle
Optional weapon to check instead of the player's weapon.
Returns
- PlayerPistolUpgrades[]
GetRapidfireUpgrades
Get the current upgrades for the player's rapidfire.
Parameters
weapon(optional)
EntityHandle
Optional weapon to check instead of the player's weapon.
Returns
- PlayerRapidfireUpgrades[]
GetShotgunUpgrades
Get the current upgrades for the player's shotgun.
This will NOT return "shotgun_upgrade_quick_fire" because there is no known way to detect this!
Parameters
weapon(optional)
EntityHandle
Optional weapon to check instead of the player's weapon.
Returns
- PlayerShotgunUpgrades[]
HasWeaponUpgrade
Check if the player has a specific weapon upgrade.
Parameters
upgrade
PlayerPistolUpgrades,PlayerRapidfireUpgrades,PlayerShotgunUpgrades
Returns
- boolean
GetWorldForward
Get the forward vector of the player in world space coordinates (z is zeroed).
Returns
- Vector
UpdateWeapons
Update player weapon inventory, both removing and setting.
Parameters
removes(optional)
(string|EntityHandle)[]
List of classnames or handles to remove.set(optional)
string,EntityHandle
Classname or handle to set as active weapon.
Returns
- EntityHandle?
The handle of the newly set weapon if given and found.
RemoveWeapons
Remove weapons from the player inventory.
Parameters
weapons
(string|EntityHandle)[]
List of classnames or handles to remove.
SetWeapon
Set the weapon that the player is holding.
Parameters
weapon
string,EntityHandle
Classname or handle to set as active weapon.
Returns
- EntityHandle?
The handle of the newly set weapon if found.
UpdateWeaponsExistence
Updates the existence of weapons in Player.Items.weapons by checking weapon switch entities.
This is called automatically whenever the weapon_switch event fires.
GetWeapons
Returns Player.Items.weapons flattened into a single array.
Returns
- EntityHandle[]
GetBackpack
Get the invisible player backpack.
This is will return the backpack even if it has been disabled with a info_hlvr_equip_player.
Returns
- EntityHandle?
SetMovementEnabled
Enable or disable player movement. Including teleport movement.
Parameters
enabled
boolean
True if movement should be enabled.delay(optional)
number
Optional delay for movement state will be changed
SetAnchorForwardAroundPlayer
Sets the forward vector of the HMD anchor while keeping the position the same relative to the player.
Normally if the player is off-center when changing the forward vector the player may appear to move too.
Parameters
forward
Vector
Normalized forward vector
SetAnchorAnglesAroundPlayer
Sets the angle of the HMD anchor while keeping the position the same relative to the player.
Normally if the player is off-center when changing the angle the player may appear to move too.
Parameters
angles
QAngle
New angle of the anchor
SetAnchorOriginAroundPlayer
Sets the origin of the HMD anchor while keeping the position the same relative to the player.
This essentially moves the player by moving the anchor and can be used in instances where setting the player origin does not work.
Parameters
pos
Vector
SetCoughHandEnabled
Sets the enabled state of the cough handpose attached to the HMD avatar.
Parameters
enabled
boolean
True if the cough handpose should be enabled
Aliases
PlayerPistolUpgrades
| Value | Description |
|---|---|
"pistol_upgrade_laser_sight" |
|
"pistol_upgrade_reflex_sight" |
|
"pistol_upgrade_bullet_hopper" |
|
"pistol_upgrade_burst_fire" |
PlayerRapidfireUpgrades
| Value | Description |
|---|---|
"rapidfire_upgrade_reflex_sight" |
|
"rapidfire_upgrade_laser_right" |
|
"rapidfire_upgrade_extended_magazine" |
PlayerShotgunUpgrades
| Value | Description |
|---|---|
"shotgun_upgrade_autoloader" |
|
"shotgun_upgrade_grenade_launcher" |
|
"shotgun_upgrade_laser_sight" |
|
"shotgun_upgrade_quick_fire" |
PlayerWeaponUpgrades
| Value | Description |
|---|---|
PlayerPistolUpgrades |
|
PlayerRapidfireUpgrades |
|
PlayerShotgunUpgrades |