Dayz Explorer 1.28.160049
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
111 {
113 m_FlashbangEffectSound.SetAttachedLocalPos(m_Player.WorldToModel(pos));
116 m_SoundStopTime = 2 * Math.Clamp(m_ProgressMultiplier,0.5,1.0);
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
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
override bool IsPlaying()
Returns true when the effect is playing, false otherwise.
override void SetAutodestroy(bool auto_destroy)
Sets whether Effect automatically cleans up when it stops.
void SetSoundMaxVolume(float volume)
Set the sound max volume.
void SetSoundLoop(bool loop)
Set if the sound loops.
void SetSoundFadeIn(float fade_in)
Set the sound fade in duration.
void SetSoundWaveKind(WaveKind wave_kind)
Set WaveKind for the sound.
void SetSoundFadeOut(float fade_out)
Set the sound fade out duration.
override void SetParent(Object parent_obj, int pivot)
Set parent for the sound to follow.
bool SoundPlay()
Plays sound.
void SoundStop()
Stops sound.
const float ALPHA_MIN
void FlashbangEffect(PlayerBase player, bool visual=true)
void Update(float deltatime)
const float SOUND_DEFER_TIME
EffectSound m_FlashbangEffectSound
PlayerBase m_Player
float m_HitDuration
SFX will be played ~0.5s AFTER VFX.
void ResetAttenuationFilter()
PPERequester_FlashbangEffects m_Requester
const float ALPHA_MAX
void SetupFlashbangValues(float progress_mult=1.0, float visual_value_max=1.0, float sound_value_max=1.0)
ref Timer m_DeferAttenuation
void SetVisual(float val)
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:3868
void Error(string err)
Messagebox with error message.
Definition endebug.c:90
WaveKind
Definition sound.c:2