DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
BulletImpactBase.c
Go to the documentation of this file.
2{
3 static const int SURVIVOR_HEAD = 0; // Head component
4 static const int INFECTED_HEAD = 3; // Head component
5 static float DEFAULT_PROJECTILE_WEIGHT = 0.015;
6
7 float MIN_SCALING_PARAM = 0.1;
8
11 float m_Weight; // projectile weight in kg
19 string m_AmmoType;
20
21 static vector INVALID = "0 0 0";
22
23 // Particle Effects
27
28 // Calculations
29 float m_EnterSplashCoef = 0.003;
30 float m_ExitSplashCoef = 0.002;
31 float m_RicochetSplashCoef = 0.002;
33 float m_AngledEnter = 0.40;
34
36 {
37
38 }
39
40 override void OnCheckUpdate()
41 {
42 //DbgUI.Text( m_ammoType );
43 }
44
45 void SetEnterParticle(int id)
46 {
47 m_ParticleEnter = id;
48 }
49
50 void SetExitParticle(int id)
51 {
52 m_ParticleExit = id;
53 }
54
56 {
58 }
59
60 void SetSingleParticle(int id)
61 {
65 }
66
67 void SetAngledEnterValue(float f)
68 {
69 m_AngledEnter = f;
70 }
71
72 void EvaluateEffect(Object directHit, int componentIndex, vector pos, int impact_type, vector surfNormal, vector exitPos, vector inSpeed, vector outSpeed, string ammoType)
73 {
74 m_DirectHit = directHit;
75 m_Pos = pos;
76 m_ImpactType = impact_type;
77 m_ComponentIndex = componentIndex;
78 m_SurfNormal = surfNormal;
79 m_ExitPos = exitPos;
80 m_InSpeed = inSpeed;
81 m_OutSpeed = outSpeed;
82 m_AmmoType = ammoType;
83 m_Weight = GetGame().ConfigGetFloat("CfgAmmo " + ammoType + " weight");
84
86 }
87
88 float CalculateStoppingForce(float in_speedf, float out_speedf, string ammoType, float weight)
89 {
90 if ( m_ImpactType == ImpactTypes.MELEE )
91 {
92 return Math.RandomFloat(50, 100);
93 }
94
95 float projectile_weight_coef = weight / DEFAULT_PROJECTILE_WEIGHT;
96
97 float stopping_force = (in_speedf - out_speedf) * projectile_weight_coef;
98
99 return stopping_force;
100 }
101
103 {
104 // All values represent scale
105 float velocity_min = (m_StoppingForce * m_EnterSplashCoef);
106 float velocity_max = (m_StoppingForce * m_EnterSplashCoef);
107 float size = (m_StoppingForce * m_EnterSplashCoef);
108 float birth_rate = (m_StoppingForce * m_EnterSplashCoef);
109 float air_resistance = velocity_min;
110 float lifetime = (m_StoppingForce * m_EnterSplashCoef);
111 float lifetime_rnd = (m_StoppingForce * m_EnterSplashCoef);
112
113 if ( m_AmmoType == "Bullet_12GaugePellets" )
114 {
115 birth_rate *= 0.5;
116 velocity_min *= 2;
117 velocity_max *= 2;
118 }
119
120
121 if (velocity_min < 0.75)
122 velocity_min = 0.75;
123
124 if (size < 0.75)
125 size = 0.75;
126
127 if (lifetime < 0.5)
128 lifetime = 0.5;
129
130 if (lifetime_rnd < 0.5)
131 lifetime_rnd = 0.5;
132
133 if (velocity_max < 1)
134 velocity_max = 1;
135
136 /*Print("===============");
137 Print(velocity_min);
138 Print(velocity_max);
139 Print(size);
140 Print(birth_rate);
141 Print(air_resistance);
142 Print(lifetime);
143 Print(lifetime_rnd);*/
144
145 p.ScaleParticleParam(EmitorParam.VELOCITY, velocity_min);
146 p.ScaleParticleParam(EmitorParam.VELOCITY_RND, velocity_max);
147 p.ScaleParticleParam(EmitorParam.SIZE, size);
148 p.ScaleParticleParam(EmitorParam.BIRTH_RATE, birth_rate);
149 p.ScaleParticleParam(EmitorParam.AIR_RESISTANCE, air_resistance);
150 p.ScaleParticleParam(EmitorParam.AIR_RESISTANCE_RND, air_resistance);
151 p.ScaleParticleParam(EmitorParam.LIFETIME, lifetime);
152 p.ScaleParticleParam(EmitorParam.LIFETIME_RND, lifetime_rnd);
153 }
154
155 void OnExitCalculations(Particle p, float outSpeedf)
156 {
157 float velocity_min = 1 + (outSpeedf * m_ExitSplashCoef);
158 float velocity_max = 1 + (outSpeedf * m_ExitSplashCoef);
159 float size = 1 + ( outSpeedf * m_ExitSplashCoef);
160 float birth_rate = 1 + (outSpeedf * m_ExitSplashCoef);
161
162 if (velocity_min < MIN_SCALING_PARAM)
163 velocity_min = MIN_SCALING_PARAM;
164
165 if (size < MIN_SCALING_PARAM)
166 size = MIN_SCALING_PARAM;
167
168 if (birth_rate < MIN_SCALING_PARAM)
169 birth_rate = MIN_SCALING_PARAM;
170
171 p.ScaleParticleParam(EmitorParam.VELOCITY, velocity_min);
172 p.ScaleParticleParam(EmitorParam.VELOCITY_RND, velocity_max);
173 p.ScaleParticleParam(EmitorParam.SIZE, size);
174 p.ScaleParticleParam(EmitorParam.BIRTH_RATE, birth_rate);
175 }
176
177 void OnRicochetCalculations(Particle p, float outspeedf)
178 {
179 float velocity_min = MIN_SCALING_PARAM + (m_StoppingForce * m_RicochetSplashCoef);
180 float velocity_max = MIN_SCALING_PARAM + (m_StoppingForce * m_RicochetSplashCoef);
183
184 if (velocity_min < MIN_SCALING_PARAM)
185 velocity_min = MIN_SCALING_PARAM;
186
187 if (size < MIN_SCALING_PARAM)
188 size = MIN_SCALING_PARAM;
189
190 if (birth_rate < MIN_SCALING_PARAM)
191 birth_rate = MIN_SCALING_PARAM;
192
193 p.ScaleParticleParam(EmitorParam.VELOCITY, velocity_min);
194 p.ScaleParticleParam(EmitorParam.VELOCITY_RND, velocity_max);
195 p.ScaleParticleParam(EmitorParam.SIZE, size);
196 p.ScaleParticleParam(EmitorParam.BIRTH_RATE, birth_rate);
197 }
198
200 {
205
206 if (velocity_min < MIN_SCALING_PARAM)
207 velocity_min = MIN_SCALING_PARAM;
208
209 if (size < MIN_SCALING_PARAM)
210 size = MIN_SCALING_PARAM;
211
212 if (birth_rate < MIN_SCALING_PARAM)
213 birth_rate = MIN_SCALING_PARAM;
214
215 p.ScaleParticleParam(EmitorParam.VELOCITY, velocity_min);
216 p.ScaleParticleParam(EmitorParam.VELOCITY_RND, velocity_max);
217 p.ScaleParticleParam(EmitorParam.SIZE, size);
218 p.ScaleParticleParam(EmitorParam.BIRTH_RATE, birth_rate);
219 }
220
221 override void Event_OnStarted()
222 {
223 Particle p;
224 vector particle_orientation;
225 float outSpeedf = m_OutSpeed.Length();
226
227 ParticleManager gPM = ParticleManager.GetInstance();
228
229 if ( m_ImpactType == ImpactTypes.RICOCHET )
230 {
232
233 if (p)
234 {
235 particle_orientation = m_OutSpeed.VectorToAngles();
236 particle_orientation = particle_orientation + "0 -90 0";
237 p.SetOrientation(particle_orientation);
238
239 OnRicochetCalculations(p, outSpeedf);
240 }
241 }
242 else
243 {
245
246 if (p)
247 {
248 if (m_SurfNormal != INVALID)
249 {
250 particle_orientation = m_SurfNormal.VectorToAngles();
251 particle_orientation = particle_orientation + "0 270 0";
252 }
253 else
254 {
255 particle_orientation = "0 0 0"; // This vector is in angles
256 }
257
258 p.SetOrientation(particle_orientation);
259
261 }
262
263 if (outSpeedf > 0 && m_SurfNormal != INVALID)
264 {
266
267 if (p)
268 {
269 particle_orientation = m_OutSpeed.VectorToAngles();
270 particle_orientation = particle_orientation + "0 -90 0";
271 p.SetOrientation(particle_orientation);
272
273 OnExitCalculations(p, outSpeedf);
274 }
275 }
276 else
277 {
278 if (m_SurfNormal != INVALID)
279 {
280 vector surfNormalN = m_SurfNormal.Normalized();
281 vector inSpeedN = m_InSpeed.Normalized();
282 vector bounce_ori = surfNormalN + inSpeedN;
283
284 float dot = vector.Dot(bounce_ori, surfNormalN);
285
286 if ( dot > m_AngledEnter )
287 {
289
290 if (p)
291 {
292 particle_orientation = bounce_ori.VectorToAngles();
293 particle_orientation = particle_orientation + "0 -90 0";
294 p.SetOrientation(particle_orientation);
295
297 }
298 }
299 }
300 }
301 }
302
303 if (p)
304 {
305 SetParticle(p);
306 }
307
308
309 // Additional impact particle over long ranges. It shows players where their bullets land
310
311 if ( Type() != Hit_MeatBones )
312 {
313 vector camera_pos = GetGame().GetCurrentCameraPosition();
314 float distance = vector.Distance(camera_pos, m_Pos);
315
316 // Additional size increase by distance from camera
317 float scaling_by_distance = distance * 0.01;
318
319 // Now scale down the above size increase by player's zoom-in value
320 float current_FOV = Camera.GetCurrentFOV();
321 float config_FOV = GetDayZGame().GetUserFOVFromConfig();
322 float FOV_scale = current_FOV / config_FOV;
323 scaling_by_distance = 1 + scaling_by_distance * FOV_scale;
324
325 if (scaling_by_distance > 1.1)
326 {
328
329 particle_orientation = m_SurfNormal.VectorToAngles();
330 particle_orientation[1] = particle_orientation[1] + 270;
331 p_distant.SetOrientation(particle_orientation);
332
333 p_distant.ScaleParticleParam(EmitorParam.SIZE, scaling_by_distance - 0.5);
334 p_distant.ScaleParticleParam(EmitorParam.BIRTH_RATE, scaling_by_distance * 0.1);
335 p_distant.ScaleParticleParam(EmitorParam.BIRTH_RATE_RND, scaling_by_distance * 0.1);
336 p_distant.ScaleParticleParam(EmitorParam.LIFETIME, scaling_by_distance * 0.3);
337 p_distant.ScaleParticleParam(EmitorParam.LIFETIME_RND, scaling_by_distance * 0.3);
338 }
339 }
340 }
341}
DayZGame GetDayZGame()
Definition DayZGame.c:3656
ImpactTypes
string Type
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
proto native float ConfigGetFloat(string path)
Get float value from config on path.
proto native vector GetCurrentCameraPosition()
void OnEnterCalculations(Particle p)
static float DEFAULT_PROJECTILE_WEIGHT
static const int SURVIVOR_HEAD
static const int INFECTED_HEAD
void OnEnterAngledCalculations(Particle p)
void SetSingleParticle(int id)
override void Event_OnStarted()
void OnExitCalculations(Particle p, float outSpeedf)
void SetExitParticle(int id)
void SetRicochetParticle(int id)
float CalculateStoppingForce(float in_speedf, float out_speedf, string ammoType, float weight)
void SetAngledEnterValue(float f)
void SetEnterParticle(int id)
void EvaluateEffect(Object directHit, int componentIndex, vector pos, int impact_type, vector surfNormal, vector exitPos, vector inSpeed, vector outSpeed, string ammoType)
override void OnCheckUpdate()
void OnRicochetCalculations(Particle p, float outspeedf)
Wrapper class for managing particles through SEffectManager.
void SetParticle(Particle p)
Sets the main particle which this Effect will manage.
Definition EnMath.c:7
Legacy way of using particles in the game.
Definition Particle.c:7
void ScaleParticleParam(int parameter_id, float coef)
Scales the given parameter on all emitors relatively to their CURRENT value.
Definition Particle.c:687
static Particle PlayInWorld(int particle_id, vector global_pos)
Creates a particle emitter on the given position and activates it.
Definition Particle.c:174
static const int IMPACT_DISTANT_DUST
proto vector Normalized()
return normalized vector (keeps orginal vector untouched)
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
proto vector VectorToAngles()
Converts vector to spherical coordinates with radius = 1.
proto native float Length()
Returns length of vector (magnitude)
static float Dot(vector v1, vector v2)
Returns Dot product of vector v1 and vector v2.
Definition EnConvert.c:271
proto native CGame GetGame()
static proto float RandomFloat(float min, float max)
Returns a random float number between and min[inclusive] and max[exclusive].
EmitorParam
Definition EnVisual.c:114