DayZ 1.24
Loading...
Searching...
No Matches
WeaponParticles.c
Go to the documentation of this file.
1/*
2 Author: Boris Vacula
3 For documentation go to: DayZ Confluence -> How-to articles -> Weapon muzzle flash particle system configuration
4 This system plays effect(s) on any weapon that is fired/jammed/ruined/...
5*/
6
7class WeaponParticlesBase // This class represents every particle effect you see in config within OnFire or OnOverheating events
8{
26
27 string m_Name;
28
29 //======================================
30 // PRELOAD EVERYTHING
31 //======================================
32
34 {
36
37 // ignoreIfSuppressed
38 m_IgnoreIfSuppressed = GetGame().ConfigGetFloat(string.Format("%1 ignoreIfSuppressed", m_Name));
39
40 // onlyIfBoltIsOpen
41 m_OnlyIfBoltIsOpen = GetGame().ConfigGetFloat(string.Format("%1 onlyIfBoltIsOpen", m_Name));
42
43 // illuminateWorld
44 m_IlluminateWorld = GetGame().ConfigGetFloat(string.Format("%1 illuminateWorld", m_Name));
45
46 m_MuzzleIndex = -1;
47 if (GetGame().ConfigIsExisting(string.Format("%1 muzzleIndex", m_Name)))
48 m_MuzzleIndex = GetGame().ConfigGetInt(string.Format("%1 muzzleIndex", m_Name));
49
50 // onlyIfWeaponIs
52 GetGame().ConfigGetText(string.Format("%1 onlyIfWeaponIs", m_Name), m_OnlyIfWeaponIs);
53
54 // onlyIfBulletIs
56 GetGame().ConfigGetText(string.Format("%1 onlyIfBulletIs", m_Name), m_OnlyIfBulletIs);
57
58 // onlyWithinHealthLabel[]
60 GetGame().ConfigGetFloatArray(string.Format("%1 onlyWithinHealthLabel", m_Name), health_limit);
61
62 if (health_limit.Count() == 2)
63 {
66 }
67 else
68 {
69 // Disable this filter
72 }
73
74 // onlyWithinOverheatLimits[]
76 GetGame().ConfigGetFloatArray(string.Format("%1 onlyWithinOverheatLimits", m_Name), overheat_limit);
77
78 if (overheat_limit.Count() == 2)
79 {
82 }
83 else
84 {
85 // Disable this filter
88 }
89
90 // onlyWithinRainLimits[]
92 GetGame().ConfigGetFloatArray(string.Format("%1 onlyWithinRainLimits", m_Name), rain_limit);
93
94 if (rain_limit.Count() == 2)
95 {
98 }
99 else
100 {
101 // Disable this filter
104 }
105
106 // overridePoint
107 m_OverridePoint = "";
108 GetGame().ConfigGetText(string.Format("%1 overridePoint", m_Name), m_OverridePoint);
109
110 if (m_OverridePoint == "")
111 m_OverridePoint = "Usti hlavne"; // default memory point name
112
113 // overrideParticle
114 string particle_name = "";
115 GetGame().ConfigGetText(string.Format("%1 overrideParticle", m_Name), particle_name);
116
117 if (particle_name != "")
119 else
120 {
122 ErrorEx(string.Format("'%1' does not contain a definition for 'overrideparticle'",
124 }
125
126 // overrideDirectionPoint
128 GetGame().ConfigGetText(string.Format("%1 overrideDirectionPoint", m_Name), m_OverrideDirectionPoint);
129
130 if (m_OverrideDirectionPoint == "")
131 {
132 // overrideDirectionVector
133 vector test_ori = GetGame().ConfigGetVector(string.Format("%1 overrideDirectionVector", m_Name));
134
135 if (test_ori != vector.Zero)
137 }
138
139 // positionOffset[]
141 GetGame().ConfigGetFloatArray(string.Format("%1 positionOffset", m_Name), v);
142
143 if (v.Count() == 3)
144 {
145 float v1 = v.Get(0);
146 float v2 = v.Get(1);
147 float v3 = v.Get(2);
149 }
150 }
151
152
153 //======================================
154 // PLAY PARTICLES
155 //======================================
156 // It is important to know that this block of script is called for weapons and muzzle attachments alike.
157 // Thus weapon == muzzle_owner when this is called for a weapon, and weapon != muzzle_owner when this is called for a suppressor.
159 {
160 if (!GetGame().IsServer() || !GetGame().IsMultiplayer())
161 {
162 // Handle effect's parameters
163 if (PrtTest.m_GunParticlesState) // Check if particles are enabled by debug
164 {
166 {
167 if (CheckBoltStateCondition(weapon)) // onlyIfBoltIsOpen
168 {
169 if (!suppressor || suppressor.IsRuined() || !(m_IgnoreIfSuppressed)) // ignoreIfSuppressed
170 {
171 if (CheckHealthCondition(muzzle_owner.GetHealthLevel())) // onlyWithinHealthLabel
172 {
173 if (CheckOverheatingCondition(muzzle_owner.GetOverheatingCoef())) // onlyWithinOverheatLimits
174 {
175 if (CheckRainCondition(GetGame().GetWeather().GetRain().GetActual())) // onlyWithinRainLimits
176 {
177 if (m_OnlyIfBulletIs == "" || m_OnlyIfBulletIs == ammoType) // onlyIfBulletIs
178 {
179 if (m_OnlyIfWeaponIs == "" || m_OnlyIfWeaponIs == weapon.GetType()) // onlyIfWeaponIs
180 {
181 // Get particle ID
183
185 {
186 // Get position of the particle
187 vector local_pos = muzzle_owner.GetSelectionPositionLS(m_OverridePoint);
189
190 // Set orientation of the particle
192
193 // Create particle
196 }
197 else
198 ErrorEx(string.Format("No valid particle found for: '%1'", m_Name));
199
200 // Create light
202 {
203 vector global_pos = muzzle_owner.ModelToWorld(local_pos + Vector(-0.2, 0, 0));
204 int randX = Math.RandomInt(0, 10);
205 if (randX > 8)
206 ScriptedLightBase.CreateLight(MuzzleFlashLight_2, global_pos);
207 else if (randX > 4)
209 else
210 ScriptedLightBase.CreateLight(MuzzleFlashLight, global_pos);
211 }
212 }
213 }
214 }
215 }
216 }
217 }
218 }
219 }
220 }
221 }
222 }
223
228
233
238
239
240 //==============================================
241 // HANDLE CONFIG PARAMETERS
242 //==============================================
243
244
245 // OnlyWithinHealthLabelMin & OnlyWithinHealthLabelMax
247 {
249 {
251 WeaponStateBase current_state = wb.GetCurrentState();
252 return current_state.IsBoltOpen();
253 }
254
255 return true;
256 }
257
258 // OnlyWithinHealthLabelMin & OnlyWithinHealthLabelMax
263
264 // OnlyWithinOverheatLimitsMin & OnlyWithinOverheatLimitsMax
269
270 // OnlyWithinRainLimitsMin & OnlyWithinRainLimitsMax
275
276 // muzzleFlashParticle
278 {
279 int particle_id = -1;
280
281 string particle_file = "";
282 string cfg_path = "CfgAmmo " + ammoType + " muzzleFlashParticle";
283 if (GetGame().ConfigGetText(cfg_path, particle_file))
285
286 // Config is accessed only once because the data is saved into a map for repeated access.
287
288 if (particle_id > 0 || m_OverrideParticle == -1)
289 {
290 if (particle_file == "")
291 ErrorEx(string.Format("Cannot spawn particle effect because item %1 is missing config parameter muzzleFlashParticle!", ammoType), ErrorExSeverity.INFO);
292 else
293 {
295
296 if (particle_id == 0)
297 {
298 string devStr;
299#ifdef DEVELOPER
300 devStr = " Make sure it's registered there and then rebuild Scripts and Graphics PBOs.";
301#endif
302 ErrorEx(string.Format("Cannot play particle effect with name %1 because no such file is registered in ParticleList.c!%2", particle_file, devStr));
303 m_OverrideParticle = particle_id; // Prevents another appearence of the above error.
304 }
305 }
306 }
307 else
309
310 return particle_id;
311 }
312
313 // OverrideDirectionPoint & OverrideDirectionVector
315 {
316 vector particle_ori = "0 0 0";
317 if (m_OverrideDirectionPoint != "")
318 {
319 vector target_pos = muzzle_owner.GetSelectionPositionLS(m_OverrideDirectionPoint);
321 particle_ori = target_pos.VectorToAngles();
322 }
323 else
324 {
325 if (m_OverrideDirectionVector != Vector(0, 0, 0))
327
328 if (muzzle_owner.IsInherited(ItemSuppressor))
329 {
330 particle_ori = particle_ori + Vector(0, 0, 270); // This rotation is necesarry due to suppressors being rotated into ground in their p3d files
331 }
332 }
333
334 return particle_ori;
335 }
336}
337
338// FIRE particles
340
341// BULLET EJECT particles
343
344// OVERHEATING particles
346{
349 muzzle_owner.RegisterOverheatingParticle(p, m_OnlyWithinOverheatLimitsMin, m_OnlyWithinOverheatLimitsMax, p.GetParticleID(), muzzle_owner, p.m_DefaultPos, p.m_DefaultOri);
354 if (!GetGame().IsServer() || !GetGame().IsMultiplayer())
355 weapon.KillAllOverheatingParticles();
365{
371
374
376 {
377 m_Particle = p;
378 }
379
381 {
382 return m_Particle;
383 }
384
386 {
388 }
389
391 {
393 }
394
396 {
398 }
399
401 {
403 }
404
412
414 {
415 return m_ParticleID;
416 }
417
419 {
420 return m_Parent;
421 }
422
424 {
425 return m_LocalPos;
426 }
427
429 {
430 return m_LocalOri;
431 }
432}
void MuzzleFlashLight_1()
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
int particle_id
float m_OnlyWithinOverheatLimitsMin
class WeaponParticlesBase OnParticleCreated(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search, Particle p)
float m_OnlyWithinOverheatLimitsMax
Definition EnMath.c:7
void SetOverheatingLimitMax(float max)
void SetParticleParams(int particle_id, Object parent, vector local_pos, vector local_ori)
void SetOverheatingLimitMin(float min)
void RegisterParticle(Particle p)
Legacy way of using particles in the game.
Definition Particle.c:7
static int GetParticleIDByName(string name)
Returns particle's ID based on the filename (without .ptc suffix)
static bool IsValidId(int id)
Purely checks for an invalid number, does NOT mean it is actually registered.
static bool m_GunParticlesState
Definition gameplay.c:1478
void WeaponParticlesBase(ItemBase muzzle_owner, string config_OnFire_entry)
bool CheckRainCondition(float rain_coef)
void OnDeactivate(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search)
bool CheckHealthCondition(int health_label)
void OnUpdate(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search)
vector CheckOrientationOverride(vector local_pos, ItemBase muzzle_owner)
bool CheckOverheatingCondition(float overheating_coef)
int CheckParticleOverride(string ammoType)
void OnParticleCreated(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search, Particle p)
bool CheckBoltStateCondition(ItemBase weapon)
void OnActivate(ItemBase weapon, int muzzle_index, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search)
represent weapon state base
Definition BulletHide.c:2
static const vector Zero
Definition EnConvert.c:110
static vector Direction(vector p1, vector p2)
Returns direction vector from point p1 to point p2.
Definition EnConvert.c:220
proto native CGame GetGame()
ErrorExSeverity
Definition EnDebug.c:62
enum ShapeType ErrorEx
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static proto int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].
proto native void OnUpdate()
Definition tools.c:333
void OnDeactivate()
called when command ends
Definition human.c:1170
class HumanMovementState OnActivate()
HumanCommandScript fully scriptable command.
Definition human.c:1167