1
- using CounterStrikeSharp . API ;
1
+ using CounterStrikeSharp . API ;
2
2
using CounterStrikeSharp . API . Core ;
3
+ using CounterStrikeSharp . API . Modules . Entities ;
3
4
using CounterStrikeSharp . API . Modules . Memory ;
4
5
using CounterStrikeSharp . API . Modules . Utils ;
5
6
using System . Runtime . InteropServices ;
@@ -80,50 +81,67 @@ public static void OnEntityCreated(CEntityInstance entity)
80
81
return ;
81
82
}
82
83
83
- CBasePlayerWeapon weapon = entity . As < CBasePlayerWeapon > ( ) ;
84
-
85
84
Server . NextWorldUpdate ( ( ) =>
86
85
{
87
- if ( weapon . OriginalOwnerXuidLow == 0 )
88
- {
89
- return ;
90
- }
86
+ var weapon = new CBasePlayerWeapon ( entity . Handle ) ;
87
+
88
+ if ( ! weapon . IsValid ) return ;
89
+
90
+ if ( weapon . OriginalOwnerXuidLow <= 0 ) return ;
91
91
92
- CCSPlayerController ? player = Utilities . GetPlayerFromSteamId ( weapon . OriginalOwnerXuidLow ) ;
92
+ SteamID ? _steamid = null ;
93
93
94
- if ( player == null )
95
- {
96
- return ;
97
- }
94
+ if ( weapon . OriginalOwnerXuidLow > 0 )
95
+ _steamid = new ( weapon . OriginalOwnerXuidLow ) ;
98
96
99
- Store_Equipment ? playerequipment = Item . GetPlayerEquipments ( player ) . FirstOrDefault ( p => p . SteamID == player . SteamID && p . Type == "customweapon" ) ;
97
+ CCSPlayerController ? player = null ;
100
98
101
- if ( playerequipment == null )
99
+ if ( _steamid != null && _steamid . IsValid ( ) )
102
100
{
103
- return ;
104
- }
101
+ player = Utilities . GetPlayers ( ) . FirstOrDefault ( p => p . IsValid && p . SteamID == _steamid . SteamId64 ) ;
105
102
106
- Dictionary < string , string > ? itemdata = Item . GetItem ( playerequipment . Type , playerequipment . UniqueId ) ;
107
-
108
- if ( itemdata == null )
109
- {
110
- return ;
103
+ if ( player == null )
104
+ player = Utilities . GetPlayerFromSteamId ( weapon . OriginalOwnerXuidLow ) ;
111
105
}
112
-
113
- if ( ! weapon . DesignerName . Contains ( itemdata [ "weapon" ] ) )
106
+ else
114
107
{
115
- return ;
108
+ CCSWeaponBaseGun gun = weapon . As < CCSWeaponBaseGun > ( ) ;
109
+ player = Utilities . GetPlayerFromIndex ( ( int ) weapon . OwnerEntity . Index ) ?? Utilities . GetPlayerFromIndex ( ( int ) gun . OwnerEntity . Value ! . Index ) ;
116
110
}
117
111
118
- CBasePlayerWeapon ? activeweapon = player . PlayerPawn . Value ? . WeaponServices ? . ActiveWeapon . Value ;
112
+ if ( string . IsNullOrEmpty ( player ? . PlayerName ) ) return ;
119
113
120
- if ( activeweapon != null && weapon == activeweapon )
121
- {
122
- Weapon . UpdateModel ( player , activeweapon , itemdata [ "uniqueid" ] , true ) ;
123
- }
124
- else
114
+ var playerequipments = Item . GetPlayerEquipments ( player ) . Where ( p => p . SteamID == player . SteamID && p . Type == "customweapon" ) . ToList ( ) ;
115
+
116
+ foreach ( var playerequipment in playerequipments )
125
117
{
126
- Weapon . UpdateModel ( player , weapon , itemdata [ "uniqueid" ] , false ) ;
118
+ Dictionary < string , string > ? itemdata = Item . GetItem ( playerequipment . Type , playerequipment . UniqueId ) ;
119
+
120
+ if ( itemdata == null ) continue ;
121
+
122
+ string classname = weapon . DesignerName ;
123
+
124
+ if ( classname . Contains ( "bayonet" ) )
125
+ {
126
+ classname = "weapon_knife" ;
127
+ }
128
+
129
+ if ( ! classname . Contains ( itemdata [ "weapon" ] ) )
130
+ {
131
+ continue ;
132
+ }
133
+
134
+ CBasePlayerWeapon ? activeweapon = player . PlayerPawn . Value ? . WeaponServices ? . ActiveWeapon . Value ;
135
+
136
+ if ( activeweapon != null && weapon == activeweapon )
137
+ {
138
+ Weapon . UpdateModel ( player , activeweapon , itemdata [ "uniqueid" ] , true ) ;
139
+ }
140
+ else
141
+ {
142
+ Weapon . UpdateModel ( player , weapon , itemdata [ "uniqueid" ] , false ) ;
143
+ }
144
+ break ;
127
145
}
128
146
} ) ;
129
147
}
@@ -204,4 +222,4 @@ public static void ResetWeapon(CCSPlayerController player, CBasePlayerWeapon wea
204
222
SetViewModel ( player , globalnamedata [ 0 ] ) ;
205
223
}
206
224
}
207
- }
225
+ }
0 commit comments