@@ -21,7 +21,9 @@ public class GrenadeThrownData
2121
2222 public float Delay { get ; set ; }
2323
24- public GrenadeThrownData ( Vector nadePosition , QAngle nadeAngle , Vector nadeVelocity , Vector playerPosition , QAngle playerAngle , string grenadeType , DateTime thrownTime )
24+ public UInt16 ItemIndex { get ; set ; }
25+
26+ public GrenadeThrownData ( Vector nadePosition , QAngle nadeAngle , Vector nadeVelocity , Vector playerPosition , QAngle playerAngle , string grenadeType , DateTime thrownTime , UInt16 itemIndex )
2527 {
2628 Position = new Vector ( nadePosition . X , nadePosition . Y , nadePosition . Z ) ;
2729 Angle = new QAngle ( nadeAngle . X , nadeAngle . Y , nadeAngle . Z ) ;
@@ -31,6 +33,7 @@ public GrenadeThrownData(Vector nadePosition, QAngle nadeAngle, Vector nadeVeloc
3133 Type = grenadeType ;
3234 ThrownTime = thrownTime ;
3335 Delay = 0 ;
36+ ItemIndex = itemIndex ;
3437 }
3538
3639 public void LoadPosition ( CCSPlayerController player )
@@ -41,38 +44,86 @@ public void LoadPosition(CCSPlayerController player)
4144
4245 public void Throw ( CCSPlayerController player )
4346 {
44- if ( Type == "smoke" )
45- {
46- SmokeGrenadeProjectile . Create ( Position , Angle , Velocity , player ) ;
47- }
48- else if ( Type == "flash" || Type == "hegrenade" || Type == "decoy" || Type == "molotov" )
49- {
50- var entity = Utilities . CreateEntityByName < CBaseCSGrenadeProjectile > ( Constants . NadeProjectileMap [ Type ] ) ;
51- if ( entity == null )
52- {
53- Console . WriteLine ( $ "[GrenadeThrownData Fatal] Failed to create entity!") ;
54- return ;
55- }
56- if ( Type == "molotov" ) entity . SetModel ( "weapons/models/grenade/incendiary/weapon_incendiarygrenade.vmdl" ) ;
57- entity . Elasticity = 0.33f ;
58- entity . IsLive = false ;
59- entity . DmgRadius = 350.0f ;
60- entity . Damage = 99.0f ;
61- entity . InitialPosition . X = Position . X ;
62- entity . InitialPosition . Y = Position . Y ;
63- entity . InitialPosition . Z = Position . Z ;
64- entity . InitialVelocity . X = Velocity . X ;
65- entity . InitialVelocity . Y = Velocity . Y ;
66- entity . InitialVelocity . Z = Velocity . Z ;
67- entity . Teleport ( Position , Angle , Velocity ) ;
68- entity . DispatchSpawn ( ) ;
69- entity . Globalname = "custom" ;
70- entity . AcceptInput ( "FireUser1" , player , player ) ;
71- entity . AcceptInput ( "InitializeSpawnFromWorld" ) ;
72- entity . TeamNum = player . TeamNum ;
73- entity . Thrower . Raw = player . PlayerPawn . Raw ;
74- entity . OriginalThrower . Raw = player . PlayerPawn . Raw ;
75- entity . OwnerEntity . Raw = player . PlayerPawn . Raw ;
76- }
47+ CBaseCSGrenadeProjectile ? grenadeEntity = null ;
48+ switch ( Type )
49+ {
50+ case "smoke" :
51+ {
52+ grenadeEntity = GrenadeFunctions . CSmokeGrenadeProjectile_CreateFunc . Invoke (
53+ Position . Handle ,
54+ Angle . Handle ,
55+ Velocity . Handle ,
56+ Velocity . Handle ,
57+ IntPtr . Zero ,
58+ ItemIndex ,
59+ ( int ) player . Team ) ;
60+ break ;
61+ }
62+ case "molotov" :
63+ {
64+ grenadeEntity = GrenadeFunctions . CMolotovProjectile_CreateFunc . Invoke (
65+ Position . Handle ,
66+ Angle . Handle ,
67+ Velocity . Handle ,
68+ Velocity . Handle ,
69+ IntPtr . Zero ,
70+ ItemIndex ) ;
71+ break ;
72+ }
73+ case "hegrenade" :
74+ {
75+ grenadeEntity = GrenadeFunctions . CHEGrenadeProjectile_CreateFunc . Invoke (
76+ Position . Handle ,
77+ Angle . Handle ,
78+ Velocity . Handle ,
79+ Velocity . Handle ,
80+ IntPtr . Zero ,
81+ ItemIndex ) ;
82+ break ;
83+ }
84+ case "decoy" :
85+ {
86+ grenadeEntity = GrenadeFunctions . CDecoyProjectile_CreateFunc . Invoke (
87+ Position . Handle ,
88+ Angle . Handle ,
89+ Velocity . Handle ,
90+ Velocity . Handle ,
91+ IntPtr . Zero ,
92+ ItemIndex ) ;
93+ break ;
94+ }
95+ case "flash" :
96+ {
97+ grenadeEntity = Utilities . CreateEntityByName < CFlashbangProjectile > ( "flashbang_projectile" ) ;
98+ if ( grenadeEntity == null ) return ;
99+ grenadeEntity . DispatchSpawn ( ) ;
100+ break ;
101+ }
102+ default :
103+ Console . WriteLine ( $ "[MatchZy] Unknown Grenade: { Type } ") ;
104+ break ;
105+ }
106+
107+ if ( grenadeEntity != null && grenadeEntity . DesignerName != "smokegrenade_projectile" )
108+ {
109+ grenadeEntity . InitialPosition . X = Position . X ;
110+ grenadeEntity . InitialPosition . Y = Position . Y ;
111+ grenadeEntity . InitialPosition . Z = Position . Z ;
112+
113+ grenadeEntity . InitialVelocity . X = Velocity . X ;
114+ grenadeEntity . InitialVelocity . Y = Velocity . Y ;
115+ grenadeEntity . InitialVelocity . Z = Velocity . Z ;
116+
117+ grenadeEntity . AngVelocity . X = Velocity . X ;
118+ grenadeEntity . AngVelocity . Y = Velocity . Y ;
119+ grenadeEntity . AngVelocity . Z = Velocity . Z ;
120+
121+ grenadeEntity . Teleport ( Position , Angle , Velocity ) ;
122+ grenadeEntity . Globalname = "custom" ;
123+ grenadeEntity . TeamNum = player . TeamNum ;
124+ grenadeEntity . Thrower . Raw = player . PlayerPawn . Raw ;
125+ grenadeEntity . OriginalThrower . Raw = player . PlayerPawn . Raw ;
126+ grenadeEntity . OwnerEntity . Raw = player . PlayerPawn . Raw ;
127+ }
77128 }
78129}
0 commit comments