File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -894,7 +894,41 @@ func (p *parser) bindWeaponS2(entity st.Entity) {
894894
895895 equipment .Entity = entity
896896
897+ // Used to detect when a player has been refunded for a weapon
898+ // This happens when:
899+ // - The player is inside the buy zone
900+ // - The player's money has increased AND the weapon entity is destroyed at the same tick (unfortunately the money is updated first)
901+ var owner * common.Player
902+ var oldOwnerMoney int
903+ var lastMoneyUpdateTick int
904+ var lastMoneyIncreased bool
905+
906+ entity .Property ("m_hOwnerEntity" ).OnUpdate (func (val st.PropertyValue ) {
907+ weaponOwner := p .GameState ().Participants ().FindByPawnHandle (val .Handle ())
908+ if weaponOwner == nil {
909+ return
910+ }
911+
912+ owner = weaponOwner
913+ oldOwnerMoney = owner .Money ()
914+
915+ owner .Entity .Property ("m_pInGameMoneyServices.m_iAccount" ).OnUpdate (func (val st.PropertyValue ) {
916+ lastMoneyUpdateTick = p .gameState .ingameTick
917+ currentMoney := owner .Money ()
918+ lastMoneyIncreased = currentMoney > oldOwnerMoney
919+ oldOwnerMoney = currentMoney
920+ })
921+ })
922+
897923 entity .OnDestroy (func () {
924+ if owner != nil && owner .IsInBuyZone () && p .GameState ().IngameTick () == lastMoneyUpdateTick && lastMoneyIncreased {
925+ p .eventDispatcher .Dispatch (events.ItemRefund {
926+ Player : owner ,
927+ Weapon : equipment ,
928+ })
929+ }
930+
931+ lastMoneyIncreased = false
898932 delete (p .gameState .weapons , entityID )
899933 })
900934
Original file line number Diff line number Diff line change @@ -659,3 +659,10 @@ type OvertimeNumberChanged struct {
659659 OldCount int
660660 NewCount int
661661}
662+
663+ // ItemRefund signals a player was refunded for an item.
664+ // Available with CS2 demos only.
665+ type ItemRefund struct {
666+ Player * common.Player
667+ Weapon * common.Equipment
668+ }
You can’t perform that action at this time.
0 commit comments