weapon_knife

From Valve Developer Community
Jump to: navigation, search
English (en)Translate (Translate)
Class hierarchy
CKnife
CWeaponCSBase
CBaseCombatWeapon
CBaseAnimating
CBaseEntity
weapon_knife.cpp
weapon_knife in Counter-Strike: Source.
weapon_knife in Counter-Strike: Global Offensive.

weapon_knife is a point entity available in Counter-Strike: Source Counter-Strike: Source, Counter-Strike: Global Offensive Counter-Strike: Global Offensive, and Counter-Strike 2 Counter-Strike 2.

Entity Description

Counter-Strike: SourceA knife, Counter-Strike's only melee weapon. Can be used by both teams.
Counter-Strike: Global Offensive

Every player on the Counter-Terrorist's team, who has nothing different equipped in his loadout, is given this entity when respawning in any gamemode, except mp_ct_default_melee is set to "" while game_type is not 1. The Terrorist's equivalent is weapon_knife_t.

All knife entities (weapon_knife_t, weapon_knife_karambit, ...) have the classname weapon_knife in-game after being spawned, except the Golden Knife. This can be observed by invoking ent_messages_draw 1 and ent_fire weapon_knife.

Damage against unarmored (armored) Players
Attack Type Counter-Strike: Source Counter-Strike: Global OffensiveCounter-Strike 2
Primary attack, first swing 20 (17) 40 (34)
Primary attack, consecutive swing 15 (12) 25 (21)
Primary attack, backstab - 90 (76)
Secondary attack 65 (55) 65 (55)
Secondary attack, backstab 195 (165) 180 (153)

A knife swing is considered a backstab if the angle between the attacked player's orientation and the 2D-vector from the attacking player to the attacked player is cos-1(0.475) ≈ 61.64° or less. This means that the orientation of the attacking player and the z-difference of the players are not regarded in this calculation.

Damage types are always DMG_SLASH and DMG_NEVERGIB.

KeyValues

CS:S / CS:GO / CS2 Weapon:

Ammo (ammo) <integer> (only in Counter-Strike: Source)
Amount of reserve ammo to be added. Fallback value is 0. !FGD
Is this weapon allowed to be picked up? (CanBePickedUp) <boolean> (in all games since Counter-Strike: Global Offensive)
Determines if players are able to pick up the weapon.

Flags

Start Constrained : [1]

Prevents the model from moving.

Inputs

CS:S / CS:GO / CS2 Weapon:

SetAmmoAmount <integer> (in all games since Counter-Strike: Global Offensive)
For guns, sets the number of bullets in the active magazine. Does nothing for grenades.
Counter-Strike: Global Offensive Every value behaves like its congruent value in the range 0-255 in modulus 256 (e.g. -255 and 257 behave like 1 etc.). When set to 0, the owner may start reloading automatically, if possible. Other values congruent to 0 (-256, 256, 512, ...) might cause undefined behavior. Values congruent to -1 (mod 256) make the ammo numbers disappear. If set to a value outside the weapon's clip size, reloading might deliver unexpected results.
Counter-Strike 2 Behaves like SetClipPrimary.
SetReserveAmmoAmount <integer> (in all games since Counter-Strike: Global Offensive)
For guns, sets the number of bullets in reserve for reloading, clamping at the weapon's maximum (e.g. 90 for the weapon_ak47).
For grenades, sets their count, clamping at the current maximum depending on the convars ammo_grenade_limit_*; When setting to 0 or below while holding the grenade, the player no longer owns any, but the viewmodel stays.
Counter-Strike: Global Offensive Negative values make a gun's ammo display disappear and reloading is impossible.
Counter-Strike 2 Negative values are clamped to 0 for guns.
ToggleCanBePickedUp <boolean> (in all games since Counter-Strike: Global Offensive)
Toggles whether the weapon can be picked up by players. Visually, nothing changes and there is no event if picking up fails. Hover texts like "[E] Swap for AK-47" remain in both cases.

SetClipPrimary <integer> (only in Counter-Strike 2)
For guns, sets the number of bullets in the active magazine, clamping between 0 and its clip size; When setting to 0, the owner may start reloading automatically.
Does nothing for grenades.
SetClipSecondary <integer> (only in Counter-Strike 2)
Icon-Bug.pngBug:Does nothing. SetReserveAmmoAmount works.  [todo tested in?]

Outputs

CS:S / CS:GO / CS2 Weapon:

OnPlayerUse
Fires when a player +uses this weapon (!activator is the player.). Does not fire if the weapon is picked up successfully.
OnPlayerPickup
Fires when a player picks this weapon up (!activator is the player.).
OnCacheInteraction  (removed since Counter-Strike 2) !FGD
When dropped, fires every tick on player touch (!activator is the player.).
Counter-Strike: Global Offensive Also fires on successful +use pickup. Does not fire if CanBePickedUp is false.
OnNPCPickup  (removed since Counter-Strike 2) !FGD
Fires when an NPC picks up this weapon (!activator is the NPC). Bots are considered players, so this output has no functionality.
Counter-Strike: Source Hostages might be NPCs, but they don't pick weapons up.