File tree Expand file tree Collapse file tree 3 files changed +14
-5
lines changed Expand file tree Collapse file tree 3 files changed +14
-5
lines changed Original file line number Diff line number Diff line change @@ -51,7 +51,6 @@ type Player struct {
5151 RoundStartEquipmentValue int
5252 ActiveWeaponID int
5353 RawWeapons map [int ]* Equipment
54- Weapons []* Equipment
5554 AmmoLeft [32 ]int
5655 Entity * st.Entity
5756 AdditionalPlayerInformation * AdditionalPlayerInformation
@@ -77,6 +76,15 @@ func (p *Player) ActiveWeapon() *Equipment {
7776 return p .RawWeapons [p .ActiveWeaponID ]
7877}
7978
79+ // Weapons returns all weapons in the player's possession
80+ func (p * Player ) Weapons () []* Equipment {
81+ res := make ([]* Equipment , 0 , len (p .RawWeapons ))
82+ for _ , w := range p .RawWeapons {
83+ res = append (res , w )
84+ }
85+ return res
86+ }
87+
8088// AdditionalPlayerInformation contains mostly scoreboard information.
8189type AdditionalPlayerInformation struct {
8290 Kills int
Original file line number Diff line number Diff line change @@ -263,7 +263,7 @@ func (p *Parser) bindNewPlayer(playerEntity *st.Entity) {
263263 if entityID != indexMask {
264264 if cache [i2 ] != 0 {
265265 // Player already has a weapon in this slot.
266- pl.RawWeapons [ cache [i2 ]] = nil
266+ delete ( pl .RawWeapons , cache [i2 ])
267267 }
268268 cache [i2 ] = entityID
269269
@@ -275,9 +275,10 @@ func (p *Parser) bindNewPlayer(playerEntity *st.Entity) {
275275 if cache [i2 ] != 0 && pl.RawWeapons [cache [i2 ]] != nil {
276276 pl.RawWeapons [cache [i2 ]].Owner = nil
277277 }
278- pl.RawWeapons [cache [i2 ]] = nil
278+ delete (pl .RawWeapons , cache [i2 ])
279+
280+ cache [i2 ] = 0
279281 }
280- cache [i2 ] = 0
281282 })
282283 }
283284
Original file line number Diff line number Diff line change @@ -437,7 +437,7 @@ func (p *Parser) handleGameEvent(ge *msg.CSVCMsg_GameEvent) {
437437func getAttackingWeapon (wep * common.Equipment , attacker * common.Player ) * common.Equipment {
438438 class := wep .Class ()
439439 isSpecialWeapon := class == common .EqClassGrenade || (class == common .EqClassEquipment && wep .Weapon != common .EqKnife )
440- if ! isSpecialWeapon && attacker != nil && len (attacker .Weapons ) > 0 {
440+ if ! isSpecialWeapon && attacker != nil && len (attacker .RawWeapons ) > 0 {
441441 return attacker .ActiveWeapon ()
442442 } else {
443443 return wep
You can’t perform that action at this time.
0 commit comments