Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_TriggerSoundComponent.c
Go to the documentation of this file.
4
5
6[EntityEditorProps(category: "GameScripted/Sound", description: "Plays sounds, within defined time and range")]
7class SCR_TriggerSoundComponent : SoundComponent
8{
9 [Attribute("", UIWidgets.EditBox, "")]
10 protected string m_sSoundEvent;
11
12 [Attribute(defvalue: "100", UIWidgets.Slider, desc: "Sounds will not be trigger if distance is less than this.", "0 5000 1")]
13 protected float m_fTriggerDistanceMin;
14
15 [Attribute(defvalue: "1000", UIWidgets.Slider, "Sounds will not be trigged if distance is greater than this.", "0 5000 1")]
16 protected float m_fTriggerDistanceMax;
17
18 [Attribute("4", UIWidgets.Slider, "Repetition count", "0 10 1")]
19 protected int m_iRepCount;
20
21 [Attribute("0", UIWidgets.Slider, "Repetition count randomisation", "0 10 1")]
22 protected int m_iRepCountRnd;
23
24 [Attribute("10", UIWidgets.Slider, "Repetition time [seconds]", "0 30 0.001")]
25 protected float m_iRepTime;
26
27 [Attribute("10", UIWidgets.Slider, "Repetition time randomization [seconds]", "0 30 0.001")]
28 protected float m_iRepTimeRnd;
29
30 [Attribute("20", UIWidgets.Slider, "Sequence reprtition time [seconds]", "0 60 0.001")]
31 protected float m_iSequenceRepTime;
32
33 [Attribute("20", UIWidgets.Slider, "Sequence repetition randomization [seconds]", "0 60 0.001")]
34 protected float m_iSequenceRepTimeRnd;
35
36 protected float m_fTime;
37 protected float m_fTriggerTime;
38
39 protected int m_iRepCountCurent;
40
41 //------------------------------------------------------------------------------------------------
42 private int GetRepCount()
43 {
44 return Math.RandomIntInclusive(Math.Max(0, m_iRepCount - m_iRepCountRnd), m_iRepCount + m_iRepCountRnd);
45 }
46
47 //------------------------------------------------------------------------------------------------
48 private float GetRepTime()
49 {
50 if (m_iRepTimeRnd < 0.001)
51 {
52 return m_iRepTime;
53 }
54 else
55 {
56 return Math.RandomFloatInclusive(Math.Max(0, m_iRepTime - m_iRepTimeRnd), m_iRepTime + m_iRepTimeRnd);
57 }
58 }
59
60 //------------------------------------------------------------------------------------------------
61 private float GetSequenceRepTime()
62 {
63 if (m_iSequenceRepTimeRnd < 0.001)
64 {
65 return m_iSequenceRepTime;
66 }
67 else
68 {
69 return Math.RandomFloatInclusive(Math.Max(0, m_iSequenceRepTime - m_iSequenceRepTimeRnd), m_iSequenceRepTime + m_iSequenceRepTimeRnd);
70 }
71 }
72
73 //------------------------------------------------------------------------------------------------
74 private bool IsInRange(IEntity owner)
75 {
76 vector matOwner[4];
77 vector matCamera[4];
78
79 owner.GetTransform(matOwner);
80 owner.GetWorld().GetCurrentCamera(matCamera);
81
82 const float distance = vector.Distance(matOwner[3], matCamera[3]);
83 return Math.IsInRange(distance, m_fTriggerDistanceMin, m_fTriggerDistanceMax);
84 }
85
86 //------------------------------------------------------------------------------------------------
87 override void UpdateSoundJob(IEntity owner, float timeSlice)
88 {
89 m_fTime += timeSlice;
90
91 if (m_fTime > m_fTriggerTime)
92 {
93 if (IsInRange(owner))
94 {
95 SoundEvent(m_sSoundEvent);
96 }
97
98 if (m_iRepCountCurent <= 1)
99 {
100 m_iRepCountCurent = GetRepCount();
101 m_fTriggerTime = GetSequenceRepTime();
102 }
103 else
104 {
105 m_iRepCountCurent--;
106 m_fTriggerTime = GetRepTime();
107 }
108
109 m_fTime = 0;
110 }
111 }
112
113 //------------------------------------------------------------------------------------------------
114 override void OnUpdateSoundJobBegin(IEntity owner)
115 {
116 m_fTime = 0;
117 m_iRepCountCurent = GetRepCount();
118 m_fTriggerTime = GetSequenceRepTime();
119 }
120
121 //------------------------------------------------------------------------------------------------
122 void SCR_TriggerSoundComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
123 {
124 SetScriptedMethodsCall(true);
125 }
126
127 //------------------------------------------------------------------------------------------------
128 void ~SCR_TriggerSoundComponent()
129 {
130 }
131
132}
bool IsInRange(notnull IEntity actionOwner, vector actionPosition)
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
float distance
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
string m_sSoundEvent
enum EVehicleType IEntity
proto external BaseWorld GetWorld()
proto external void GetTransform(out vector mat[])
Definition Math.c:13
void OnUpdateSoundJobBegin(IEntity owner)
void UpdateSoundJob(IEntity owner, float timeSlice)
Call when component is in range.
SCR_FieldOfViewSettings Attribute