‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
_globallogic_utils.gsc
Go to the documentation of this file.
1 #using scripts\codescripts\struct;
2 
3 #using scripts\shared\hostmigration_shared;
4 #using scripts\shared\hud_message_shared;
5 #using scripts\shared\killstreaks_shared;
6 
7 #insert scripts\shared\shared.gsh;
8 
9 #using scripts\mp\gametypes\_globallogic_score;
10 #using scripts\mp\gametypes\_hostmigration;
11 #using scripts\mp\gametypes\_hud_message;
12 
13 #using scripts\mp\killstreaks\_killstreaks;
14 
15 #namespace globallogic_utils;
16 
17 function ‪testMenu()
18 {
19  self endon ( "death" );
20  self endon ( "disconnect" );
21 
22  for ( ;; )
23  {
24  wait ( 10.0 );
25 
26  notifyData = spawnStruct();
27  notifyData.titleText = &"MP_CHALLENGE_COMPLETED";
28  notifyData.notifyText = "wheee";
29  notifyData.sound = "mp_challenge_complete";
30 
31  self thread ‪hud_message::notifyMessage( notifyData );
32  }
33 }
34 
35 function ‪testShock()
36 {
37  self endon ( "death" );
38  self endon ( "disconnect" );
39 
40  for ( ;; )
41  {
42  wait ( 3.0 );
43 
44  numShots = randomInt( 6 );
45 
46  for ( i = 0; i < numShots; i++ )
47  {
48  iPrintLnBold( numShots );
49  self shellShock( "frag_grenade_mp", 0.2 );
50  wait ( 0.1 );
51  }
52  }
53 }
54 
55 function ‪testHPs()
56 {
57  self endon ( "death" );
58  self endon ( "disconnect" );
59 
60  hps = [];
61  hps[hps.size] = "radar";
62  hps[hps.size] = "artillery";
63  hps[hps.size] = "dogs";
64 
65  for ( ;; )
66  {
67  hp = "radar";
68  if ( self thread ‪killstreaks::give( hp ) )
69  {
70  self playLocalSound( level.killstreaks[hp].informDialog );
71  }
72 
73  wait ( 20.0 );
74  }
75 }
76 
77 
78 // returns the best guess of the exact time until the scoreboard will be displayed and player control will be lost.
79 // returns undefined if time is not known
81 {
82  if ( level.gameEnded )
83  {
84  timePassed = (getTime() - level.gameEndTime) / 1000;
85  timeRemaining = level.postRoundTime - timePassed;
86 
87  if ( timeRemaining < 0 )
88  return 0;
89 
90  return timeRemaining;
91  }
92 
93  if ( level.inOvertime )
94  return undefined;
95 
96  if ( level.timeLimit <= 0 )
97  return undefined;
98 
99  if ( !isdefined( level.startTime ) )
100  return undefined;
101 
102  timePassed = (‪getTimePassed() - level.startTime)/1000;
103  timeRemaining = (level.timeLimit * 60) - timePassed;
104 
105  return timeRemaining + level.postRoundTime;
106 }
107 
108 
110 {
111  return level.timeLimit * 60 * 1000 - ‪getTimePassed();
112 }
113 
114 function ‪registerPostRoundEvent( eventFunc )
115 {
116  if ( !isdefined( level.postRoundEvents ) )
117  level.postRoundEvents = [];
118 
119  level.postRoundEvents[level.postRoundEvents.size] = eventFunc;
120 }
121 
123 {
124  if ( !isdefined( level.postRoundEvents ) )
125  return;
126 
127  for ( i = 0 ; i < level.postRoundEvents.size ; i++ )
128  {
129  [[level.postRoundEvents[i]]]();
130  }
131 }
132 
133 function ‪getValueInRange( value, minValue, maxValue )
134 {
135  if ( value > maxValue )
136  return maxValue;
137  else if ( value < minValue )
138  return minValue;
139  else
140  return value;
141 }
142 
143 
144 function ‪isValidClass( c )
145 {
146  if ( SessionModeIsZombiesGame() )
147  {
148  assert( !isdefined( c ) );
149  return true;
150  }
151  return isdefined( c ) && c != "";
152 }
153 
154 
155 function ‪playTickingSound( gametype_tick_sound )
156 {
157  self endon("death");
158  self endon("stop_ticking");
159  level endon("game_ended");
160 
161  time = level.bombTimer;
162 
163  while(1)
164  {
165  self playSound( gametype_tick_sound );
166 
167  if ( time > 10 )
168  {
169  time -= 1;
170  wait 1;
171  }
172  else if ( time > 4 )
173  {
174  time -= .5;
175  wait .5;
176  }
177  else if ( time > 1 )
178  {
179  time -= .4;
180  wait .4;
181  }
182  else
183  {
184  time -= .3;
185  wait .3;
186  }
188  }
189 }
190 
192 {
193  self notify("stop_ticking");
194 }
195 
196 function ‪gameTimer()
197 {
198  level endon ( "game_ended" );
199 
200  level waittill("prematch_over");
201 
202  level.startTime = getTime();
203  level.discardTime = 0;
204 
205  if ( isdefined( game["roundMillisecondsAlreadyPassed"] ) )
206  {
207  level.startTime -= game["roundMillisecondsAlreadyPassed"];
208  game["roundMillisecondsAlreadyPassed"] = undefined;
209  }
210 
211  prevtime = gettime() - 1000; // need to subtract a second the first time prevtime is set
212 
213  while ( game["state"] == "playing" )
214  {
215  if ( !level.timerStopped )
216  {
217  // the wait isn't always exactly 1 second. dunno why.
218  game["timepassed"] += gettime() - prevtime;
219  }
220  if ( !level.playableTimerStopped )
221  {
222  game["playabletimepassed"] += gettime() - prevtime;
223  }
224  prevtime = gettime();
225  wait ( 1.0 );
226  }
227 }
228 
230 {
231  player = self;
232 
233  player endon( "death" );
234  player endon( "disconnect" );
235 
236  if( ‪GetRoundStartDelay() )
237  {
238  wait( ‪GetRoundStartDelay() );
239  }
240 
241  player DisableRoundStartDelay();
242 }
243 
245 {
246  waitTime = level.roundStartExplosiveDelay - ([[level.getTimePassed]]() / 1000);
247  if( waitTime > 0 )
248  {
249  return waitTime;
250  }
251 
252  return 0;
253 }
254 
256 {
257  self endon("disconnect");
258  self endon("joined_spectators");
259  self endon("death");
260 
261  if( isDefined( level.prematch_over ) && level.prematch_over )
262  {
263  ‪WAIT_SERVER_FRAME; // Delay one frame because the ps->weapFlags are geting cleared on spawn
264  }
265  else
266  {
267  level waittill("prematch_over");
268  }
269 
270  self EnableRoundStartDelay();
272 }
273 
275 {
276  if ( !isdefined( level.startTime ) )
277  return 0;
278 
279  if ( level.timerStopped )
280  return (level.timerPauseTime - level.startTime) - level.discardTime;
281  else
282  return (gettime() - level.startTime) - level.discardTime;
283 
284 }
285 
286 
287 function ‪pauseTimer( pausePlayableTimer = false )
288 {
289  level.playableTimerStopped = pausePlayableTimer;
290 
291  if ( level.timerStopped )
292  return;
293 
294  level.timerStopped = true;
295  level.timerPauseTime = gettime();
296 }
297 
298 
299 function ‪resumeTimer()
300 {
301  if ( !level.timerStopped )
302  return;
303 
304  level.timerStopped = false;
305  level.playableTimerStopped = false;
306  level.discardTime += gettime() - level.timerPauseTime;
307 }
308 
309 function ‪resumeTimerDiscardOverride( discardTime )
310 {
311  if ( !level.timerStopped )
312  return;
313 
314  level.timerStopped = false;
315  level.discardTime = discardTime;
316 }
317 
318 function ‪getScoreRemaining( team )
319 {
320  assert( IsPlayer( self ) || isdefined( team ) );
321 
322  scoreLimit = level.scoreLimit;
323 
324  if ( IsPlayer( self ) )
325  return scoreLimit - ‪globallogic_score::_getPlayerScore( self );
326  else
327  return scoreLimit - GetTeamScore( team );
328 }
329 
330 function ‪GetTeamScoreForRound( team )
331 {
332  if ( level.cumulativeRoundScores && isdefined( game["lastroundscore"][team] ) )
333  {
334  return GetTeamScore( team ) - game["lastroundscore"][team];
335  }
336 
337  return GetTeamScore( team );
338 }
339 
340 function ‪getScorePerMinute( team )
341 {
342  assert( IsPlayer( self ) || isdefined( team ) );
343 
344  minutesPassed = ( ‪getTimePassed() / ( 60 * 1000 ) ) + 0.0001;
345 
346  if ( IsPlayer( self ) )
347  return ‪globallogic_score::_getPlayerScore( self ) / minutesPassed;
348  else
349  return ‪GetTeamScoreForRound( team ) / minutesPassed;
350 }
351 
352 
354 {
355  assert( IsPlayer( self ) || isdefined( team ) );
356 
357  scorePerMinute = self ‪getScorePerMinute( team );
358  scoreRemaining = self ‪getScoreRemaining( team );
359 
360  if ( !scorePerMinute )
361  return 999999;
362 
363  return scoreRemaining / scorePerMinute;
364 }
365 
366 
367 function ‪rumbler()
368 {
369  self endon("disconnect");
370  while(1)
371  {
372  wait(0.1);
373  self PlayRumbleOnEntity( "damage_heavy" );
374  }
375 }
376 
377 
378 function ‪waitForTimeOrNotify( time, notifyname )
379 {
380  self endon( notifyname );
381  wait time;
382 }
383 
384 
385 function ‪waitForTimeOrNotifyNoArtillery( time, notifyname )
386 {
387  self endon( notifyname );
388  wait time;
389  while( isdefined( level.artilleryInProgress ) )
390  {
391  assert( level.artilleryInProgress ); // undefined or true
392  wait .25;
393  }
394 }
395 
396 
397 function ‪isHeadShot( weapon, sHitLoc, sMeansOfDeath, eInflictor )
398 {
399  if( sHitLoc != "head" && sHitLoc != "helmet" )
400  {
401  return false;
402  }
403 
404  switch( sMeansOfDeath )
405  {
406  case "MOD_MELEE":
407  case "MOD_MELEE_ASSASSINATE":
408  return false;
409  case "MOD_IMPACT":
410  if( weapon.rootWeapon != level.weaponBallisticKnife )
411  return false;
412  }
413 
414  if ( ‪killstreaks::is_killstreak_weapon( weapon ) )
415  {
416  if ( !isdefined( eInflictor ) || !isdefined( eInflictor.controlled ) || eInflictor.controlled == false )
417  {
418  return false;
419  }
420  }
421 
422  return true;
423 }
424 
425 
426 function ‪getHitLocHeight( sHitLoc )
427 {
428  switch( sHitLoc )
429  {
430  case "helmet":
431  case "head":
432  case "neck":
433  return 60;
434  case "torso_upper":
435  case "right_arm_upper":
436  case "left_arm_upper":
437  case "right_arm_lower":
438  case "left_arm_lower":
439  case "right_hand":
440  case "left_hand":
441  case "gun":
442  return 48;
443  case "torso_lower":
444  return 40;
445  case "right_leg_upper":
446  case "left_leg_upper":
447  return 32;
448  case "right_leg_lower":
449  case "left_leg_lower":
450  return 10;
451  case "right_foot":
452  case "left_foot":
453  return 5;
454  }
455  return 48;
456 }
457 
458 function ‪debugLine( start, ‪end )
459 {
460  /#
461  for ( i = 0; i < 50; i++ )
462  {
463  line( start, ‪end );
464  wait .05;
465  }
466  #/
467 }
468 
469 
470 function ‪isExcluded( entity, entityList )
471 {
472  for ( index = 0; index < entityList.size; index++ )
473  {
474  if ( entity == entityList[index] )
475  return true;
476  }
477  return false;
478 }
479 
480 
481 function ‪waitForTimeOrNotifies( desiredDelay )
482 {
483  startedWaiting = getTime();
484 
485  waitedTime = (getTime() - startedWaiting)/1000;
486 
487  if ( waitedTime < desiredDelay )
488  {
489  wait desiredDelay - waitedTime;
490  return desiredDelay;
491  }
492  else
493  {
494  return waitedTime;
495  }
496 }
497 
498 function ‪logTeamWinString( wintype, winner )
499 {
500  /#
501  log_string = wintype;
502 
503  if( isdefined( winner ) )
504  {
505  log_string = log_string + ", win: " + winner;
506  }
507 
508  foreach ( team in level.teams )
509  {
510  log_string = log_string + ", " + team + ": " + game["teamScores"][team];
511  }
512 
513  print( log_string );
514  #/
515 }
516 
‪waitTillHostMigrationDone
‪function waitTillHostMigrationDone()
Definition: hostmigration_shared.gsc:193
‪notifyMessage
‪function notifyMessage(notifyData)
Definition: hud_message_shared.gsc:214
‪getHitLocHeight
‪function getHitLocHeight(sHitLoc)
Definition: _globallogic_utils.gsc:426
‪GetTeamScoreForRound
‪function GetTeamScoreForRound(team)
Definition: _globallogic_utils.gsc:330
‪waitForTimeOrNotifies
‪function waitForTimeOrNotifies(desiredDelay)
Definition: _globallogic_utils.gsc:481
‪executePostRoundEvents
‪function executePostRoundEvents()
Definition: _globallogic_utils.gsc:122
‪timeUntilRoundEnd
‪function timeUntilRoundEnd()
Definition: _globallogic_utils.gsc:80
‪getTimeRemaining
‪function getTimeRemaining()
Definition: _globallogic_utils.gsc:109
‪rumbler
‪function rumbler()
Definition: _globallogic_utils.gsc:367
‪playTickingSound
‪function playTickingSound(gametype_tick_sound)
Definition: _globallogic_utils.gsc:155
‪isExcluded
‪function isExcluded(entity, entityList)
Definition: _globallogic_utils.gsc:470
‪getScorePerMinute
‪function getScorePerMinute(team)
Definition: _globallogic_utils.gsc:340
‪GetRoundStartDelay
‪function GetRoundStartDelay()
Definition: _globallogic_utils.gsc:244
‪pauseTimer
‪function pauseTimer(pausePlayableTimer=false)
Definition: _globallogic_utils.gsc:287
‪getEstimatedTimeUntilScoreLimit
‪function getEstimatedTimeUntilScoreLimit(team)
Definition: _globallogic_utils.gsc:353
‪registerPostRoundEvent
‪function registerPostRoundEvent(eventFunc)
Definition: _globallogic_utils.gsc:114
‪debugLine
‪function debugLine(start, end)
Definition: _globallogic_utils.gsc:458
‪isHeadShot
‪function isHeadShot(weapon, sHitLoc, sMeansOfDeath, eInflictor)
Definition: _globallogic_utils.gsc:397
‪testMenu
‪function testMenu()
Definition: _globallogic_utils.gsc:17
‪resumeTimer
‪function resumeTimer()
Definition: _globallogic_utils.gsc:299
‪_getPlayerScore
‪function _getPlayerScore(player)
Definition: _globallogic_score.gsc:538
‪getTimePassed
‪function getTimePassed()
Definition: _globallogic_utils.gsc:274
‪is_killstreak_weapon
‪function is_killstreak_weapon(weapon)
Definition: killstreaks_shared.gsc:16
‪waitForTimeOrNotify
‪function waitForTimeOrNotify(time, notifyname)
Definition: _globallogic_utils.gsc:378
‪gameTimer
‪function gameTimer()
Definition: _globallogic_utils.gsc:196
‪end
‪function end(final)
Definition: _killcam.gsc:511
‪logTeamWinString
‪function logTeamWinString(wintype, winner)
Definition: _globallogic_utils.gsc:498
‪isValidClass
‪function isValidClass(c)
Definition: _globallogic_utils.gsc:144
‪testShock
‪function testShock()
Definition: _globallogic_utils.gsc:35
‪getValueInRange
‪function getValueInRange(value, minValue, maxValue)
Definition: _globallogic_utils.gsc:133
‪resumeTimerDiscardOverride
‪function resumeTimerDiscardOverride(discardTime)
Definition: _globallogic_utils.gsc:309
‪ApplyRoundStartDelay
‪function ApplyRoundStartDelay()
Definition: _globallogic_utils.gsc:255
‪DisablePlayerRoundStartDelay
‪function DisablePlayerRoundStartDelay()
Definition: _globallogic_utils.gsc:229
‪waitForTimeOrNotifyNoArtillery
‪function waitForTimeOrNotifyNoArtillery(time, notifyname)
Definition: _globallogic_utils.gsc:385
‪stopTickingSound
‪function stopTickingSound()
Definition: _globallogic_utils.gsc:191
‪give
‪function give(killstreakType, streak, suppressNotification, noXP, toBottom)
Definition: _killstreaks.gsc:539
‪getScoreRemaining
‪function getScoreRemaining(team)
Definition: _globallogic_utils.gsc:318
‪testHPs
‪function testHPs()
Definition: _globallogic_utils.gsc:55
‪WAIT_SERVER_FRAME
‪#define WAIT_SERVER_FRAME
Definition: shared.gsh:265