Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Loading...
Searching...
No Matches
flashbangeffect.c
Go to the documentation of this file.
2{
3 protected const float ALPHA_MIN = 0.0;
4 protected const float ALPHA_MAX = 1.0;
5
6 protected const float SOUND_DEFER_TIME = 0.4;
7
8 protected float m_HitDuration;
9 protected float m_BreakPoint;
10 protected float m_TimeActive;
11 protected float m_DayTimeToggle;
12
13 protected float m_AlphaMaxActual; //actual max alpha of the effect
14 protected float m_SoundMaxActual; //actual max volume of the sound
15 protected float m_ProgressMultiplier;
16
17 protected bool m_Visual;
18 protected bool m_Initialized;
19
22 protected float m_SoundStopTime;
23
25
26 protected PPERequester_FlashbangEffects m_Requester;
27
28 void FlashbangEffect(PlayerBase player, bool visual = true)
29 {
30 m_Player = player;
31 m_Visual = visual;
32 m_Initialized = false;
33
34 m_HitDuration = 8.0;
35 m_BreakPoint = 2.5;
37 m_SoundMaxActual = 1.0;
39
41
42 if (m_Visual)
43 {
44 Class.CastTo(m_Requester,PPERequesterBank.GetRequester(PPERequester_FlashbangEffects));
45 m_Requester.Start();
46 }
47
49 m_DeferAttenuation.Run(SOUND_DEFER_TIME, this, "PlaySound", null, false);
50
52 m_DayTimeToggle = 5;
53 if ( g_Game.GetDayTime() >= 22.0 || g_Game.GetDayTime() < 7.0 )
54 {
55 m_DayTimeToggle = 10;
56 }
57 }
58
60 {
61 if ( m_Visual )
62 {
64 }
65
66 if ( m_Player )
67 {
68 m_Player.OnPlayerReceiveFlashbangHitEnd();
69 }
70
71 if ( m_DeferAttenuation.IsRunning() )
72 {
73 m_DeferAttenuation.Stop();
74 }
75
76 m_DeferAttenuation = null;
78 }
79
80 void SetupFlashbangValues(float progress_mult = 1.0, float visual_value_max = 1.0, float sound_value_max = 1.0)
81 {
82 if ( !m_Initialized )
83 {
84 m_Initialized = true;
85 m_ProgressMultiplier = progress_mult;
86 m_AlphaMaxActual = visual_value_max;
87 m_SoundMaxActual = sound_value_max;
88
91 }
92 }
93
94 protected void PlaySound()
95 {
96 if ( !m_Initialized )
97 {
98 Error("" + this + " not initialized");
99 return;
100 }
101
102 vector pos;
103 MiscGameplayFunctions.GetHeadBonePos(m_Player, pos);
104
106 {
107 m_FlashbangEffectSound = SEffectManager.CreateSound("Tinnitus_SoundSet", pos);
108 }
109
110 if (!m_FlashbangEffectSound.IsPlaying())
111 {
113 m_FlashbangEffectSound.SetAttachedLocalPos(m_Player.WorldToModel(pos));
114 m_FlashbangEffectSound.SetSoundWaveKind(WaveKind.WAVEEFFECTEX);
115 m_FlashbangEffectSound.SetSoundFadeIn(4 * Math.Clamp(m_ProgressMultiplier,0.5,1.0)); //TODO
117 m_FlashbangEffectSound.SetSoundFadeOut(m_SoundStopTime); //TODO
118 m_FlashbangEffectSound.SetSoundMaxVolume(Math.Clamp(m_SoundMaxActual,0.1,1.0)); //TODO
119 m_FlashbangEffectSound.SetSoundLoop(true);
120 m_FlashbangEffectSound.SoundPlay();
121 m_FlashbangEffectSound.SetAutodestroy(true);
122
124 }
125 }
126
127 protected void SetAttenuationFilter()
128 {
129 if ( !m_DeferAttenuation.IsRunning() || m_Player.GetMasterAttenuation() != "FlashbangAttenuation" )
130 {
131 m_Player.SetMasterAttenuation("FlashbangAttenuation");
132 }
133 }
134
135 protected void ResetAttenuationFilter()
136 {
137 m_Player.SetMasterAttenuation("");
138 }
139
140 protected void StopSound()
141 {
143 {
144 m_FlashbangEffectSound.SoundStop();
146 }
147 }
148
149 protected void ClearVisual()
150 {
151 if (m_Requester)
152 {
153 m_Requester.Stop();
154 }
155 }
156
157 protected void SetVisual(float val)
158 {
159 if (m_Requester && m_Requester.IsRequesterRunning())
160 {
161 m_Requester.SetFlashbangIntensity(val, m_DayTimeToggle);
162 }
163 }
164
165 void Stop()
166 {
167 StopSound();
168 }
169
170 void Update(float deltatime)
171 {
172 if ( !m_Initialized )
173 {
174 Error("" + this + " not initialized");
175 }
176 else if ( m_Visual )
177 {
178 float value;
179
180 if ( m_TimeActive <= m_BreakPoint )
181 {
182 value = m_AlphaMaxActual;
183 //Print("Flashbango | m_AlphaMaxActual: " + value);
184 }
185 else
186 {
188 value = Math.Clamp(value,0.0,1.0);
189 value = m_AlphaMaxActual - value * m_AlphaMaxActual;
190 //Print("Flashbango | tmp_value: " + value);
191 }
192 SetVisual(value);
193 }
194
195 m_TimeActive += deltatime;
196
198 {
199 StopSound();
200 }
201
203 {
205 delete this;
206 }
207 }
208}
Super root of all classes in Enforce script.
Definition enscript.c:11
Wrapper class for managing sound through SEffectManager.
Definition effectsound.c:5
void SetupFlashbangValues(float progress_mult=1.0, float visual_value_max=1.0, float sound_value_max=1.0)
void Update(float deltatime)
const float ALPHA_MIN
ref Timer m_DeferAttenuation
PPERequester_FlashbangEffects m_Requester
void FlashbangEffect(PlayerBase player, bool visual=true)
const float ALPHA_MAX
PlayerBase m_Player
void SetVisual(float val)
float m_HitDuration
SFX will be played ~0.5s AFTER VFX.
void ResetAttenuationFilter()
EffectSound m_FlashbangEffectSound
const float SOUND_DEFER_TIME
Definition enmath.c:7
Manager class for managing Effect (EffectParticle, EffectSound).
static EffectSound CreateSound(string sound_set, vector position, float play_fade_in=0, float stop_fade_out=0, bool loop=false, bool enviroment=false)
Create an EffectSound.
static void DestroyEffect(Effect effect)
Unregisters, stops and frees the Effect.
DayZGame g_Game
Definition dayzgame.c:3942
void Error(string err)
Messagebox with error message.
Definition endebug.c:90
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.
static proto float InverseLerp(float a, float b, float value)
Calculates the linear value that produces the interpolant value within the range [a,...
WaveKind
Definition sound.c:2