DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
Particle.c
Go to the documentation of this file.
1
7{
13 protected int m_ParticleID;
15 protected float m_Lifetime;
17 protected bool m_IsRepeat;
19 private bool m_MarkedForDeletion;
21
38
46
51
53 protected int m_PreviousFrame;
57 static private const int MAX_EMITORS = 30;
58
59
61 void Particle()
62 {
64 }
65
67 protected void ParticleInit()
68 {
69 SetFlags(EntityFlags.VISIBLE, true);
70 SetEventMask(EntityEvent.INIT);
71 SetEventMask(EntityEvent.FRAME);
72 }
73
78
88 static Particle CreateOnObject( int particle_id, Object parent_obj, vector local_pos = "0 0 0", vector local_ori = "0 0 0", bool force_world_rotation = false )
89 {
90 if (!parent_obj)
91 Error("ERROR when creating a particle! Parameter parent_obj is NULL!");
92
93 vector global_pos = parent_obj.GetPosition();
94 Particle p = CreateInWorld(particle_id, global_pos, Vector(0,0,0), force_world_rotation);
95 p.AddAsChild(parent_obj, local_pos, local_ori, force_world_rotation);
96 p.m_DefaultOri = local_ori;
97
98 return p;
99 }
100
104 static Particle Create( int particle_id, Object parent_obj, vector local_pos = "0 0 0", vector local_ori = "0 0 0" )
105 {
106 return CreateOnObject( particle_id, parent_obj, local_pos, local_ori);
107 }
108
117 static Particle CreateInWorld( int particle_id, vector global_pos, vector global_ori = "0 0 0", bool force_world_rotation = false )
118 {
119 Particle p = Particle.Cast( GetGame().CreateObjectEx("Particle", global_pos, ECE_LOCAL) );
121 p.SetOrientation(global_ori);
122 p.m_ForceOrientationRelativeToWorld = force_world_rotation;
123 return p;
124 }
125
129 static Particle Create( int particle_id, vector global_pos, vector global_ori = "0 0 0" )
130 {
131 return CreateInWorld( particle_id, global_pos, global_ori );
132 }
133
135
136
137
142
152 static Particle PlayOnObject( int particle_id, Object parent_obj, vector local_pos = "0 0 0", vector local_ori = "0 0 0", bool force_world_rotation = false )
153 {
154 Particle p = CreateOnObject(particle_id, parent_obj, local_pos, local_ori, force_world_rotation);
155 p.PlayParticle();
156
157 return p;
158 }
159
163 static Particle Play( int particle_id, Object parent_obj, vector local_pos = "0 0 0", vector local_ori = "0 0 0" )
164 {
165 return PlayOnObject( particle_id, parent_obj, local_pos, local_ori);
166 }
167
174 static Particle PlayInWorld( int particle_id, vector global_pos)
175 {
176 Particle p = CreateInWorld(particle_id, global_pos);
177 p.PlayParticle();
178
179 return p;
180 }
181
185 static Particle Play( int particle_id, vector global_pos)
186 {
187 return PlayInWorld( particle_id, global_pos);
188 }
189
191
192
193
198
203 override void PlayParticle(int particle_id = -1)
204 {
206 }
207
215 override bool PlayParticleEx(int particle_id = -1, int flags = 0)
216 {
217 if ( particle_id > -1 )
218 {
220 }
221
223
224 UpdateState();
225
226 return true;
227 }
228
233 void Play(int particle_id = -1)
234 {
236 }
237
245 override bool StopParticle(int flags = 0)
246 {
248
249 // Without the following we might get an error when a particle parent is despawned client-side.
250 Object parent = Object.Cast( GetParent() );
251 if ( parent && !ToDelete())
252 {
253 vector world_pos = GetPosition();
254 parent.RemoveChild(this);
255 SetPosition(world_pos);
256 }
257
258 UpdateState();
259
260 return true;
261 }
262
266 void Stop()
267 {
268 StopParticle();
269 }
270
272
273
274
279
286 {
288 }
289
298 {
299 return m_ParticleID;
300 }
301
308 {
309 return m_ParticleEffect;
310 }
311
317 {
318 return m_ParentObject;
319 }
320
326 {
328 {
329 return m_ParticleEffect.HasActiveParticle(m_ParticleEffect);
330 }
331
332 return false;
333 }
334
341 {
343 {
344 return m_ParticleEffect.GetParticleCount(m_ParticleEffect);
345 }
346
347 return 0;
348 }
349
354 bool IsRepeat()
355 {
357 {
358 bool repeat = false;
359
361
362 for (int i = 0; i < emitors; ++i)
363 {
364 GetParticleParm(m_ParticleEffect, i, EmitorParam.REPEAT, repeat);
365
366 if (repeat)
367 {
368 return true;
369 }
370 }
371 }
372
373 return false;
374 }
375
381 {
382 float lifetime_return = 0;
383
385 {
386 float lifetime_min = 0;
387 float lifetime_random = 0;
388 float effect_time = 0;
389
390 float lifetime_sum = 0;
391
393
394 for (int i = 0; i < emitors; ++i)
395 {
396 GetParticleParm(m_ParticleEffect, i, EmitorParam.LIFETIME, lifetime_min);
397 GetParticleParm(m_ParticleEffect, i, EmitorParam.LIFETIME_RND, lifetime_random);
398 GetParticleParm(m_ParticleEffect, i, EmitorParam.EFFECT_TIME, effect_time);
399
400 lifetime_sum = lifetime_min + lifetime_random + effect_time;
401
402 if ( lifetime_sum > lifetime_return )
403 {
404 lifetime_return = lifetime_sum;
405 }
406 }
407 }
408
409 return lifetime_return;
410 }
411
413
414
415
420
425 protected void UpdateState()
426 {
427 if ( m_IsPlaying == false && m_ParticleEffect)
428 {
430 }
431 else if ( m_IsPlaying == true && m_ParticleEffect == null )
432 {
434 }
435 }
436
440 private void CreateParticleEffect()
441 {
442 if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() )
443 {
445 if (fullPath == "")
446 {
447 ErrorEx("Could not play Particle as there is no valid particle id assigned.");
448 m_IsPlaying = false;
449 return;
450 }
451
452 if ( m_ParticleEffect == null )
453 {
454 m_ParticleEffect = GetGame().CreateObjectEx("#particlesourceenf", vector.Zero, ECE_LOCAL); // particle source must be lowercase!
455 }
456
458
459 vobject vobj = GetObject( fullPath );
460 m_ParticleEffect.SetObject(vobj, "");
461 ReleaseObject(vobj);
462
465 }
466 }
467
475 {
476 if ( m_ParticleEffect && GetGame() )
477 {
478 SetParameter(-1, EmitorParam.LIFETIME, 0);
479 SetParameter(-1, EmitorParam.LIFETIME_RND, 0);
480 SetParameter(-1, EmitorParam.REPEAT, 0);
481
482 m_IsRepeat = false;
483 }
484 }
485
489 override void EOnFrame(IEntity other, float timeSlice)
490 {
491 m_Lifetime -= timeSlice;
493 }
494
499 {
500 if (m_Lifetime <= 0)
501 {
503 {
504 m_IsRepeat = IsRepeat(); // It is possible that the REPEAT flag was changed during lifetime, so it needs to be checked again.
505
506 if ( m_IsRepeat )
507 {
509 }
510 else
511 {
513
514 if ( GetParticleCount() == 0 )
515 {
516 m_MarkedForDeletion = true;
517 OnToDelete();
519 }
520 }
521 }
522 else
523 {
525 {
527 {
528 m_ParticleEffect.Delete();
529 m_ParticleEffect = null;
530 }
531
532 Delete();
533 }
534 }
535 }
536 }
537
541 private void OnToDelete()
542 {
543
544 }
545
547
548
549
554
563 void AddAsChild(Object parent, vector local_pos = "0 0 0", vector local_ori = "0 0 0", bool force_rotation_to_world = false)
564 {
565 if (ToDelete())
566 return;
567
568 if (parent)
569 {
570 // AddAsChild method is sometimes called from a timer.
571 // Due to that it is necesarry to use ToDelete() here to check if the parent object is flagged for deletion or not on client,
572 // because sometimes this code is executed before the parent's destructor from where this would normally be handled.
573 if (!parent.ToDelete())
574 {
575 SetPosition(local_pos);
576 SetOrientation(local_ori);
577 m_ParentObject = parent;
578 m_DefaultPos = local_pos;
579 m_ForceOrientationRelativeToWorld = force_rotation_to_world;
580
583
584 parent.AddChild(this, -1, false);
585 }
586 }
587 else
588 {
589 if (m_ParentObject && !m_ParentObject.ToDelete())
590 {
591 m_ParentObject.RemoveChild(this, true);
592 m_ParentObject = null;
593 }
594 }
595 }
596
598
599
600
605
611 void SetParticleParam(int parameter_id, float value )
612 {
613 if (!m_ParticleEffect)
614 return;
615
616 SetParticleParm(m_ParticleEffect, -1, parameter_id, value);
617 }
618
625 void SetParameter(int emitter, int parameter, float value)
626 {
627 if (!m_ParticleEffect)
628 return;
629
630 SetParticleParm(m_ParticleEffect, emitter, parameter, value);
631 }
632
639 void GetParameter(int emitter, int parameter, out float value)
640 {
641 if (!m_ParticleEffect)
642 return;
643
644 GetParticleParm(m_ParticleEffect, emitter, parameter, value);
645 }
646
653 float GetParameterEx(int emitter, int parameter)
654 {
655 if (!m_ParticleEffect)
656 return 0;
657
658 float value;
659 GetParticleParm(m_ParticleEffect, emitter, parameter, value);
660 return value;
661 }
662
668 void ScaleParticleParamFromOriginal(int parameter_id, float coef )
669 {
670 if (!m_ParticleEffect)
671 return;
672
674 for (int i = 0; i < emitors; ++i)
675 {
676 float value;
677 GetParticleParmOriginal(m_ParticleEffect, i, parameter_id, value);
678 SetParticleParm(m_ParticleEffect, i, parameter_id, value * coef);
679 }
680 }
681
687 void ScaleParticleParam(int parameter_id, float coef )
688 {
689 if (!m_ParticleEffect)
690 return;
691
693 for (int i = 0; i < emitors; ++i)
694 {
695 float value;
696 GetParticleParm(m_ParticleEffect, i, parameter_id, value);
697 SetParticleParm(m_ParticleEffect, i, parameter_id, value * coef);
698 }
699 }
700
707 void IncrementParticleParamFromOriginal(int parameter_id, float value )
708 {
709 if (!m_ParticleEffect)
710 return;
711
713 for (int i = 0; i < emitors; ++i)
714 {
715 float param;
716 GetParticleParmOriginal(m_ParticleEffect, i, parameter_id, param);
717 SetParticleParm(m_ParticleEffect, i, parameter_id, param + value);
718 }
719 }
720
727 void IncrementParticleParam(int parameter_id, float value )
728 {
729 if (!m_ParticleEffect)
730 return;
731
733 for (int i = 0; i < emitors; ++i)
734 {
735 float param;
736 GetParticleParm(m_ParticleEffect, i, parameter_id, param);
737 SetParticleParm(m_ParticleEffect, i, parameter_id, param + value);
738 }
739 }
740
742
743
744
749
754 {
755 return m_RandomizeOri && m_RandomizeOri.IsRunning();
756 }
757
765 void SetWiggle(float random_angle, float random_interval)
766 {
767 if ( random_angle != 0 || random_interval != 0 )
768 {
769 m_MaxOriWiggle = random_angle;
770 m_MaxOriInterval = random_interval;
771
772 if ( !m_RandomizeOri )
774
775 if ( !m_RandomizeOri.IsRunning() ) // Makes sure the timer is NOT running already
776 m_RandomizeOri.Run( Math.RandomFloat(0, m_MaxOriInterval) , this, "RandomizeOrientation", null, false);
777 }
778 else
779 {
780 StopWiggle();
781 }
782 }
783
788 {
789 if ( m_RandomizeOri )
790 {
792 }
793
794 m_MaxOriWiggle = 0;
796 }
797
802 {
803 m_WiggleProcessing = true;
804
805 if (m_ParentObject)
806 {
807 if ( !m_RandomizeOri.IsRunning() )
808 {
809 m_RandomizeOri.Run( Math.RandomFloat(0, m_MaxOriInterval) , this, "RandomizeOrientation", NULL, false);
810 }
811
812 Object old_parent = m_ParentObject;
813 AddAsChild( null );
815 }
816
817 m_WiggleProcessing = false;
818 }
819
824 {
826 }
827
831 protected float RandWiggleFloat()
832 {
834 }
835
837}
Object GetObject()
const int ECE_LOCAL
protected bool m_IsPlaying
Whether the Effect is currently playing.
Definition Effect.c:37
void ParticleBase()
ctor
protected void OnParticleEnd()
Event when the particle ends.
protected void OnParticleStop()
Event when the particle stops.
protected void OnParticleStart()
Event when the particle starts.
int particle_id
class JsonUndergroundAreaTriggerData GetPosition
proto native Object CreateObjectEx(string type, vector pos, int iFlags, int iRotation=RF_DEFAULT)
Creates object of certain type.
Definition EnMath.c:7
Legacy way of using particles in the game.
Definition Particle.c:7
Object GetDirectParticleEffect()
Returns direct particle effect entity which is usually handled by this class 'Particle' if there is o...
Definition Particle.c:307
void SetParameter(int emitter, int parameter, float value)
Set the value of a parameter of an emitor in the particle.
Definition Particle.c:625
private void DestroyParticleEffect()
Destroys ParticleEffect child, called from UpdateState.
Definition Particle.c:474
protected int m_ParticleID
ID from ParticleList if assigned.
Definition Particle.c:13
void Stop()
Legacy function for backwards compatibility with 1.14 and below.
Definition Particle.c:266
void Play(int particle_id=-1)
Legacy function for backwards compatibility with 1.01 and below.
Definition Particle.c:233
protected float m_Lifetime
Approx. remaining lifetime of particle.
Definition Particle.c:15
void ScaleParticleParam(int parameter_id, float coef)
Scales the given parameter on all emitors relatively to their CURRENT value.
Definition Particle.c:687
float m_MaxOriWiggle
Used for Wiggle API, Wiggle room [-m_MaxOriWiggle, m_MaxOriWiggle].
Definition Particle.c:40
bool IsWiggling()
Checks if particle is currently wiggling.
Definition Particle.c:753
void GetParameter(int emitter, int parameter, out float value)
Get the value of a parameter of an emitor in the particle.
Definition Particle.c:639
static Particle PlayOnObject(int particle_id, Object parent_obj, vector local_pos="0 0 0", vector local_ori="0 0 0", bool force_world_rotation=false)
Creates a particle emitter, attaches it on the given object and activates it.
Definition Particle.c:152
protected bool m_IsRepeat
Whether this particle repeats.
Definition Particle.c:17
private bool m_MarkedForDeletion
Whether this particle is queued for deletion.
Definition Particle.c:19
vector m_DefaultOri
Used for Wiggle API, to restore after unparenting.
Definition Particle.c:31
override bool PlayParticleEx(int particle_id=-1, int flags=0)
Method to tell the particle to start playing.
Definition Particle.c:215
bool IsRepeat()
Returns whether there is a repeating particle.
Definition Particle.c:354
static Particle Play(int particle_id, vector global_pos)
Legacy function for backwards compatibility with 1.01 and below.
Definition Particle.c:185
vector m_DefaultPos
Used for Wiggle API, to restore after unparenting.
Definition Particle.c:33
static private const int MAX_EMITORS
DEPRECATED
Definition Particle.c:57
Object GetParticleParent()
Returns the parent of this Particle if there is one.
Definition Particle.c:316
override void PlayParticle(int particle_id=-1)
Method to tell the particle to start playing.
Definition Particle.c:203
protected float RandWiggleFloat()
Helper to get a randomized wiggle float value.
Definition Particle.c:831
static Particle Create(int particle_id, vector global_pos, vector global_ori="0 0 0")
Legacy function for backwards compatibility with 1.01 and below.
Definition Particle.c:129
bool m_WiggleProcessing
Used for Wiggle API, to signal that wiggle API is currently doing work.
Definition Particle.c:27
void AddAsChild(Object parent, vector local_pos="0 0 0", vector local_ori="0 0 0", bool force_rotation_to_world=false)
Attaches this particle onto some object. If null value is provided then the particle will be detached...
Definition Particle.c:563
void SetWiggle(float random_angle, float random_interval)
Makes the particle change direction by random_angle every random_interval seconds.
Definition Particle.c:765
vector m_DefaultWorldPos
Used for Wiggle API, to restore after unparenting.
Definition Particle.c:37
float m_MaxOriInterval
Used for Wiggle API, Interval for wiggling [0, m_MaxOriInterval[.
Definition Particle.c:42
protected Object m_ParticleEffect
The child object which contains the actual particle.
Definition Particle.c:50
protected vector RandWiggleVector()
Helper to get a randomized wiggle vector.
Definition Particle.c:823
bool HasActiveParticle()
Returns if there is any particle active.
Definition Particle.c:325
protected void UpdateState()
Creates/Destroys ParticleEffect child according to current state.
Definition Particle.c:425
protected Object m_ParentObject
Parent Object the Particle is child of.
Definition Particle.c:48
float GetParameterEx(int emitter, int parameter)
Get the value of a parameter of an emitor in the particle.
Definition Particle.c:653
bool m_ForceOrientationRelativeToWorld
Used for Wiggle API, to restore after unparenting.
Definition Particle.c:29
protected void ParticleInit()
Purely here so that it can be emptied in ParticleSource.
Definition Particle.c:67
private vector m_GlobalPosPreviousFrame
DEPRECATED.
Definition Particle.c:55
static Particle CreateInWorld(int particle_id, vector global_pos, vector global_ori="0 0 0", bool force_world_rotation=false)
Creates a particle emitter on the given position.
Definition Particle.c:117
void IncrementParticleParam(int parameter_id, float value)
Increments the value of the given parameter relatively from the CURRENT value.
Definition Particle.c:727
void RandomizeOrientation()
Randomizes a new orientation and applies it.
Definition Particle.c:801
private void OnToDelete()
Called before deletion from OnCheckAutoDelete.
Definition Particle.c:541
static Particle PlayInWorld(int particle_id, vector global_pos)
Creates a particle emitter on the given position and activates it.
Definition Particle.c:174
void SetParticleParam(int parameter_id, float value)
Set the value of a parameter of all emitors in the particle.
Definition Particle.c:611
void Particle()
ctor
Definition Particle.c:61
void SetSource(int particle_id)
Sets particle id.
Definition Particle.c:285
static Particle CreateOnObject(int particle_id, Object parent_obj, vector local_pos="0 0 0", vector local_ori="0 0 0", bool force_world_rotation=false)
Creates a particle emitter and attaches it on the given object.
Definition Particle.c:88
int GetParticleID()
Gets particle id.
Definition Particle.c:297
static Particle Play(int particle_id, Object parent_obj, vector local_pos="0 0 0", vector local_ori="0 0 0")
Legacy function for backwards compatibility with 1.01 and below.
Definition Particle.c:163
void StopWiggle()
Stops randomized wiggle.
Definition Particle.c:787
void OnCheckAutoDelete()
Creates ParticleEffect child, called from UpdateState.
Definition Particle.c:498
protected int m_PreviousFrame
DEPRECATED.
Definition Particle.c:53
float GetMaxLifetime()
Returns the approx. max lifetime.
Definition Particle.c:380
private void CreateParticleEffect()
Creates ParticleEffect child, called from UpdateState.
Definition Particle.c:440
void IncrementParticleParamFromOriginal(int parameter_id, float value)
Increments the value of the given parameter relatively from the ORIGINAL value.
Definition Particle.c:707
int GetParticleCount()
Returns the total count of active particles in all emitors.
Definition Particle.c:340
override bool StopParticle(int flags=0)
Method to tell the particle to stop playing.
Definition Particle.c:245
vector m_DefaultWorldOri
Used for Wiggle API, to restore after unparenting.
Definition Particle.c:35
override void EOnFrame(IEntity other, float timeSlice)
OnFrame update event decrementing the stored approx. lifetime and checking for deletion.
Definition Particle.c:489
void ScaleParticleParamFromOriginal(int parameter_id, float coef)
Scales the given parameter on all emitors relatively to their ORIGINAL value.
Definition Particle.c:668
static Particle Create(int particle_id, Object parent_obj, vector local_pos="0 0 0", vector local_ori="0 0 0")
Legacy function for backwards compatibility.
Definition Particle.c:104
ref Timer m_RandomizeOri
Used for Wiggle API, calls the Wiggle functionality.
Definition Particle.c:44
static string GetParticleFullPath(int particle_id)
Returns particle's full path (with .ptc suffix) based on its ID.
override void Stop()
static const vector Zero
Definition EnConvert.c:110
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
Definition EnDebug.c:90
enum ShapeType ErrorEx
proto native void SetPosition(vector position)
Set the world position of the Effect.
Definition Effect.c:427
proto native void SetFlags(ShapeFlags flags)
EntityEvent
Entity events for event-mask, or throwing event from code.
Definition EnEntity.c:45
EntityFlags
Entity flags.
Definition EnEntity.c:115
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static float RandomFloatInclusive(float min, float max)
Returns a random float number between and min [inclusive] and max [inclusive].
Definition EnMath.c:86
static proto float RandomFloat(float min, float max)
Returns a random float number between and min[inclusive] and max[exclusive].
proto void SetParticleParm(notnull IEntity ent, int emitor, EmitorParam parameter, void value)
proto void GetParticleParmOriginal(notnull IEntity ent, int emitor, EmitorParam parameter, out void value)
proto int GetParticleEmitorCount(notnull IEntity ent)
EmitorParam
Definition EnVisual.c:114
proto void GetParticleParm(notnull IEntity ent, int emitor, EmitorParam parameter, out void value)
const int CALL_CATEGORY_GAMEPLAY
Definition tools.c:10
proto native void ReleaseObject(vobject object, int flag=0)
proto native Widget GetParent()
Get parent of the Effect.
Definition Effect.c:396
proto native void AddChild(Widget child, bool immedUpdate=true)