DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
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
48 m_DeferAttenuation = new ref Timer();
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 {
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));
121
123 }
124 }
125
126 protected void SetAttenuationFilter()
127 {
128 if ( !m_DeferAttenuation.IsRunning() || m_Player.GetMasterAttenuation() != "FlashbangAttenuation" )
129 {
130 m_Player.SetMasterAttenuation("FlashbangAttenuation");
131 }
132 }
133
134 protected void ResetAttenuationFilter()
135 {
136 m_Player.SetMasterAttenuation("");
137 }
138
139 protected void StopSound()
140 {
142 {
144 }
145 }
146
147 protected void ClearVisual()
148 {
149 if (m_Requester)
150 {
151 m_Requester.Stop();
152 }
153 }
154
155 protected void SetVisual(float val)
156 {
157 if (m_Requester && m_Requester.IsRequesterRunning())
158 {
159 m_Requester.SetFlashbangIntensity(val, m_DayTimeToggle);
160 }
161 }
162
163 void Stop()
164 {
165 StopSound();
166 }
167
168 void Update(float deltatime)
169 {
170 if ( !m_Initialized )
171 {
172 Error("" + this + " not initialized");
173 }
174 else if ( m_Visual )
175 {
176 float value;
177
178 if ( m_TimeActive <= m_BreakPoint )
179 {
180 value = m_AlphaMaxActual;
181 //Print("Flashbango | m_AlphaMaxActual: " + value);
182 }
183 else
184 {
186 value = Math.Clamp(value,0.0,1.0);
187 value = m_AlphaMaxActual - value * m_AlphaMaxActual;
188 //Print("Flashbango | tmp_value: " + value);
189 }
190 SetVisual(value);
191 }
192
193 m_TimeActive += deltatime;
194
196 {
197 StopSound();
198 }
199
201 {
203 delete this;
204 }
205 }
206}
DayZGame g_Game
Definition DayZGame.c:3654
WaveKind
Definition Sound.c:2
Super root of all classes in Enforce script.
Definition EnScript.c:11
Wrapper class for managing sound through SEffectManager.
Definition EffectSound.c:5
bool SoundPlay()
Plays sound.
void SetSoundMaxVolume(float volume)
Set the sound max volume.
void SetSoundFadeOut(float fade_out)
Set the sound fade out duration.
void SetSoundWaveKind(WaveKind wave_kind)
Set WaveKind for the sound.
override void SetParent(Object parent_obj)
Set parent for the sound to follow.
void SoundStop()
Stops sound.
void SetSoundFadeIn(float fade_in)
Set the sound fade in duration.
void SetSoundLoop(bool loop)
Set if the sound loops.
override bool IsPlaying()
Returns true when the effect is playing, false otherwise.
void SetupFlashbangValues(float progress_mult=1.0, float visual_value_max=1.0, float sound_value_max=1.0)
protected void SetAttenuationFilter()
void Update(float deltatime)
protected bool m_Initialized
protected bool m_Visual
protected float m_HitDuration
SFX will be played ~0.5s AFTER VFX.
void FlashbangEffect(PlayerBase player, bool visual=true)
protected EffectSound m_FlashbangEffectSound
protected float m_TimeActive
protected void ResetAttenuationFilter()
protected float m_DayTimeToggle
protected float m_SoundStopTime
protected ref Timer m_DeferAttenuation
protected float m_AlphaMaxActual
protected void SetVisual(float val)
protected PlayerBase m_Player
protected float m_BreakPoint
protected float m_ProgressMultiplier
protected void StopSound()
protected float m_SoundMaxActual
protected const float SOUND_DEFER_TIME
protected PPERequester_FlashbangEffects m_Requester
protected void ClearVisual()
protected void PlaySound()
protected const float ALPHA_MAX
protected const float ALPHA_MIN
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.
override void Stop()
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,...