Weapon ID enum and helper functions v2
vscript to make working with Weapon IDs easier
Some game events, such as player_hurt, have a parameter for "weaponid" but there's no enumerator in the game that tells you what weapon is what.
This file adds the enumerator
By default, the constants in the enumerator are added to the root table (NOT the constant table), because of this, typing
Also adds helper functions
You can get the inventory ID by getting the NetProp "m_AttributeManager.m_Item.m_iItemDefinitionIndex" from the weapon.
Both functions have 2 inputs: hWeapon, and hAttacker.
hWeapon is the entity handle for the weapon you want.
hAttacker is an optional input for the entity handle of the attacking player. This is used to check the class of the player, so that it returns the correct weapon ID for weapons that are on multiple classes.
The reason I included both is that I already coded the inventory ID when I was told about classnames, and also because it might help if for some reason you need to change the classname of the weapon.
A few more notes:
Officially, the dragons fury uses "TF_WEPON_FLAME_BALL" as its weapon ID, i've made it so that you can either use that or spell it correctly as "TF_WEAPON_FLAME_BALL". They have no difference, its just spelling, I still can't believe valve just made that typo in the first place tbh.
This isn't a good utility for getting the weapon from a weapon ID, its more for sending your own game events. Many weapons share the same weapon ID, and they're mostly only distinguished by major differences in how the weapon works.
I.e. scout's regular bats and the Sandman have 2 different weapon IDs, but most of the bats that do not have a throwable use the same ID as the regular bats.
There are a few oddities in terms of how these IDs match up.
I typed out all the inventory ID numbers manually, so if I missed one, or made a typo, PLEASE tell me.
This file adds the enumerator
eWeaponId
, which contains the internal weapon IDs that the game uses, ripped straight from the game.By default, the constants in the enumerator are added to the root table (NOT the constant table), because of this, typing
eWeaponId.TF_WEAPON_ROCKETLAUNCHER
will give you the same thing as simply typing TF_WEAPON_ROCKETLAUNCHER
Also adds helper functions
GetWeaponIdFromInventoryId()
and GetWeaponIdFromClassname()
so you can easily get the weapon ID from either the classname of the entity, or the inventory ID (what the item schema uses).You can get the inventory ID by getting the NetProp "m_AttributeManager.m_Item.m_iItemDefinitionIndex" from the weapon.
Both functions have 2 inputs: hWeapon, and hAttacker.
hWeapon is the entity handle for the weapon you want.
hAttacker is an optional input for the entity handle of the attacking player. This is used to check the class of the player, so that it returns the correct weapon ID for weapons that are on multiple classes.
The reason I included both is that I already coded the inventory ID when I was told about classnames, and also because it might help if for some reason you need to change the classname of the weapon.
A few more notes:
Officially, the dragons fury uses "TF_WEPON_FLAME_BALL" as its weapon ID, i've made it so that you can either use that or spell it correctly as "TF_WEAPON_FLAME_BALL". They have no difference, its just spelling, I still can't believe valve just made that typo in the first place tbh.
This isn't a good utility for getting the weapon from a weapon ID, its more for sending your own game events. Many weapons share the same weapon ID, and they're mostly only distinguished by major differences in how the weapon works.
I.e. scout's regular bats and the Sandman have 2 different weapon IDs, but most of the bats that do not have a throwable use the same ID as the regular bats.
There are a few oddities in terms of how these IDs match up.
- There's a different ID for each class that can wield a shotgun.
- The scout's pistols and engineer's pistols use different IDs
- All sappers use the "TF_WEAPON_BUILDER" ID, which is shared with engi for his toolbox
- The direct hit has its own ID
- The Half-Zatoichi has its own classname, but uses the "TF_WEAPON_SWORD" ID
- The Gunslinger has its own classname, but uses the "TF_WEAPON_WRENCH" ID
- The Pain Train uses "TF_WEAPON_SHOVEL" on soldier, and "TF_WEAPON_BOTTLE" on demoman
- All-class melee weapons all use the "saxxy" classname", but use the weapon ID of their respective class' stock melee weapons, EXCEPT for heavy, which shared "TF_WEAPON_FIREAXE" with pyro
- Scout drinks (bonk, crit-a-cola) have their own classname, but share the "TF_WEAPON_LUNCHBOX" ID with heavy's food items.
I typed out all the inventory ID numbers manually, so if I missed one, or made a typo, PLEASE tell me.
- License
- Free to use and modify. Credit is appreciated but not required.