Advertisement
Guest User

_healthoverlay.gsc

a guest
Nov 22nd, 2013
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. init()
  2. {
  3. precacheShader("overlay_low_health");
  4.  
  5. level.healthOverlayCutoff = 0.55; // getting the dvar value directly doesn't work right because it's a client dvar getdvarfloat("hud_healthoverlay_pulseStart");
  6.  
  7. regenTime = 5;
  8.  
  9. level.playerHealth_RegularRegenDelay = regenTime * 1000;
  10.  
  11. level.healthRegenDisabled = (level.playerHealth_RegularRegenDelay <= 0);
  12.  
  13. level thread onPlayerConnect();
  14. }
  15.  
  16. onPlayerConnect()
  17. {
  18. for(;;)
  19. {
  20. level waittill("connecting", player);
  21. player thread onPlayerSpawned();
  22. player thread onPlayerKilled();
  23. player thread onJoinedTeam();
  24. player thread onJoinedSpectators();
  25. player thread onPlayerDisconnect();
  26. }
  27. }
  28.  
  29. onJoinedTeam()
  30. {
  31. self endon("disconnect");
  32.  
  33. for(;;)
  34. {
  35. self waittill("joined_team");
  36. self notify("end_healthregen");
  37. }
  38. }
  39.  
  40. onJoinedSpectators()
  41. {
  42. self endon("disconnect");
  43.  
  44. for(;;)
  45. {
  46. self waittill("joined_spectators");
  47. self notify("end_healthregen");
  48. }
  49. }
  50.  
  51. onPlayerSpawned()
  52. {
  53. self endon("disconnect");
  54.  
  55. for(;;)
  56. {
  57. self waittill("spawned_player");
  58. self thread playerHealthRegen();
  59. }
  60. }
  61.  
  62. onPlayerKilled()
  63. {
  64. self endon("disconnect");
  65.  
  66. for(;;)
  67. {
  68. self waittill("killed_player");
  69. self notify("end_healthregen");
  70. }
  71. }
  72.  
  73. onPlayerDisconnect()
  74. {
  75. self waittill("disconnect");
  76. self notify("end_healthregen");
  77. }
  78.  
  79. playerHealthRegen()
  80. {
  81. self endon("end_healthregen");
  82.  
  83. if ( self.health <= 0 )
  84. {
  85. assert( !isalive( self ) );
  86. return;
  87. }
  88.  
  89. maxhealth = self.health;
  90. oldhealth = maxhealth;
  91. player = self;
  92. health_add = 0;
  93.  
  94. regenRate = 0.1; // 0.017;
  95. veryHurt = false;
  96.  
  97. player.breathingStopTime = -10000;
  98.  
  99. thread playerBreathingSound(maxhealth * 0.35);
  100.  
  101. lastSoundTime_Recover = 0;
  102. hurtTime = 0;
  103. newHealth = 0;
  104.  
  105. for (;;)
  106. {
  107. wait (0.05);
  108. if (player.health == maxhealth)
  109. {
  110. veryHurt = false;
  111. self.atBrinkOfDeath = false;
  112. continue;
  113. }
  114.  
  115. if (player.health <= 0)
  116. return;
  117.  
  118. wasVeryHurt = veryHurt;
  119. ratio = player.health / maxHealth;
  120. if (ratio <= level.healthOverlayCutoff)
  121. {
  122. veryHurt = true;
  123. self.atBrinkOfDeath = true;
  124. if (!wasVeryHurt)
  125. {
  126. hurtTime = gettime();
  127. }
  128. }
  129.  
  130. if (player.health >= oldhealth)
  131. {
  132. if (gettime() - hurttime < level.playerHealth_RegularRegenDelay)
  133. continue;
  134.  
  135. if ( level.healthRegenDisabled )
  136. continue;
  137.  
  138. if (gettime() - lastSoundTime_Recover > level.playerHealth_RegularRegenDelay)
  139. {
  140. lastSoundTime_Recover = gettime();
  141. self playLocalSound("breathing_better");
  142. }
  143.  
  144. if (veryHurt)
  145. {
  146. newHealth = ratio;
  147. if (gettime() > hurtTime + 3000)
  148. newHealth += regenRate;
  149. }
  150. else
  151. newHealth = 1;
  152.  
  153. if ( newHealth >= 1.0 )
  154. {
  155. if ( veryHurt )
  156. self maps\mp\gametypes\_missions::healthRegenerated();
  157. newHealth = 1.0;
  158. }
  159.  
  160. if (newHealth <= 0)
  161. {
  162. // Player is dead
  163. return;
  164. }
  165.  
  166. player setnormalhealth (newHealth);
  167. oldhealth = player.health;
  168. continue;
  169. }
  170.  
  171. oldhealth = player.health;
  172.  
  173. health_add = 0;
  174. hurtTime = gettime();
  175. player.breathingStopTime = hurtTime + 6000;
  176. }
  177. }
  178.  
  179. playerBreathingSound(healthcap)
  180. {
  181. self endon("end_healthregen");
  182.  
  183. wait (2);
  184. player = self;
  185. for (;;)
  186. {
  187. wait (0.2);
  188. if (player.health <= 0)
  189. return;
  190.  
  191. // Player still has a lot of health so no breathing sound
  192. if (player.health >= healthcap)
  193. continue;
  194.  
  195. if ( level.healthRegenDisabled && gettime() > player.breathingStopTime )
  196. continue;
  197.  
  198. player playLocalSound("breathing_hurt");
  199. wait .784;
  200. wait (0.1 + randomfloat (0.8));
  201. }
  202. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement