‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
_healthoverlay.gsc
Go to the documentation of this file.
1 #using scripts\codescripts\struct;
2 
3 #using scripts\shared\callbacks_shared;
4 #using scripts\shared\system_shared;
5 #using scripts\shared\util_shared;
6 
7 #insert scripts\shared\shared.gsh;
8 
9 #using scripts\mp\gametypes\_globallogic_player;
10 
11 //#precache( "material", "overlay_low_health" );
12 
13 #namespace healthoverlay;
14 
15 ‪REGISTER_SYSTEM( "healthoverlay", &‪__init__, undefined )
16 
17 function ‪__init__()
18 {
20 
26 
27  level.start_player_health_regen = &‪player_health_regen;
28 }
29 
30 function ‪init()
31 {
32  level.healthOverlayCutoff = 0.55; // getting the dvar value directly doesn't work right because it's a client dvar GetDvarfloat( "hud_healthoverlay_pulseStart");
33 
34  regenTime = level.playerHealthRegenTime;
35 
36  level.playerHealth_RegularRegenDelay = regenTime * 1000;
37 
38  level.healthRegenDisabled = (level.playerHealth_RegularRegenDelay <= 0);
39 }
40 
42 {
43  self notify("end_healthregen");
44 }
45 
47 {
48  self endon("end_healthregen");
49 
50  if ( self.health <= 0 )
51  {
52  assert( !isalive( self ) );
53  return;
54  }
55 
56  maxhealth = self.health;
57  oldhealth = maxhealth;
58  player = self;
59  health_add = 0;
60 
61  regenRate = 0.1; // 0.017;
62 
63  useTrueRegen = false;
64 
65  veryHurt = false;
66 
67  player.breathingStopTime = -10000;
68 
69  thread ‪player_breathing_sound(maxhealth * 0.35);
70  thread ‪player_heartbeat_sound(maxhealth * 0.35);
71 
72  lastSoundTime_Recover = 0;
73  hurtTime = 0;
74  newHealth = 0;
75 
76  for (;;)
77  {
79 
80  if( isdefined( player.regenRate ) )
81  {
82  regenRate = player.regenRate;
83  useTrueRegen = true;
84  }
85 
86  if (player.health == maxhealth)
87  {
88  veryHurt = false;
89  if ( isdefined( self.atBrinkOfDeath ) && self.atBrinkOfDeath == true )
90  {
91  self notify( "challenge_survived_from_death" );
92  }
93  self.atBrinkOfDeath = false;
94  continue;
95  }
96 
97  if (player.health <= 0)
98  return;
99 
100  if ( isdefined(player.laststand) && player.laststand )
101  continue;
102 
103  wasVeryHurt = veryHurt;
104  ratio = player.health / maxHealth;
105  if (ratio <= level.healthOverlayCutoff)
106  {
107  veryHurt = true;
108  self.atBrinkOfDeath = true;
109  self.isNearDeath = true;
110  if (!wasVeryHurt)
111  {
112  hurtTime = gettime();
113  }
114  }
115  else
116  {
117  self.isNearDeath = false;
118  }
119 
120  if (player.health >= oldhealth)
121  {
122  regenTime = level.playerHealth_RegularRegenDelay;
123 
124  if ( player HasPerk( "specialty_healthregen" ) )
125  {
126  regenTime = Int( regenTime / GetDvarfloat( "perk_healthRegenMultiplier" ) );
127  }
128 
129  if (gettime() - hurttime < regenTime)
130  continue;
131 
132  if ( level.healthRegenDisabled )
133  continue;
134 
135  if (gettime() - lastSoundTime_Recover > regenTime)
136  {
137  lastSoundTime_Recover = gettime();
138  self notify ("snd_breathing_better");
139  }
140 
141  if (veryHurt)
142  {
143  newHealth = ratio;
144  veryHurtTime = 3000;
145 
146  if ( player HasPerk( "specialty_healthregen" ) )
147  {
148  veryHurtTime = Int( veryHurtTime / GetDvarfloat( "perk_healthRegenMultiplier" ) );
149  }
150 
151  if (gettime() > hurtTime + veryHurtTime)
152  newHealth += regenRate;
153  }
154  else
155  {
156  if( useTrueRegen )
157  {
158  newHealth = ratio + regenRate;
159  }
160  else
161  {
162  newHealth = 1;
163  }
164  }
165 
166  if ( newHealth >= 1.0 )
167  {
169  newHealth = 1.0;
170  }
171 
172  if (newHealth <= 0)
173  {
174  // Player is dead
175  return;
176  }
177 
178  player setnormalhealth (newHealth);
179  ‪change = player.health - oldhealth;
180  if ( ‪change > 0 )
181  {
183  }
184  oldhealth = player.health;
185  continue;
186  }
187 
188  oldhealth = player.health;
189 
190  health_add = 0;
191  hurtTime = gettime();
192  player.breathingStopTime = hurtTime + 6000;
193  }
194 }
195 
196 function ‪decay_player_damages( decay )
197 {
198  if ( !isdefined( self.attackerDamage ) )
199  return;
200 
201  for ( i = 0; i < self.attackerDamage.size; i++ )
202  {
203  if ( !isdefined( self.attackerDamage[i] ) || !isdefined( self.attackerDamage[i].‪damage ) )
204  continue;
205 
206  self.attackerDamage[i].damage -= decay;
207  if ( self.attackerDamage[i].‪damage < 0 )
208  self.attackerDamage[i].damage = 0;
209  }
210 }
211 
212 function ‪player_breathing_sound(healthcap)
213 {
214  self endon("end_healthregen");
215 
216  wait (2);
217  player = self;
218  for (;;)
219  {
220  wait (0.2);
221  if (player.health <= 0)
222  return;
223 
224  // no breathing sounds when using remote
225  if ( player ‪util::isUsingRemote() )
226  continue;
227 
228  // Player still has a lot of health so no breathing sound
229  if (player.health >= healthcap)
230  continue;
231 
232  if ( level.healthRegenDisabled && gettime() > player.breathingStopTime )
233  continue;
234 
235 // changing to notify to enable voice specfic hurt sounds.
236  player notify ("snd_breathing_hurt");
237 
238  wait .784;
239  wait (0.1 + randomfloat (0.8));
240  }
241 }
242 function ‪player_heartbeat_sound(healthcap)
243 {
244  self endon("end_healthregen");
245  self.hearbeatwait = .2;
246  wait (2);
247  player = self;
248  for (;;)
249  {
250  wait (0.2);
251  if (player.health <= 0)
252  return;
253 
254  // no heartbeat sounds when using remote
255  if ( player ‪util::isUsingRemote() )
256  {
257  continue;
258  }
259 
260  // Player still has a lot of health so no hearbeat sound
261  if (player.health >= healthcap)
262  {
263  self.hearbeatwait = .3;
264  continue;
265  }
266 
267 
268  if ( level.healthRegenDisabled && gettime() > player.breathingStopTime )
269  {
270  self.hearbeatwait = .3;
271  continue;
272  }
273 
274  player playLocalSound("mpl_player_heartbeat");
275 
276  wait (self.hearbeatwait);
277  //println ("snd heart wait =" + self.hearbeatwait);
278 
279  if (self.hearbeatwait <= .6)
280  {
281  self.hearbeatwait = (self.hearbeatwait + .1);
282  //println ("snd heart new wait =" + self.hearbeatwait);
283  }
284  }
285 }
‪__init__
‪function __init__()
Definition: _healthoverlay.gsc:17
‪on_joined_team
‪function on_joined_team()
Definition: _battlechatter.gsc:133
‪on_start_gametype
‪function on_start_gametype(func, obj)
Definition: callbacks_shared.csc:285
‪init
‪function init()
Definition: _healthoverlay.gsc:30
‪on_disconnect
‪function on_disconnect()
Definition: _wager.gsc:88
‪isUsingRemote
‪function isUsingRemote()
Definition: util_shared.gsc:2705
‪end_health_regen
‪function end_health_regen()
Definition: _healthoverlay.gsc:41
‪damage
‪function damage(trap)
Definition: _zm_trap_electric.gsc:116
‪player_health_regen
‪function player_health_regen()
Definition: _healthoverlay.gsc:46
‪on_spawned
‪function on_spawned(func, obj)
Definition: callbacks_shared.csc:245
‪player_breathing_sound
‪function player_breathing_sound(healthcap)
Definition: _healthoverlay.gsc:212
‪player_heartbeat_sound
‪function player_heartbeat_sound(healthcap)
Definition: _healthoverlay.gsc:242
‪on_player_killed
‪function on_player_killed()
Definition: _friendicons.gsc:44
‪REGISTER_SYSTEM
‪#define REGISTER_SYSTEM(__sys, __func_init_preload, __reqs)
Definition: shared.gsh:204
‪on_joined_spectate
‪function on_joined_spectate(func, obj)
Definition: callbacks_shared.gsc:290
‪decay_player_damages
‪function decay_player_damages(decay)
Definition: _healthoverlay.gsc:196
‪change
‪function change(team)
Definition: _teams.gsc:258
‪resetAttackerList
‪function resetAttackerList()
Definition: _globallogic_player.gsc:2387
‪WAIT_SERVER_FRAME
‪#define WAIT_SERVER_FRAME
Definition: shared.gsh:265