Skip to main content

c_base_combat_weapon

Represents a combat weapon in CS:GO. Provides access to weapon state, timing, ammunition, and accuracy calculations. Source: game/sdk/classes/c_base_combat_weapon.h:10 Inherits: c_base_entity

Network Variables

next_primary_attack
float
Server time when the weapon can fire its next primary attackNetvar: CBaseCombatWeapon::m_flNextPrimaryAttack
float time_until_fire = weapon->next_primary_attack() - g_interfaces.global_vars->cur_time;
next_secondary_attack
float
Server time when the weapon can fire its next secondary attackNetvar: CBaseCombatWeapon::m_flNextSecondaryAttack
clip_mag
std::int32_t
Current ammunition in the weapon’s magazine/clipNetvar: CBaseCombatWeapon::m_iClip1
int bullets_remaining = weapon->clip_mag();
clip_reserve
std::int32_t
Reserve ammunition count for primary fireNetvar: CBaseCombatWeapon::m_iPrimaryReserveAmmoCount
view_model_index
std::int32_t
Model index for the first-person view modelNetvar: CBaseCombatWeapon::m_iViewModelIndex
world_model_index
std::int32_t
Model index for the third-person world modelNetvar: CBaseCombatWeapon::m_iWorldModelIndex
world_dropped_model_index
std::int32_t
Model index when weapon is dropped in the worldNetvar: CBaseCombatWeapon::m_iWorldDroppedModelIndex
postpone_fire_ready_time
float
Time when postponed fire will be readyNetvar: CBaseCombatWeapon::m_flPostponeFireReadyTime
world_view_model
std::uintptr_t
Handle to the weapon’s world view model entityNetvar: CBaseCombatWeapon::m_hWeaponWorldModel
definition_index
short
Weapon definition index (identifies weapon type)Netvar: CBaseAttributableItem::m_iItemDefinitionIndex
short weapon_id = weapon->definition_index();
// Compare with weapon IDs (7 = AK-47, 4 = Glock, etc.)

Methods

get_weapon_data
sdk::weapon_data_t*
Retrieves the weapon’s static data including damage, range, and accuracy valuesReturns: Pointer to weapon data structure, or nullptr if unavailableVirtual Index: 461
auto data = weapon->get_weapon_data();
if (data) {
    float damage = data->damage;
    float range = data->range;
}
inaccuracy
float
Calculates current weapon inaccuracy value based on movement, stance, and other factorsReturns: Inaccuracy value (higher = less accurate)Virtual Index: 483
float current_inaccuracy = weapon->inaccuracy();
spread
float
Calculates current weapon spread valueReturns: Spread valueVirtual Index: 453
float current_spread = weapon->spread();
spread_vector
math::vec3
Generates a random spread vector for bullet trajectory calculationParameters:
  • seed - Random seed for reproducibility
  • inaccuracy - Inaccuracy value
  • spread - Spread value
Returns: 3D vector representing spread offsetThis method uses the weapon’s bullet count from weapon data and generates a randomized spread pattern using sine/cosine calculations.
float inaccuracy = weapon->inaccuracy();
float spread = weapon->spread();
math::vec3 spread_vec = weapon->spread_vector(cmd->random_seed, inaccuracy, spread);

// Apply to aim angle
math::vec3 aim_direction = forward + right * spread_vec.x + up * spread_vec.y;
can_shoot_primary
bool
Checks if the weapon can fire primary attackReturns: true if primary fire is available
Implementation defined externally
can_shoot_secondary
bool
Checks if the weapon can fire secondary attackReturns: true if secondary fire is available
Implementation defined externally

weapon_data_t

Static weapon configuration data structure. Source: game/sdk/structs/weapon_data_t.h

Common Fields

damage
int
Base damage dealt by the weapon
bullets
int
Number of bullets fired per shot (typically 1, or 9 for shotguns)
range
float
Maximum effective range of the weapon
range_modifier
float
Damage falloff modifier over distance
penetration
float
Penetration power through surfaces

Usage Examples

Check if weapon can fire

auto weapon = player->active_weapon();
if (!weapon) return;

float server_time = player->tick_base() * g_interfaces.global_vars->interval_per_tick;
float next_attack = weapon->next_primary_attack();

if (server_time >= next_attack) {
    // Weapon is ready to fire
    if (weapon->clip_mag() > 0) {
        // Has ammunition
    }
}

Calculate weapon accuracy

auto weapon = player->active_weapon();
if (!weapon) return;

float inaccuracy = weapon->inaccuracy();
float spread = weapon->spread();
float total_spread = inaccuracy + spread;

if (total_spread < 0.01f) {
    // Weapon is very accurate
}

Get weapon information

auto weapon = player->active_weapon();
if (!weapon) return;

auto data = weapon->get_weapon_data();
if (data && data->bullets > 0) {
    int clip = weapon->clip_mag();
    int reserve = weapon->clip_reserve();
    short weapon_id = weapon->definition_index();
    
    // Use weapon information
}
Always validate weapon pointers and weapon data before accessing properties. Weapon data can be nullptr for invalid or uninitialized weapons.

Build docs developers (and LLMs) love