File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -894,7 +894,43 @@ 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 (
902+ owner * common.Player
903+ oldOwnerMoney int
904+ lastMoneyUpdateTick int
905+ lastMoneyIncreased bool
906+ )
907+
908+ entity .Property ("m_hOwnerEntity" ).OnUpdate (func (val st.PropertyValue ) {
909+ weaponOwner := p .GameState ().Participants ().FindByPawnHandle (val .Handle ())
910+ if weaponOwner == nil {
911+ return
912+ }
913+
914+ owner = weaponOwner
915+ oldOwnerMoney = owner .Money ()
916+
917+ owner .Entity .Property ("m_pInGameMoneyServices.m_iAccount" ).OnUpdate (func (val st.PropertyValue ) {
918+ lastMoneyUpdateTick = p .gameState .ingameTick
919+ currentMoney := owner .Money ()
920+ lastMoneyIncreased = currentMoney > oldOwnerMoney
921+ oldOwnerMoney = currentMoney
922+ })
923+ })
924+
897925 entity .OnDestroy (func () {
926+ if owner != nil && owner .IsInBuyZone () && p .GameState ().IngameTick () == lastMoneyUpdateTick && lastMoneyIncreased {
927+ p .eventDispatcher .Dispatch (events.ItemRefund {
928+ Player : owner ,
929+ Weapon : equipment ,
930+ })
931+ }
932+
933+ lastMoneyIncreased = false
898934 delete (p .gameState .weapons , entityID )
899935 })
900936
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