‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
_zm_playerhealth.gsc
Go to the documentation of this file.
1 #using scripts\codescripts\struct;
2 
3 #using scripts\shared\callbacks_shared;
4 #using scripts\shared\flag_shared;
5 #using scripts\shared\system_shared;
6 #using scripts\shared\util_shared;
7 #using scripts\shared\visionset_mgr_shared;
8 #using scripts\shared\clientfield_shared;
9 
10 #using scripts\zm\_util;
11 #using scripts\zm\_zm_perks;
12 
13 #insert scripts\shared\version.gsh;
14 #insert scripts\shared\shared.gsh;
15 #insert scripts\zm\_zm_playerhealth.gsh;
16 
17 #precache( "material", "overlay_low_health" );
18 
19 #namespace zm_playerhealth;
20 
21 ‪REGISTER_SYSTEM( "zm_playerhealth", &‪__init__, undefined )
22 
23 function ‪__init__()
24 {
25  ‪clientfield::register( "toplayer", "sndZombieHealth", ‪VERSION_DLC5, 1, "int" );
26 
27  level.global_damage_func_ads =&‪empty_kill_func;
28  level.global_damage_func =&‪empty_kill_func;
29 
30  level.difficultyType[ 0 ] = "easy";
31  level.difficultyType[ 1 ] = "normal";
32  level.difficultyType[ 2 ] = "hardened";
33  level.difficultyType[ 3 ] = "veteran";
34 
35  level.difficultyString[ "easy" ] = &"GAMESKILL_EASY";
36  level.difficultyString[ "normal" ] = &"GAMESKILL_NORMAL";
37  level.difficultyString[ "hardened" ] = &"GAMESKILL_HARDENED";
38  level.difficultyString[ "veteran" ] = &"GAMESKILL_VETERAN";
39 
40  level.gameSkill = 1;
41 
42  switch ( level.gameSkill )
43  {
44  case 0:
45  SetDvar ("currentDifficulty", "easy");
46  break;
47  case 1:
48  SetDvar ("currentDifficulty", "normal");
49  break;
50  case 2:
51  SetDvar ("currentDifficulty", "hardened");
52  break;
53  case 3:
54  SetDvar ("currentDifficulty", "veteran");
55  break;
56  }
57 
58 
59 
60  level.player_deathInvulnerableTime = 1700;
61  level.longRegenTime = 5000;
62  level.healthOverlayCutoff = 0.2;
63  level.invulTime_preShield = 0.35;
64  level.invulTime_onShield = 0.5;
65  level.invulTime_postShield = 0.3;
66  level.playerHealth_RegularRegenDelay = 2400;
67  level.worthyDamageRatio = 0.1;
68 
70 
71  ‪DEFAULT( level.vsmgr_prio_overlay_zm_player_health_blur, ‪ZM_HEALTH_BLUR_OVERLAY_PRIORITY );
72 
74 }
75 
77 {
78  // Make sure max health is set back to default - Needed for persistent jugg upgrade
79  // There are numerous places the health is set, this one should override them all as the player is spawned (MikeA: 12/21/12)
80  self ‪zm_perks::perk_set_max_health_if_jugg( "health_reboot", true, false );
81 
82  self notify( "noHealthOverlay" );
83  self thread ‪playerHealthRegen();
84 }
85 
87 {
90 }
91 
93 {
94  self endon("noHealthOverlay");
95 
96  self.hurtAgain = false;
97  for ( ;; )
98  {
99  self waittill( "damage", amount, attacker, dir, point, mod );
100 
101  if(isdefined(attacker) && isplayer(attacker) && attacker.team == self.team)
102  {
103  continue;
104  }
105 
106  self.hurtAgain = true;
107  self.damagePoint = point;
108  self.damageAttacker = attacker;
109  }
110 }
111 
113 {
114  self notify("playerHealthRegen");
115  self endon ("playerHealthRegen");
116  self endon ("death");
117  self endon ("disconnect");
118 
119  if( !isdefined( self.flag ) )
120  {
121  self.flag = [];
122  self.flags_lock = [];
123  }
124  if( !isdefined(self.flag["player_has_red_flashing_overlay"]) )
125  {
126  self ‪flag::init("player_has_red_flashing_overlay");
127  self ‪flag::init("player_is_invulnerable");
128  }
129  self ‪flag::clear("player_has_red_flashing_overlay");
130  self ‪flag::clear("player_is_invulnerable");
131 
132  self thread ‪healthOverlay();
133  oldratio = 1;
134  health_add = 0;
135 
136  regenRate = 0.1; // 0.017;
137 
138  veryHurt = false;
139  playerJustGotRedFlashing = false;
140 
141  invulTime = 0;
142  hurtTime = 0;
143  newHealth = 0;
144  lastinvulratio = 1;
145  self thread ‪playerHurtcheck();
146  if(!isdefined (self.veryhurt))
147  {
148  self.veryhurt = 0;
149  }
150 
151  self.boltHit = false;
152 
153  if( GetDvarString( "scr_playerInvulTimeScale" ) == "" )
154  {
155  SetDvar( "scr_playerInvulTimeScale", 1.0 );
156  }
157 
158  //CODER_MOD: King (6/11/08) - Local copy of this dvar. Calling dvar get is expensive
159  playerInvulTimeScale = GetDvarFloat( "scr_playerInvulTimeScale" );
160 
161  for( ;; )
162  {
164  waittillframeend; // if we're on hard, we need to wait until the bolt damage check before we decide what to do
165 
166  if( self.health == self.maxHealth )
167  {
168  if( self ‪flag::get( "player_has_red_flashing_overlay" ) )
169  {
170  self ‪clientfield::set_to_player( "sndZombieHealth", 0 );
171  self ‪flag::clear( "player_has_red_flashing_overlay" );
172  }
173 
174  lastinvulratio = 1;
175  playerJustGotRedFlashing = false;
176  veryHurt = false;
177  continue;
178  }
179 
180  if( self.health <= 0 )
181  {
182 
183  return;
184  }
185 
186  wasVeryHurt = veryHurt;
187  health_ratio = self.health / self.maxHealth;
188 
189  if( health_ratio <= level.healthOverlayCutoff )
190  {
191  veryHurt = true;
192 
193  if( !wasVeryHurt )
194  {
195  hurtTime = gettime();
196  self startfadingblur( 3.6, 2 );
197  //self thread player_health_visionset();
198 
199  self ‪clientfield::set_to_player( "sndZombieHealth", 1 );
200  self ‪flag::set( "player_has_red_flashing_overlay" );
201  playerJustGotRedFlashing = true;
202  }
203  }
204 
205  if( self.hurtAgain )
206  {
207  hurtTime = gettime();
208  self.hurtAgain = false;
209  }
210 
211  if( health_ratio >= oldratio )
212  {
213  if( gettime() - hurttime < level.playerHealth_RegularRegenDelay )
214  {
215  continue;
216  }
217 
218  if( veryHurt )
219  {
220  self.veryhurt = 1;
221  newHealth = health_ratio;
222  if( gettime() > hurtTime + level.longRegenTime )
223  {
224  newHealth += regenRate;
225  }
226  }
227  else
228  {
229  newHealth = 1;
230  self.veryhurt = 0;
231  }
232 
233  if( newHealth > 1.0 )
234  {
235  newHealth = 1.0;
236  }
237 
238  if( newHealth <= 0 )
239  {
240  // Player is dead
241  return;
242  }
243 
244  self setnormalhealth( newHealth );
245 
246  oldratio = self.health / self.maxHealth;
247  continue;
248  }
249  // if we're here, we have taken damage: health_ratio < oldratio.
250 
251  invulWorthyHealthDrop = lastinvulRatio - health_ratio > level.worthyDamageRatio;
252 
253  if( self.health <= 1 )
254  {
255  // if player's health is <= 1, code's player_deathInvulnerableTime has kicked in and the player won't lose health for a while.
256  // set the health to 2 so we can at least detect when they're getting hit.
257  self setnormalhealth( 2 / self.maxHealth );
258  invulWorthyHealthDrop = true;
259  }
260 
261  oldratio = self.health / self.maxHealth;
262 
263  level notify( "hit_again" );
264 
265  health_add = 0;
266  hurtTime = gettime();
267  self startfadingblur( 3, 0.8 );
268  //self thread player_health_visionset();
269 
270  if( !invulWorthyHealthDrop || playerInvulTimeScale <= 0.0 )
271  {
272 
273  continue;
274  }
275 
276  if( self ‪flag::get( "player_is_invulnerable" ) )
277  continue;
278  self ‪flag::set( "player_is_invulnerable" );
279  level notify( "player_becoming_invulnerable" ); // because "player_is_invulnerable" notify happens on both set * and * clear
280 
281  if( playerJustGotRedFlashing )
282  {
283  invulTime = level.invulTime_onShield;
284  playerJustGotRedFlashing = false;
285  }
286  else if( veryHurt )
287  {
288  invulTime = level.invulTime_postShield;
289  }
290  else
291  {
292  invulTime = level.invulTime_preShield;
293  }
294 
295  invulTime *= playerInvulTimeScale;
296 
297 
298  lastinvulratio = self.health / self.maxHealth;
299  self thread ‪playerInvul( invulTime );
300  }
301 }
302 
304 {
305  self endon( "death" );
306  self endon( "disconnect" );
307 
308  if ( ‪timer > 0 )
309  {
310  wait( ‪timer );
311  }
312 
313  self ‪flag::clear( "player_is_invulnerable" );
314 }
315 
316 
318 {
319  self endon( "disconnect" );
320  self endon( "noHealthOverlay" );
321 
322  if(!isdefined(self._health_overlay))
323  {
324  self._health_overlay = newClientHudElem( self );
325  self._health_overlay.x = 0;
326  self._health_overlay.y = 0;
327  self._health_overlay setshader( "overlay_low_health", 640, 480 );
328  self._health_overlay.alignX = "left";
329  self._health_overlay.alignY = "top";
330  self._health_overlay.horzAlign = "fullscreen";
331  self._health_overlay.vertAlign = "fullscreen";
332  self._health_overlay.alpha = 0;
333  }
334 
335  overlay = self._health_overlay;
336 
337  // CODER_MOD
338  // Austin (4/19/08): fade out the overlay for the 4/21 milestone
339  self thread ‪healthOverlay_remove( overlay );
340  self thread ‪watchHideRedFlashingOverlay( overlay );
341 
342  pulseTime = 0.8;
343  for( ;; )
344  {
345  if ( overlay.alpha > 0 )
346  overlay fadeOverTime( 0.5 );
347  overlay.alpha = 0;
348 
349  // CODER_MOD
350  // Austin (5/29/07): restore these flags as player flags, these changes were clobbered during the integrate
351  self ‪flag::wait_till( "player_has_red_flashing_overlay" );
352  self ‪redFlashingOverlay( overlay );
353  }
354 }
355 
356 function ‪fadeFunc( overlay, severity, mult, hud_scaleOnly )
357 {
358  pulseTime = 0.8;
359  scaleMin = 0.5;
360 
361  fadeInTime = pulseTime * 0.1;
362  stayFullTime = pulseTime * ( .1 + severity * .2 );
363  fadeOutHalfTime = pulseTime * ( 0.1 + severity * .1 );
364  fadeOutFullTime = pulseTime * 0.3;
365  remainingTime = pulseTime - fadeInTime - stayFullTime - fadeOutHalfTime - fadeOutFullTime;
366  assert( remainingTime >= -.001 );
367  if ( remainingTime < 0 )
368  {
369  remainingTime = 0;
370  }
371 
372  halfAlpha = 0.8 + severity * 0.1;
373  leastAlpha = 0.5 + severity * 0.3;
374 
375  overlay fadeOverTime( fadeInTime );
376  overlay.alpha = mult * 1.0;
377  wait fadeInTime + stayFullTime;
378 
379  overlay fadeOverTime( fadeOutHalfTime );
380  overlay.alpha = mult * halfAlpha;
381  wait fadeOutHalfTime;
382 
383  overlay fadeOverTime( fadeOutFullTime );
384  overlay.alpha = mult * leastAlpha;
385  wait fadeOutFullTime;
386 
387  wait remainingTime;
388 }
389 
391 {
392  self endon( "death_or_disconnect");
393 
394  while (isdefined(overlay))
395  {
396  self waittill("clear_red_flashing_overlay");
397 
398  self ‪clientfield::set_to_player( "sndZombieHealth", 0 );
399  self ‪flag::clear( "player_has_red_flashing_overlay" );
400 
401  overlay fadeOverTime( 0.05 );
402  overlay.alpha = 0;
403 
404  self notify( "hit_again" );
405  }
406 }
407 
408 function ‪redFlashingOverlay( overlay )
409 {
410  self endon( "hit_again" );
411  self endon( "damage" );
412  self endon ("death");
413  self endon ("disconnect");
414  self endon( "clear_red_flashing_overlay" );
415 
416  //prof_begin( "redFlashingOverlay" );
417 
418  // if severity isn't very high, the overlay becomes very unnoticeable to the player.
419  // keep it high while they haven't regenerated or they'll feel like their health is nearly full and they're safe to step out.
420 
421  self.stopFlashingBadlyTime = gettime() + level.longRegenTime;
422 
423  if ( !‪IS_TRUE( self.is_in_process_of_zombify ) && !‪IS_TRUE( self.‪is_zombie ) )
424  {
425  ‪fadeFunc( overlay, 1, 1, false );
426  while ( gettime() < self.stopFlashingBadlyTime && isalive( self ) && ( !‪IS_TRUE( self.is_in_process_of_zombify ) && !‪IS_TRUE( self.‪is_zombie ) ) )
427  {
428  ‪fadeFunc( overlay, .9, 1, false );
429  }
430 
431  if ( !‪IS_TRUE( self.is_in_process_of_zombify ) && !‪IS_TRUE( self.‪is_zombie ) )
432  {
433  if ( isalive( self ) )
434  {
435  ‪fadeFunc( overlay, .65, 0.8, false );
436  }
437 
438  ‪fadeFunc( overlay, 0, 0.6, true );
439  }
440  }
441 
442  overlay fadeOverTime( 0.5 );
443  overlay.alpha = 0;
444 
445  // CODER_MOD
446  // Austin (5/29/07): restore this flag as a player flag, these changes were clobbered during the integrate
447  self ‪flag::clear( "player_has_red_flashing_overlay" );
448  self ‪clientfield::set_to_player( "sndZombieHealth", 0 );
449 
450  //prof_end( "redFlashingOverlay" );
451 
452  wait( 0.5 );// for fade out
453  self notify( "hit_again" );
454 }
455 
456 function ‪healthOverlay_remove( overlay )
457 {
458  // this hud element will get cleaned up automatically by the code when the player disconnects
459  // so we just need to make sure this thread ends
460  self endon ("disconnect");
461  // CODER_MOD
462  // Austin (5/29/07): restore these they were clobbered during the integrate
463  self ‪util::waittill_any ("noHealthOverlay", "death");
464 
465  overlay fadeOverTime( 3.5 );
466  overlay.alpha = 0;
467 }
468 
469 function ‪empty_kill_func( type, loc, point, attacker, amount )
470 {
471 
472 }
473 
‪is_zombie
‪function is_zombie()
Definition: zombie_utility.gsc:1320
‪activate
‪function activate()
Definition: traps_shared.gsc:655
‪empty_kill_func
‪function empty_kill_func(type, loc, point, attacker, amount)
Definition: _zm_playerhealth.gsc:469
‪playerHealthRegen
‪function playerHealthRegen()
Definition: _zm_playerhealth.gsc:112
‪timer
‪function timer(n_time, str_endon, x, y, height)
Definition: lui_shared.gsc:163
‪fadeFunc
‪function fadeFunc(overlay, severity, mult, hud_scaleOnly)
Definition: _zm_playerhealth.gsc:356
‪playerHurtcheck
‪function playerHurtcheck()
Definition: _zm_playerhealth.gsc:92
‪set_to_player
‪function set_to_player(str_field_name, n_value)
Definition: clientfield_shared.gsc:58
‪clear
‪function clear(str_flag)
Definition: flag_shared.csc:130
‪playerInvul
‪function playerInvul(timer)
Definition: _zm_playerhealth.gsc:303
‪VERSION_SHIP
‪#define VERSION_SHIP
Definition: version.gsh:36
‪ZM_HEALTH_BLUR_SCREEN_EFFECT_NAME
‪#define ZM_HEALTH_BLUR_SCREEN_EFFECT_NAME
Definition: _zm_playerhealth.gsh:3
‪IS_TRUE
‪#define IS_TRUE(__a)
Definition: shared.gsh:251
‪get
‪function get(kvp_value, kvp_key="targetname")
Definition: struct.csc:13
‪healthOverlay
‪function healthOverlay()
Definition: _zm_playerhealth.gsc:317
‪ZM_HEALTH_BLUR_OVERLAY_DURATION_LOOP
‪#define ZM_HEALTH_BLUR_OVERLAY_DURATION_LOOP
Definition: _zm_playerhealth.gsh:17
‪watchHideRedFlashingOverlay
‪function watchHideRedFlashingOverlay(overlay)
Definition: _zm_playerhealth.gsc:390
‪ZM_HEALTH_BLUR_OVERLAY_DURATION_OUT
‪#define ZM_HEALTH_BLUR_OVERLAY_DURATION_OUT
Definition: _zm_playerhealth.gsh:18
‪DEFAULT
‪#define DEFAULT(__var, __default)
Definition: shared.gsh:270
‪on_spawned
‪function on_spawned(func, obj)
Definition: callbacks_shared.csc:245
‪waittill_any
‪function waittill_any(str_notify1, str_notify2, str_notify3, str_notify4, str_notify5)
Definition: util_shared.csc:375
‪deactivate
‪function deactivate()
Definition: traps_shared.gsc:649
‪player_health_visionset
‪function player_health_visionset()
Definition: _zm_playerhealth.gsc:86
‪wait_till
‪function wait_till(str_flag)
Definition: flag_shared.csc:189
‪REGISTER_SYSTEM
‪#define REGISTER_SYSTEM(__sys, __func_init_preload, __reqs)
Definition: shared.gsh:204
‪on_player_spawned
‪function on_player_spawned()
Definition: _zm_playerhealth.gsc:76
‪register_info
‪function register_info(type, name, version, lerp_step_count)
Definition: visionset_mgr_shared.csc:334
‪ZM_HEALTH_BLUR_OVERLAY_DURATION_IN
‪#define ZM_HEALTH_BLUR_OVERLAY_DURATION_IN
Definition: _zm_playerhealth.gsh:16
‪init
‪function init()
Definition: struct.csc:1
‪__init__
‪function __init__()
Definition: _zm_playerhealth.gsc:23
‪set
‪function set(str_field_name, n_value)
Definition: clientfield_shared.gsc:34
‪VERSION_DLC5
‪#define VERSION_DLC5
Definition: version.gsh:99
‪ZM_HEALTH_BLUR_OVERLAY_LERP_COUNT
‪#define ZM_HEALTH_BLUR_OVERLAY_LERP_COUNT
Definition: _zm_playerhealth.gsh:6
‪healthOverlay_remove
‪function healthOverlay_remove(overlay)
Definition: _zm_playerhealth.gsc:456
‪ZM_HEALTH_BLUR_OVERLAY_PRIORITY
‪#define ZM_HEALTH_BLUR_OVERLAY_PRIORITY
Definition: _zm_playerhealth.gsh:5
‪register
‪function register()
Definition: _ai_tank.gsc:126
‪redFlashingOverlay
‪function redFlashingOverlay(overlay)
Definition: _zm_playerhealth.gsc:408
‪ramp_in_out_thread_per_player
‪function ramp_in_out_thread_per_player(player, ramp_in, full_period, ramp_out)
Definition: visionset_mgr_shared.gsc:392
‪WAIT_SERVER_FRAME
‪#define WAIT_SERVER_FRAME
Definition: shared.gsh:265
‪perk_set_max_health_if_jugg
‪function perk_set_max_health_if_jugg(str_perk, set_preMaxHealth, clamp_health_to_max_health)
Definition: _zm_perks.gsc:791