1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
|
global function ClScreenfade_Init
global function RegisterDoomProtectionHintDamage
global function UpdateScreenFade
struct
{
var screenFade = null
int lastAlpha = -1
void functionref() screenFadeFunc
} file
void function ClScreenfade_Init()
{
RegisterSignal( "NewScreenFade" )
if ( IsSingleplayer() )
file.screenFadeFunc = UpdateScreenFade_SpFirstFrame
else
file.screenFadeFunc = UpdateScreenFadeInternal
thread PlayerPainSoundThread()
AddCallback_OnClientScriptInit( ScreenFade_AddClient )
file.screenFade = RuiCreate( $"ui/screen_fade.rpak", clGlobal.topoFullScreen, RUI_DRAW_HUD, RUI_SORT_SCREENFADE )
if ( IsLobby() )
return
RuiSetFloat3( file.screenFade, "fadeColor", <0, 0, 0> )
RuiSetFloat( file.screenFade, "fadeAlpha", 1.0 )
}
void function ScreenFade_AddClient( entity player )
{
}
void function UpdateScreenFade()
{
file.screenFadeFunc()
}
void function UpdateScreenFadeInternal()
{
table fadeParams = expect table( GetFadeParams() )
//For debugging screen fade
/*int alpha = expect int (fadeParams.a )
if ( file.lastAlpha != alpha )
printt( "Alpha changed in UpdateScreenFade to: " + alpha )
file.lastAlpha = alpha*/
RuiSetFloat3( file.screenFade, "fadeColor", < expect int( fadeParams.r ) / 255.0, expect int( fadeParams.g ) / 255.0, expect int( fadeParams.b ) / 255.0 > )
RuiSetFloat( file.screenFade, "fadeAlpha", expect int( fadeParams.a ) / 255.0 )
}
void function UpdateScreenFade_SpFirstFrame()
{
RuiSetFloat3( file.screenFade, "fadeColor", < 0, 0, 0 > )
RuiSetFloat( file.screenFade, "fadeAlpha", 255 )
file.screenFadeFunc = UpdateScreenFadeInternal
}
float g_doomProtectionHintDamage = 0.0
float g_doomProtectionHintLastShowedTime = 0.0
void function RegisterDoomProtectionHintDamage( float newAmount )
{
const float LOCKOUT_TIME = 20.0
if ( newAmount < 0.0 )
return
if ( (Time() - g_doomProtectionHintLastShowedTime) < LOCKOUT_TIME )
return
g_doomProtectionHintDamage += newAmount;
printt( "g_doomProtectionHintDamage is now:", g_doomProtectionHintDamage )
}
void function DoomProtectionHintThread()
{
const float HINT_DURATION = 4.0
const float THRESHOLD_PILOT = 1000
const float THRESHOLD_TITAN = 2000
const float FIRSTTIME_SCALE = 0.6
while ( true )
{
WaitFrame()
entity player = GetLocalViewPlayer()
if ( !IsValid( player ) )
continue;
float threshold = player.IsTitan() ? THRESHOLD_TITAN : THRESHOLD_PILOT
if ( g_doomProtectionHintLastShowedTime == 0.0 )
threshold *= FIRSTTIME_SCALE
if ( g_doomProtectionHintDamage > threshold )
{
wait 0.4
entity player = GetLocalViewPlayer()
if ( IsValid( player ) )
{
SetTimedEventNotification( HINT_DURATION, player.IsTitan() ? "#NOTIFY_HINT_TITAN_USE_FINISHERS" : "#NOTIFY_HINT_PILOTS_USE_FINISHERS" )
g_doomProtectionHintLastShowedTime = Time()
g_doomProtectionHintDamage = 0.0
}
}
}
}
string function GetPainSound( entity player, string varName )
{
var resultRaw = player.GetPlayerSettingsField( varName )
if ( resultRaw == null )
{
Assert( 0, ("Invalid player setting field: " + varName) )
return ""
}
return expect string( resultRaw )
}
void function PlayerPainSoundThread()
{
// Each layer has:
//: begin threshold (health falls below XX)
//: end threshold (health has risen back up above YY)
//: looping sound
//: endcap sound
float HEALTH_PERCENT_LAYER1 = 0.85;
float HEALTH_PERCENT_LAYER1_END = 0.85;
float HEALTH_PERCENT_LAYER2 = 0.55;
float HEALTH_PERCENT_LAYER2_END = 0.55;
float HEALTH_PERCENT_LAYER3 = 0.55;
float HEALTH_PERCENT_LAYER3_END = 0.59;
if ( shGlobal.proto_pilotHealthRegenDisabled )
{
HEALTH_PERCENT_LAYER1 *= 0.33
HEALTH_PERCENT_LAYER1_END *= 0.33
HEALTH_PERCENT_LAYER2 *= 0.33
HEALTH_PERCENT_LAYER2_END *= 0.33
HEALTH_PERCENT_LAYER3 *= 0.33
HEALTH_PERCENT_LAYER3_END *= 0.33
}
entity ourPlayer = null;
bool arePlayingLayer1 = false;
bool arePlayingLayer2 = false;
bool arePlayingLayer3 = false;
string soundLayer1Loop = ""
string soundLayer1End = ""
string soundLayer2Start = ""
string soundLayer2Loop = ""
string soundLayer3Loop = ""
string soundLayer3End = ""
while ( true )
{
bool shouldPlayLayer1 = false
bool shouldPlayLayer2 = false
bool shouldPlayLayer3 = false
bool endcapsAllowed = false
entity localViewPlayer = GetLocalViewPlayer();
if ( !IsValid( localViewPlayer ) )
{
}
else if ( !IsAlive( localViewPlayer ) )
{
}
else if ( (ourPlayer != null) && (ourPlayer != localViewPlayer) )
{
}
else if ( localViewPlayer.IsTitan() )
{
endcapsAllowed = true
}
else
{
endcapsAllowed = true
int health = localViewPlayer.GetHealth()
int maxHealth = localViewPlayer.GetMaxHealth()
float healthPercent = ((maxHealth > 0) ? (health.tofloat() / maxHealth.tofloat()) : 1.0)
if ( !arePlayingLayer1 && (healthPercent <= HEALTH_PERCENT_LAYER1) )
shouldPlayLayer1 = true
else if ( arePlayingLayer1 && (healthPercent <= HEALTH_PERCENT_LAYER1_END) )
shouldPlayLayer1 = true
if ( !arePlayingLayer2 && (healthPercent <= HEALTH_PERCENT_LAYER2) )
shouldPlayLayer2 = true
else if ( arePlayingLayer2 && (healthPercent <= HEALTH_PERCENT_LAYER2_END) )
shouldPlayLayer2 = true
if ( !arePlayingLayer3 && (healthPercent <= HEALTH_PERCENT_LAYER3) )
shouldPlayLayer3 = true
else if ( arePlayingLayer3 && (healthPercent <= HEALTH_PERCENT_LAYER3_END) )
shouldPlayLayer3 = true
}
if ( shouldPlayLayer1 != arePlayingLayer1 )
{
if ( shouldPlayLayer1 )
{
//printt( "LAYER 1 STARTS" )
arePlayingLayer1 = true
Assert( (ourPlayer == null) || (ourPlayer == localViewPlayer) )
ourPlayer = localViewPlayer
soundLayer1Loop = GetPainSound( ourPlayer, "sound_pain_layer1_loop" )
soundLayer1End = GetPainSound( ourPlayer, "sound_pain_layer1_end" )
if ( soundLayer1Loop != "" )
EmitSoundOnEntity( ourPlayer, soundLayer1Loop )
}
else
{
//printt( "LAYER 1 _stop_" )
if ( IsValid( ourPlayer ) )
{
if ( soundLayer1Loop != "" )
StopSoundOnEntity( ourPlayer, soundLayer1Loop )
if ( endcapsAllowed && (soundLayer1End != "") )
EmitSoundOnEntity( ourPlayer, soundLayer1End )
}
arePlayingLayer1 = false;
}
}
if ( shouldPlayLayer2 != arePlayingLayer2 )
{
if ( shouldPlayLayer2 )
{
//printt( "LAYER 2 STARTS" );
arePlayingLayer2 = true;
Assert( (ourPlayer == null) || (ourPlayer == localViewPlayer) )
ourPlayer = localViewPlayer;
soundLayer2Start = GetPainSound( ourPlayer, "sound_pain_layer2_start" )
soundLayer2Loop = GetPainSound( ourPlayer, "sound_pain_layer2_loop" )
EmitSoundOnEntity( ourPlayer, soundLayer2Start )
EmitSoundOnEntity( ourPlayer, soundLayer2Loop )
}
else
{
//printt( "LAYER 2 _stop_" );
if ( IsValid( ourPlayer ) )
{
if ( soundLayer2Start != "" )
StopSoundOnEntity( ourPlayer, soundLayer2Start )
if ( soundLayer2Loop != "" )
StopSoundOnEntity( ourPlayer, soundLayer2Loop )
}
arePlayingLayer2 = false;
}
}
if ( shouldPlayLayer3 != arePlayingLayer3 )
{
if ( shouldPlayLayer3 )
{
//printt( "LAYER 3 STARTS" )
arePlayingLayer3 = true
Assert( (ourPlayer == null) || (ourPlayer == localViewPlayer) )
ourPlayer = localViewPlayer
soundLayer3Loop = GetPainSound( ourPlayer, "sound_pain_layer3_loop" )
soundLayer3End = GetPainSound( ourPlayer, "sound_pain_layer3_end" )
EmitSoundOnEntity( ourPlayer, soundLayer3Loop )
}
else
{
//printt( "LAYER 3 _stop_" )
if ( IsValid( ourPlayer ) )
{
if ( soundLayer3Loop != "" )
StopSoundOnEntity( ourPlayer, soundLayer3Loop )
if ( endcapsAllowed && (soundLayer3End != "") )
EmitSoundOnEntity( ourPlayer, soundLayer3End )
}
arePlayingLayer3 = false;
}
}
if ( !arePlayingLayer1 && !arePlayingLayer2 && !arePlayingLayer3 )
ourPlayer = null
WaitFrame()
}
}
/*
void function ClientSetPilotPainFlashColor( entity player, int a )
{
player.hudElems.damageOverlayPainFlash.SetColor( 255, 255, 255, a )
if ( a > 0 )
player.hudElems.damageOverlayPainFlash.Show()
else
player.hudElems.damageOverlayPainFlash.Hide()
}
*/
|