DayZ 1.29
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
WeaponParticles.c
См. документацию.
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
33 void WeaponParticlesBase(ItemBase muzzle_owner, string config_OnFire_entry)
34 {
35 m_Name = config_OnFire_entry;
36
37 // ignoreIfSuppressed
38 m_IgnoreIfSuppressed = g_Game.ConfigGetFloat(string.Format("%1 ignoreIfSuppressed", m_Name));
39
40 // onlyIfBoltIsOpen
41 m_OnlyIfBoltIsOpen = g_Game.ConfigGetFloat(string.Format("%1 onlyIfBoltIsOpen", m_Name));
42
43 // illuminateWorld
44 m_IlluminateWorld = g_Game.ConfigGetFloat(string.Format("%1 illuminateWorld", m_Name));
45
46 m_MuzzleIndex = -1;
47 if (g_Game.ConfigIsExisting(string.Format("%1 muzzleIndex", m_Name)))
48 {
49 m_MuzzleIndex = g_Game.ConfigGetInt(string.Format("%1 muzzleIndex", m_Name));
50 }
51
52 // onlyIfWeaponIs
54 g_Game.ConfigGetText(string.Format("%1 onlyIfWeaponIs", m_Name), m_OnlyIfWeaponIs);
55
56 // onlyIfBulletIs
58 g_Game.ConfigGetText(string.Format("%1 onlyIfBulletIs", m_Name), m_OnlyIfBulletIs);
59
60 // onlyWithinHealthLabel[]
61 array<float> health_limit = new array<float>;
62 g_Game.ConfigGetFloatArray(string.Format("%1 onlyWithinHealthLabel", m_Name), health_limit);
63
64 if (health_limit.Count() == 2)
65 {
66 m_OnlyWithinHealthLabelMin = health_limit.Get(0);
67 m_OnlyWithinHealthLabelMax = health_limit.Get(1);
68 }
69 else
70 {
71 // Disable this filter
74 }
75
76 // onlyWithinOverheatLimits[]
77 array<float> overheat_limit = new array<float>;
78 g_Game.ConfigGetFloatArray(string.Format("%1 onlyWithinOverheatLimits", m_Name), overheat_limit);
79
80 if (overheat_limit.Count() == 2)
81 {
82 m_OnlyWithinOverheatLimitsMin = overheat_limit.Get(0);
83 m_OnlyWithinOverheatLimitsMax = overheat_limit.Get(1);
84 }
85 else
86 {
87 // Disable this filter
90 }
91
92 // onlyWithinRainLimits[]
93 array<float> rain_limit = new array<float>;
94 g_Game.ConfigGetFloatArray(string.Format("%1 onlyWithinRainLimits", m_Name), rain_limit);
95
96 if (rain_limit.Count() == 2)
97 {
98 m_OnlyWithinRainLimitsMin = rain_limit.Get(0);
99 m_OnlyWithinRainLimitsMax = rain_limit.Get(1);
100 }
101 else
102 {
103 // Disable this filter
106 }
107
108 // overridePoint
109 m_OverridePoint = "";
110 g_Game.ConfigGetText(string.Format("%1 overridePoint", m_Name), m_OverridePoint);
111
112 if (m_OverridePoint == "")
113 m_OverridePoint = "Usti hlavne"; // default memory point name
114
115 // overrideParticle
116 string particle_name = "";
117 g_Game.ConfigGetText( string.Format("%1 overrideParticle", m_Name), particle_name);
118
119 if (particle_name != "")
120 {
122 }
123 else
124 {
126 ErrorEx(string.Format("'%1' does not contain a definition for 'overrideparticle'",
127 config_OnFire_entry), ErrorExSeverity.INFO);
128 }
129
130 // overrideDirectionPoint
132 g_Game.ConfigGetText(string.Format("%1 overrideDirectionPoint", m_Name), m_OverrideDirectionPoint);
133
134 if (m_OverrideDirectionPoint == "")
135 {
136 // overrideDirectionVector
137 vector test_ori = g_Game.ConfigGetVector(string.Format("%1 overrideDirectionVector", m_Name));
138
139 if (test_ori != vector.Zero)
140 {
141 m_OverrideDirectionVector = test_ori;
142 }
143 }
144
145 // positionOffset[]
147 g_Game.ConfigGetFloatArray(string.Format("%1 positionOffset", m_Name), v);
148
149 if (v.Count() == 3)
150 {
151 float v1 = v.Get(0);
152 float v2 = v.Get(1);
153 float v3 = v.Get(2);
154 m_PositionOffset = Vector(v1, v2, v3);
155 }
156 }
157
158
159
160 //======================================
161 // PLAY PARTICLES
162 //======================================
163 // It is important to know that this block of script is called for weapons and muzzle attachments alike.
164 // Thus weapon == muzzle_owner when this is called for a weapon, and weapon != muzzle_owner when this is called for a suppressor.
165 void OnActivate(ItemBase weapon, int muzzle_index, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search)
166 {
167 if ( !g_Game.IsServer() || !g_Game.IsMultiplayer() )
168 {
169 // Handle effect's parameters
170 if ( PrtTest.m_GunParticlesState ) // Check if particles are enabled by debug
171 {
172 if ( m_MuzzleIndex == -1 || m_MuzzleIndex == muzzle_index )
173 {
174 if ( CheckBoltStateCondition(weapon) ) // onlyIfBoltIsOpen
175 {
176 if ( !suppressor || suppressor.IsRuined() || !(m_IgnoreIfSuppressed) ) // ignoreIfSuppressed
177 {
178 if ( CheckHealthCondition( muzzle_owner.GetHealthLevel() ) ) // onlyWithinHealthLabel
179 {
180 if ( CheckOverheatingCondition( muzzle_owner.GetOverheatingCoef() ) ) // onlyWithinOverheatLimits
181 {
182 if ( CheckRainCondition( g_Game.GetWeather().GetRain().GetActual() ) ) // onlyWithinRainLimits
183 {
184 if ( m_OnlyIfBulletIs == "" || m_OnlyIfBulletIs == ammoType ) // onlyIfBulletIs
185 {
186 if ( m_OnlyIfWeaponIs == "" || m_OnlyIfWeaponIs == weapon.GetType() ) // onlyIfWeaponIs
187 {
188 // Get particle ID
189 int particle_id = CheckParticleOverride(ammoType);
190
192 {
193 // Get position of the particle
194 vector local_pos = muzzle_owner.GetSelectionPositionLS(m_OverridePoint);
195 local_pos += m_PositionOffset;
196
197 // Set orientation of the particle
198 vector particle_ori = CheckOrientationOverride(local_pos, muzzle_owner);
199
200 // Create particle
201 Particle p = ParticleManager.GetInstance().PlayOnObject( particle_id, muzzle_owner, local_pos, particle_ori );
202 OnParticleCreated(weapon, ammoType, muzzle_owner, suppressor, config_to_search, p);
203 }
204 else
205 {
206 ErrorEx(string.Format("No valid particle found for: '%1'", m_Name));
207 }
208
209 // Create light
211 {
212 vector global_pos = muzzle_owner.ModelToWorld(local_pos + Vector(-0.2, 0, 0));
213 int randX = Math.RandomInt( 0,10 );
214 if ( randX > 8 )
215 ScriptedLightBase.CreateLight( MuzzleFlashLight_2, global_pos );
216 else if ( randX > 4 )
217 ScriptedLightBase.CreateLight( MuzzleFlashLight_1, global_pos );
218 else
219 ScriptedLightBase.CreateLight(MuzzleFlashLight, global_pos);
220 }
221 }
222 }
223 }
224 }
225 }
226 }
227 }
228 }
229 }
230 }
231 }
232
233 void OnParticleCreated(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search, Particle p)
234 {
235
236 }
237
238 void OnDeactivate(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search)
239 {
240
241 }
242
243 void OnUpdate(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search)
244 {
245
246 }
247
248
249 //==============================================
250 // HANDLE CONFIG PARAMETERS
251 //==============================================
252
253
254 // OnlyWithinHealthLabelMin & OnlyWithinHealthLabelMax
256 {
257 if ( m_OnlyIfBoltIsOpen )
258 {
259 Weapon_Base wb = Weapon_Base.Cast( weapon );
260 WeaponStateBase current_state = wb.GetCurrentState();
261 return current_state.IsBoltOpen();
262 }
263
264 return true;
265 }
266
267 // OnlyWithinHealthLabelMin & OnlyWithinHealthLabelMax
268 bool CheckHealthCondition(int health_label)
269 {
270 return ( (health_label >= m_OnlyWithinHealthLabelMin) && (health_label <= m_OnlyWithinHealthLabelMax) );
271 }
272
273 // OnlyWithinOverheatLimitsMin & OnlyWithinOverheatLimitsMax
274 bool CheckOverheatingCondition(float overheating_coef)
275 {
276 return ( (overheating_coef >= m_OnlyWithinOverheatLimitsMin) && (overheating_coef <= m_OnlyWithinOverheatLimitsMax) );
277 }
278
279 // OnlyWithinRainLimitsMin & OnlyWithinRainLimitsMax
280 bool CheckRainCondition(float rain_coef)
281 {
282 return ( (rain_coef >= m_OnlyWithinRainLimitsMin) && (rain_coef <= m_OnlyWithinRainLimitsMax) );
283 }
284
285 // muzzleFlashParticle
286 int CheckParticleOverride(string ammoType)
287 {
288 int particle_id = -1;
289
290 string particle_file = "";
291 string cfg_path = "CfgAmmo " + ammoType + " muzzleFlashParticle";
292 if (g_Game.ConfigGetText( cfg_path, particle_file))
294
295 // Config is accessed only once because the data is saved into a map for repeated access.
296
297 if ( particle_id > 0 || m_OverrideParticle == -1)
298 {
299 if (particle_file == "")
300 {
301 ErrorEx(string.Format("Cannot spawn particle effect because item %1 is missing config parameter muzzleFlashParticle!", ammoType), ErrorExSeverity.INFO);
302 }
303 else
304 {
306
307 if (particle_id == 0)
308 {
309 string devStr;
310 #ifdef DEVELOPER
311 devStr = " Make sure it's registered there and then rebuild Scripts and Graphics PBOs.";
312 #endif
313 ErrorEx(string.Format("Cannot play particle effect with name %1 because no such file is registered in ParticleList.c!%2", particle_file, devStr));
314 m_OverrideParticle = particle_id; // Prevents another appearence of the above error.
315 }
316 }
317 }
318 else
319 {
321 }
322
323 return particle_id;
324 }
325
326 // OverrideDirectionPoint & OverrideDirectionVector
328 {
329 vector particle_ori = "0 0 0";
330 if (m_OverrideDirectionPoint != "")
331 {
332 vector target_pos = muzzle_owner.GetSelectionPositionLS(m_OverrideDirectionPoint);
333 target_pos = vector.Direction(local_pos, target_pos);
334 particle_ori = target_pos.VectorToAngles();
335 }
336 else
337 {
338 if (m_OverrideDirectionVector != Vector(0, 0, 0))
339 {
340 particle_ori = m_OverrideDirectionVector;
341 }
342
343 if (muzzle_owner.IsInherited(ItemSuppressor))
344 {
345 particle_ori = particle_ori + Vector(0,0,270); // This rotation is necesarry due to suppressors being rotated into ground in their p3d files
346 }
347 }
348
349 return particle_ori;
350 }
351}
352
353// FIRE particles
354class WeaponParticlesOnFire : WeaponParticlesBase {}
355
356// BULLET EJECT particles
357class WeaponParticlesOnBulletCasingEject : WeaponParticlesBase {}
358
359// OVERHEATING particles
360class WeaponParticlesOnOverheating: WeaponParticlesBase
361{
362 override void OnParticleCreated(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search, Particle p)
364 muzzle_owner.RegisterOverheatingParticle(p, m_OnlyWithinOverheatLimitsMin, m_OnlyWithinOverheatLimitsMax, p.GetParticleID(), muzzle_owner, p.m_DefaultPos, p.m_DefaultOri );
367 override void OnDeactivate(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search)
369 if ( !g_Game.IsServer() || !g_Game.IsMultiplayer() )
371 weapon.KillAllOverheatingParticles();
375 override void OnUpdate(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search)
377 OnActivate(weapon, 0, ammoType, muzzle_owner, suppressor, config_to_search);
380
382{
388
391
393 {
394 m_Particle = p;
395 }
396
398 {
399 return m_Particle;
400 }
401
403 {
405 }
406
408 {
410 }
411
413 {
415 }
416
418 {
420 }
421
422 void SetParticleParams(int particle_id, Object parent, vector local_pos, vector local_ori)
423 {
425 m_Parent = parent;
426 m_LocalPos = local_pos;
427 m_LocalOri = local_ori;
428 }
429
431 {
432 return m_ParticleID;
433 }
434
436 {
437 return m_Parent;
438 }
439
441 {
442 return m_LocalPos;
443 }
444
446 {
447 return m_LocalOri;
448 }
449}
DayZGame g_Game
Определения DayZGame.c:3942
class GP5GasMask extends MaskBase ItemBase
void MuzzleFlashLight_1()
Определения MuzzleFlashLight.c:24
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
Определения ParticleManager.c:88
int particle_id
Определения SmokeSimulation.c:28
void OnActivate()
Определения Trap_LandMine.c:67
float m_OnlyWithinOverheatLimitsMin
Определения WeaponParticles.c:370
float m_OnlyWithinOverheatLimitsMax
Определения WeaponParticles.c:371
Определения EnMath.c:7
Определения ObjectTyped.c:2
vector m_LocalPos
Определения WeaponParticles.c:386
float GetOverheatingLimitMax()
Определения WeaponParticles.c:417
float m_OverheatingLimitMax
Определения WeaponParticles.c:390
vector GetParticleOri()
Определения WeaponParticles.c:445
void SetOverheatingLimitMax(float max)
Определения WeaponParticles.c:407
void SetParticleParams(int particle_id, Object parent, vector local_pos, vector local_ori)
Определения WeaponParticles.c:422
Object GetParticleParent()
Определения WeaponParticles.c:435
int m_ParticleID
Определения WeaponParticles.c:384
float GetOverheatingLimitMin()
Определения WeaponParticles.c:412
Object m_Parent
Определения WeaponParticles.c:385
Particle m_Particle
Определения WeaponParticles.c:383
float m_OverheatingLimitMin
Определения WeaponParticles.c:389
Particle GetParticle()
Определения WeaponParticles.c:397
void SetOverheatingLimitMin(float min)
Определения WeaponParticles.c:402
int GetParticleID()
Определения WeaponParticles.c:430
void RegisterParticle(Particle p)
Определения WeaponParticles.c:392
vector GetParticlePos()
Определения WeaponParticles.c:440
vector m_LocalOri
Определения WeaponParticles.c:387
vector m_DefaultPos
Used for Wiggle API, to restore after unparenting.
Определения Particle.c:33
vector m_DefaultOri
Used for Wiggle API, to restore after unparenting.
Определения Particle.c:31
int GetParticleID()
Gets particle id.
Определения Particle.c:297
Legacy way of using particles in the game.
Определения Particle.c:7
static int GetParticleIDByName(string name)
Returns particle's ID based on the filename (without .ptc suffix)
Определения ParticleList.c:506
static bool IsValidId(int id)
Purely checks for an invalid number, does NOT mean it is actually registered.
Определения ParticleList.c:476
Определения ParticleList.c:12
static bool m_GunParticlesState
Определения gameplay.c:1538
Определения gameplay.c:1537
shorthand
Определения BoltActionRifle_Base.c:6
void WeaponParticlesBase(ItemBase muzzle_owner, string config_OnFire_entry)
Определения WeaponParticles.c:33
bool CheckRainCondition(float rain_coef)
Определения WeaponParticles.c:280
void OnDeactivate(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search)
Определения WeaponParticles.c:238
bool CheckHealthCondition(int health_label)
Определения WeaponParticles.c:268
void OnUpdate(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search)
Определения WeaponParticles.c:243
float m_OnlyWithinRainLimitsMin
Определения WeaponParticles.c:18
int m_OnlyWithinHealthLabelMin
Определения WeaponParticles.c:14
vector m_PositionOffset
Определения WeaponParticles.c:25
float m_OnlyWithinOverheatLimitsMax
Определения WeaponParticles.c:17
float m_OnlyWithinRainLimitsMax
Определения WeaponParticles.c:19
string m_OnlyIfWeaponIs
Определения WeaponParticles.c:22
bool m_IgnoreIfSuppressed
Определения WeaponParticles.c:10
int m_OverrideParticle
Определения WeaponParticles.c:13
float m_OnlyWithinOverheatLimitsMin
Определения WeaponParticles.c:16
string m_OnlyIfBulletIs
Определения WeaponParticles.c:21
int m_MuzzleIndex
Определения WeaponParticles.c:12
vector CheckOrientationOverride(vector local_pos, ItemBase muzzle_owner)
Определения WeaponParticles.c:327
bool CheckOverheatingCondition(float overheating_coef)
Определения WeaponParticles.c:274
int CheckParticleOverride(string ammoType)
Определения WeaponParticles.c:286
string m_OverrideDirectionPoint
Определения WeaponParticles.c:20
bool m_OnlyIfBoltIsOpen
Определения WeaponParticles.c:11
string m_Name
Определения WeaponParticles.c:27
string m_OverridePoint
Определения WeaponParticles.c:23
void OnParticleCreated(ItemBase weapon, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search, Particle p)
Определения WeaponParticles.c:233
bool CheckBoltStateCondition(ItemBase weapon)
Определения WeaponParticles.c:255
vector m_OverrideDirectionVector
Определения WeaponParticles.c:24
int m_OnlyWithinHealthLabelMax
Определения WeaponParticles.c:15
void OnActivate(ItemBase weapon, int muzzle_index, string ammoType, ItemBase muzzle_owner, ItemBase suppressor, string config_to_search)
Определения WeaponParticles.c:165
bool m_IlluminateWorld
Определения WeaponParticles.c:9
bool IsBoltOpen()
Определения WeaponStateBase.c:163
represent weapon state base
Определения BulletHide.c:2
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
static const vector Zero
Определения EnConvert.c:123
static vector Direction(vector p1, vector p2)
Returns direction vector from point p1 to point p2.
Определения EnConvert.c:233
proto vector VectorToAngles()
Converts vector to spherical coordinates with radius = 1.
Определения EnConvert.c:119
ErrorExSeverity
Определения 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()
Определения 3_Game/DayZ/tools/tools.c:349