Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_BellSoundComponent.c
Go to the documentation of this file.
3{
4 [Attribute("", UIWidgets.EditBox, "")]
5 float m_fBellTime;
6
7 [Attribute("", UIWidgets.EditBox, "")]
8 int m_iRepetitionCount;
9}
10
11[ComponentEditorProps(category: "GameScripted/Sound", description: "Bell Sound Component")]
12class SCR_BellSoundComponentClass : SoundComponentClass
14}
15
16class SCR_BellSoundComponent : SoundComponent
17{
18 [Attribute("", UIWidgets.Object, "Time settings")]
19 ref array<ref SCR_SoundBellTime> m_aSoundBellTime;
20
21 private static GameSignalsManager m_GameSignalManager;
22 private int m_iTimeOfDaySignalIdx;
23
24 private const float TRIGGER_INTERVAL = 850;
25
26 protected float m_fTimer;
27 protected float m_fTimeOfDayValueLast;
28
29 protected int m_iBellTimeIdx = -1;
30 protected int m_iSoundBellTimeCount;
31 protected int m_iRepetitionCount;
32
33 private float m_fWorldTimeLast;
34
35 //------------------------------------------------------------------------------------------------
36 override void UpdateSoundJob(IEntity owner, float timeSlice)
37 {
38 // UpdateSoundJob only once pref frame
39 float worldTime = owner.GetWorld().GetWorldTime();
40
41 if (m_fWorldTimeLast == worldTime)
42 return;
43
44 float dt = worldTime - m_fWorldTimeLast;
45 float timeOfDay = m_GameSignalManager.GetSignalValue(m_iTimeOfDaySignalIdx) * 24;
46
47 if (m_iRepetitionCount != 0)
48 {
49 m_fTimer += dt;
50
51 if (m_fTimer > TRIGGER_INTERVAL)
52 {
53 //Play sound
54 string eventName;
55
56 if (m_iRepetitionCount == 1)
57 {
58 eventName = SCR_SoundEvent.SOUND_BELL_END;
59 }
60 else if (m_iRepetitionCount%2 == 0)
61 {
62 eventName = SCR_SoundEvent.SOUND_BELL_A;
63 }
64 else
65 {
66 eventName = SCR_SoundEvent.SOUND_BELL_B;
67 }
68
69 SoundEvent(eventName);
70
72 m_fTimer = 0;
73 }
74 }
75 else
76 {
77 // Get m_iBellTimeIdx
78 if (m_iBellTimeIdx == - 1)
79 {
81
82 for (int i = 0; i < m_iSoundBellTimeCount; i++)
83 {
84 if (m_aSoundBellTime[i].m_fBellTime > timeOfDay)
85 {
87 break;
88 }
89 }
90 }
91
92 // OnFrame check if sound should be triggered
93 if (m_aSoundBellTime[m_iBellTimeIdx].m_fBellTime < timeOfDay && m_aSoundBellTime[m_iBellTimeIdx].m_fBellTime >= m_fTimeOfDayValueLast)
94 {
95 m_iRepetitionCount = m_aSoundBellTime[m_iBellTimeIdx].m_iRepetitionCount;
96 m_iBellTimeIdx = -1;
97 }
98 }
99
100 // Set Last values
101 m_fTimeOfDayValueLast = timeOfDay;
102 m_fWorldTimeLast = worldTime;
103 }
104
105 //------------------------------------------------------------------------------------------------
106 override void OnUpdateSoundJobBegin(IEntity owner)
107 {
108 m_fTimeOfDayValueLast = m_GameSignalManager.GetSignalValue(m_iTimeOfDaySignalIdx) * 24;
110 m_iBellTimeIdx = -1;
111 }
112
113 //------------------------------------------------------------------------------------------------
114 override void OnPostInit(IEntity owner)
115 {
116 super.OnPostInit(owner);
117
118 // Set Init
119 SetEventMask(owner, EntityEvent.INIT);
120 }
121
122 //------------------------------------------------------------------------------------------------
123 override void OnInit(IEntity owner)
124 {
125 // Get m_aSoundBellTime count
126 m_iSoundBellTimeCount = m_aSoundBellTime.Count();
127
128 // Disable OnFrame if no time is defined
129 if (m_iSoundBellTimeCount == 0)
130 {
131 SetScriptedMethodsCall(false);
132 return;
133 }
134
135 // Get GameSignalsManager
136 m_GameSignalManager = GetGame().GetSignalsManager();
137
138 m_iTimeOfDaySignalIdx = m_GameSignalManager.AddOrFindSignal("TimeOfDay");
139 }
140
141 //------------------------------------------------------------------------------------------------
142 // constructor
146 void SCR_BellSoundComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
147 {
148 SetScriptedMethodsCall(true);
149 }
150}
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
class SCR_SoundBellTime ComponentEditorProps(category:"GameScripted/Sound", description:"Bell Sound Component")
int m_iRepetitionCount
float m_fBellTime
enum EVehicleType IEntity
proto external int SetEventMask(notnull IEntity owner, int mask)
proto external BaseWorld GetWorld()
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14