4 override bool _WB_GetCustomTitle(
BaseContainer source, out
string title)
6 title =
"Random Particle Effect";
17 [
Attribute(
"60",
UIWidgets.Slider,
"Maximum duration for particle spawning loop [seconds]",
"0 600 1")]
18 protected float m_fMaxDuration;
21 [
Attribute(
"1",
UIWidgets.Slider,
"Minimum interval between particle spawns [seconds]",
"0.1 30 0.1")]
22 protected float m_fMinInterval;
25 [
Attribute(
"5",
UIWidgets.Slider,
"Maximum interval between particle spawns [seconds]",
"0.1 30 0.1")]
26 protected float m_fMaxInterval;
33 [
Attribute(
"0",
UIWidgets.Slider,
"Minimum distance from camera to trigger effects [meters]",
"0 1000 1")]
34 protected float m_fTriggerDistanceMin;
37 [
Attribute(
"5",
UIWidgets.Slider,
"Maximum distance from camera to trigger effects [meters] (0 = no limit)",
"0 1000 1")]
38 protected float m_fTriggerDistanceMax;
46 protected int m_iRepetitionCountRnd;
50 protected float m_fSequenceRepetitionTime;
53 [
Attribute(
"5",
UIWidgets.Slider,
"Sequence repetition time randomization [seconds]",
"0 30 0.1")]
54 protected float m_fSequenceRepetitionTimeRnd;
57 protected float m_fElapsedTime = 0;
60 protected int m_iCurrentRepCount;
61 protected bool m_bInSequence =
false;
67 SCR_RandomParticleSpawnable otherRandom = SCR_RandomParticleSpawnable.Cast(other);
69 if (!super.CompareAttributes(other))
75 if (otherRandom.m_fMaxDuration != m_fMaxDuration)
78 if (otherRandom.m_fMinInterval != m_fMinInterval)
81 if (otherRandom.m_fMaxInterval != m_fMaxInterval)
87 if (otherRandom.m_fTriggerDistanceMin != m_fTriggerDistanceMin)
90 if (otherRandom.m_fTriggerDistanceMax != m_fTriggerDistanceMax)
96 if (otherRandom.m_iRepetitionCountRnd != m_iRepetitionCountRnd)
99 if (otherRandom.m_fSequenceRepetitionTime != m_fSequenceRepetitionTime)
102 if (otherRandom.m_fSequenceRepetitionTimeRnd != m_fSequenceRepetitionTimeRnd)
109 override void SetVariables(WorldEditorAPI api, IEntitySource source, array<ref ContainerIdPathEntry>
path,
int index)
111 super.SetVariables(api, source,
path,
index);
114 api.SetVariableValue(source,
path,
"m_fMaxDuration", m_fMaxDuration.ToString());
115 api.SetVariableValue(source,
path,
"m_fMinInterval", m_fMinInterval.ToString());
116 api.SetVariableValue(source,
path,
"m_fMaxInterval", m_fMaxInterval.ToString());
118 api.SetVariableValue(source,
path,
"m_fTriggerDistanceMin", m_fTriggerDistanceMin.ToString());
119 api.SetVariableValue(source,
path,
"m_fTriggerDistanceMax", m_fTriggerDistanceMax.ToString());
121 api.SetVariableValue(source,
path,
"m_iRepetitionCountRnd", m_iRepetitionCountRnd.ToString());
122 api.SetVariableValue(source,
path,
"m_fSequenceRepetitionTime", m_fSequenceRepetitionTime.ToString());
123 api.SetVariableValue(source,
path,
"m_fSequenceRepetitionTimeRnd", m_fSequenceRepetitionTimeRnd.ToString());
127 override bool CreateObject(WorldEditorAPI api, IEntitySource source, array<ref ContainerIdPathEntry>
path,
int index)
129 if (!AlreadyExists(api, source,
index))
131 api.CreateObjectArrayVariableMember(source,
path,
"m_aPhaseDestroySpawnObjects",
"SCR_RandomParticleSpawnable",
index);
141 protected int GetRepCount()
148 protected float GetRandomInterval()
150 if (m_fMinInterval >= m_fMaxInterval)
151 return m_fMinInterval;
153 return Math.RandomFloatInclusive(m_fMinInterval, m_fMaxInterval);
158 protected float GetSequenceRepTime()
160 if (m_fSequenceRepetitionTimeRnd < 0.001)
161 return m_fSequenceRepetitionTime;
163 return Math.RandomFloatInclusive(Math.Max(0.1, m_fSequenceRepetitionTime - m_fSequenceRepetitionTimeRnd), m_fSequenceRepetitionTime + m_fSequenceRepetitionTimeRnd);
171 if (m_fTriggerDistanceMax <= 0 && m_fTriggerDistanceMin <= 0)
174 vector ownerTransform[4];
175 vector cameraTransform[4];
178 owner.
GetWorld().GetCurrentCamera(cameraTransform);
180 float distance = vector.Distance(ownerTransform[3], cameraTransform[3]);
183 if (m_fTriggerDistanceMin > 0 &&
distance < m_fTriggerDistanceMin)
187 if (m_fTriggerDistanceMax > 0 &&
distance > m_fTriggerDistanceMax)
195 protected void OnTimer(
IEntity owner, SCR_HitInfo hitInfo)
205 if (m_fMaxDuration > 0 && m_fElapsedTime >= m_fMaxDuration)
215 ScheduleNextTimer(owner, hitInfo);
222 super.Spawn(owner, null, hitInfo,
false);
228 SoundComponent soundComponent = SoundComponent.Cast(owner.
FindComponent(SoundComponent));
236 ScheduleNextTimer(owner, hitInfo);
241 protected void ScheduleNextTimer(
IEntity owner, SCR_HitInfo hitInfo)
248 if (m_bInSequence && m_iCurrentRepCount > 1)
251 m_iCurrentRepCount--;
252 nextInterval = GetRandomInterval();
257 m_iCurrentRepCount = GetRepCount();
258 m_bInSequence =
true;
260 if (m_iCurrentRepCount > 1)
262 m_iCurrentRepCount--;
263 nextInterval = GetRandomInterval();
268 m_bInSequence =
false;
269 nextInterval = GetSequenceRepTime();
274 m_fElapsedTime += nextInterval;
277 m_CallQueue.CallLater(OnTimer, nextInterval * 1000,
false, owner, hitInfo);
282 protected void CleanupTimer()
286 m_CallQueue.Remove(OnTimer);
291 m_iCurrentRepCount = 0;
292 m_bInSequence =
false;
300 if (!owner || !hitInfo)
306 m_prng =
new RandomGenerator;
308 int seed = owner.
GetID();
309 m_prng.SetSeed(seed);
313 m_CallQueue =
GetGame().GetCallqueue();
314 m_iCurrentRepCount = GetRepCount();
315 m_bInSequence =
true;
323 SoundComponent soundComponent = SoundComponent.Cast(owner.
FindComponent(SoundComponent));
333 if (m_CallQueue && m_fMaxDuration > 0)
337 if (m_iCurrentRepCount > 1)
339 m_iCurrentRepCount--;
340 firstInterval = GetRandomInterval();
344 m_bInSequence =
false;
345 firstInterval = GetSequenceRepTime();
348 m_fElapsedTime += firstInterval;
349 m_CallQueue.CallLater(OnTimer, firstInterval * 1000,
false, owner, hitInfo);
352 return initialParticle;
364 void SCR_RandomParticleSpawnable()
367 if (m_fMinInterval > m_fMaxInterval)
369 float temp = m_fMinInterval;
370 m_fMinInterval = m_fMaxInterval;
371 m_fMaxInterval = temp;
375 if (m_fMinInterval < 0.1)
376 m_fMinInterval = 0.1;
378 if (m_fMaxInterval < 0.1)
379 m_fMaxInterval = 0.1;
ArmaReforgerScripted GetGame()
SCR_AIGroupClass snapToTerrain
void GetSpawnTransform(IEntity owner, out vector outMat[4], bool localCoords=false)
Calculates the spawn tranformation matrix for the object.
bool IsInRange(notnull IEntity actionOwner, vector actionPosition)
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
SCR_Spawnable_RandomParticleTitle BaseContainerCustomTitle BaseContainerProps()
void ParticleEffectEntity(IEntitySource src, IEntity parent)
enum EVehicleType IEntity
proto external Managed FindComponent(typename typeName)
proto external BaseWorld GetWorld()
proto external EntityID GetID()
proto external void GetTransform(out vector mat[])
proto external bool IsDeleted()
Custom title for Workbench editor.
ScriptCallQueue Class provide "lazy" calls - when we don't want to execute function immediately but l...
AISpawnerGroupClass AIGroupClass Spawn()
Spawns a new group entity, sets its transformation and then calls OnSpawn.
SCR_FieldOfViewSettings Attribute