@@ -274,7 +274,7 @@ type Equipment struct {
274274 Weapon EquipmentElement // The type of weapon which the equipment instantiates.
275275 Owner * Player // The player carrying the equipment, not necessarily the buyer.
276276 AmmoType int // TODO: Remove this? doesn't seem applicable to CS:GO
277- AmmoInMagazine int // Amount of bullets in the weapon's magazine
277+ AmmoInMagazine int // Amount of bullets in the weapon's magazine. Deprecated, use AmmoInMagazine2() instead.
278278 AmmoReserve int // Amount of reserve bullets
279279 OriginalString string // E.g. 'models/weapons/w_rif_m4a1_s.mdl'. Used internally to differentiate alternative weapons (M4A4 / M4A1-S etc.).
280280 ZoomLevel int // How far the player has zoomed in on the weapon. 0=no zoom, 1=first level, 2=maximum zoom
@@ -295,6 +295,32 @@ func (e Equipment) UniqueID() int64 {
295295 return e .uniqueID
296296}
297297
298+ // AmmoInMagazine2 returns the ammo left in the magazine.
299+ // Returns CWeaponCSBase.m_iClip1 for most weapons and 1 for grenades.
300+ func (e Equipment ) AmmoInMagazine2 () int {
301+ if e .Class () == EqClassGrenade {
302+ return 1
303+ }
304+
305+ return e .AmmoInMagazine
306+ }
307+
308+ // AmmoReserve2 returns the ammo left available for reloading.
309+ // Returns CWeaponCSBase.m_iPrimaryReserveAmmoCount for most weapons and 'Owner.AmmoLeft[AmmoType] - 1' for grenades.
310+ // Use AmmoInMagazine2() + AmmoReserve2() to quickly get the amount of grenades a player owns.
311+ func (e Equipment ) AmmoReserve2 () int {
312+ if e .Class () == EqClassGrenade {
313+ if e .Owner != nil {
314+ // minus one for 'InMagazine'
315+ return e .Owner .AmmoLeft [e .AmmoType ] - 1
316+ }
317+
318+ return 0
319+ }
320+
321+ return e .AmmoReserve
322+ }
323+
298324// NewEquipment creates a new Equipment and sets the UniqueID.
299325//
300326// Intended for internal use only.
0 commit comments