Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CS2: Randomly missing WeaponInstance.Entity on grenades #580

Open
dankotov opened this issue Feb 25, 2025 · 0 comments
Open

CS2: Randomly missing WeaponInstance.Entity on grenades #580

dankotov opened this issue Feb 25, 2025 · 0 comments

Comments

@dankotov
Copy link

dankotov commented Feb 25, 2025

Describe the bug
Occasionally (about 10% from my testitng) grenades will have WeaponInstance.Entity as nil when retrieved inside event handler functions for events like WeaponFire or GrenadeProjectileThrown.

In WeaponFire events, this only happens to grenade weapons.

To Reproduce
Demos from any of the following, but not limited to matches:
https://www.hltv.org/matches/2378899/vitality-vs-faze-iem-katowice-2025
https://www.hltv.org/matches/2378897/eternal-fire-vs-virtuspro-iem-katowice-2025
https://www.hltv.org/matches/2378898/falcons-vs-g2-iem-katowice-2025

Code:

func main() {
  // ...
  p.RegisterEventHandler(func(e events.GrenadeProjectileThrow) {
    if e.Projectile.WeaponInstance.Entity == nil {
        fmt.Println("Missing Entity")
    }
  })
  // ...
}

Expected behavior
Every nade should have a corresponding WeaponInstance.Entity.

Library version
v4.3.3

Additional context
I have also observed, that for all of the nades in these demos, where WeaponInstance.Entity is missing, WeaponInstance.Owner is also missing.

I have also tested with the code below to confirm that the cause of this issue is not that those entities are destroyed when a grenade is thrown.

func main() {
  // ...
  lastNonNilWeaponEntities := make(map[ulid.ULID]st.Entity)
  
  p.RegisterEventHandler(func(e events.FrameDone) {
    for _, player := range p.GameState().Participants().Playing() {
      for _, weapon := range player.Weapons() {
        ent := weapon.Entity
        if ent == nil {
          continue
        }
        lastNonNilWeaponEntities[weapon.UniqueID2()] = weapon.Entity 
      }
    }
  })
  
  p.RegisterEventHandler(func(e events.GrenadeProjectileThrow) {
    projectileWeaponInstanceId := e.Projectile.WeaponInstance.UniqueID2()
    projectileWeaponInstanceEntity := lastNonNilWeaponEntities[projectileWeaponInstanceId]
    if projectileWeaponInstanceEntity == nil {
      fmt.Println("Missing Entity")
      return
    }
  })
 // ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants