‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
util_shared.csc
Go to the documentation of this file.
1 #using scripts\shared\flagsys_shared;
2 #using scripts\shared\trigger_shared;
3 #using scripts\shared\util_shared;
4 
5 #insert scripts\shared\shared.gsh;
6 
7 #define MAX_CLIENT_OBJECTIVE_IDS 32
8 
9 /*
10  util.gsc
11 
12  This is a utility script common to all game modes. Don't add anything with calls to game type
13  specific script API calls.
14 */
15 
16 #namespace util;
17 
32 function ‪empty( ‪a, b, c, d, e )
33 {
34 }
35 
37 {
38  localClient = 0;
39 
40  if(!isdefined(level.localPlayers))
41  {
42  while(!isdefined(level.localPlayers))
43  {
45  }
46  }
47 
48  while( level.localPlayers.size <= 0 )
49  {
51  }
52 
53  while (localClient < level.localPlayers.size)
54  {
55  ‪waitforclient(localClient);
56  localClient++;
57  }
58 }
59 
60 function ‪waitforclient(client)
61 {
62  while(!clienthassnapshot(client))
63  {
65  }
66  //syncsystemstates(client);
67 }
68 
69 function ‪get_dvar_float_default( str_dvar, default_val )
70 {
71  value = GetDvarString( str_dvar );
72  return ( value != "" ? Float( value ) : default_val );
73 }
74 
75 function ‪get_dvar_int_default( str_dvar, default_val )
76 {
77  value = GetDvarString( str_dvar );
78  return ( value != "" ? Int( value ) : default_val );
79 }
80 
92 function ‪spawn_model( n_client, str_model, origin = ( 0, 0, 0 ), angles = ( 0, 0, 0 ) )
93 {
94  model = ‪Spawn( n_client, origin, "script_model" );
95  model SetModel( str_model );
96  model.angles = angles;
97  return model;
98 }
99 
100 // ----------------------------------------------------------------------------------------------------
101 // -- Arrays ------------------------------------------------------------------------------------------
102 // ----------------------------------------------------------------------------------------------------
103 
104 function ‪waittill_string( msg, ent )
105 {
106  if ( msg != "entityshutdown" )
107  {
108  self endon ("entityshutdown");
109  }
110 
111  ent endon( "die" );
112  self waittill( msg );
113  ent notify( "returned", msg );
114 }
115 
123 function ‪waittill_multiple( ... )
124 {
125  s_tracker = SpawnStruct();
126  s_tracker._wait_count = 0;
127 
128  for ( i = 0; i < vararg.size; i++ )
129  {
130  self thread ‪_waitlogic( s_tracker, vararg[ i ] );
131  }
132 
133  if ( s_tracker._wait_count > 0 )
134  {
135  s_tracker waittill( "waitlogic_finished" );
136  }
137 }
138 
147 {
148  ‪a_ents = [];
149  a_notifies = [];
150 
151  for ( i = 0; i < vararg.size; i++ )
152  {
153  if ( i % 2 )
154  {
155  ‪ARRAY_ADD( a_notifies, vararg[ i ] );
156  }
157  else
158  {
159  ‪ARRAY_ADD( ‪a_ents, vararg[ i ] );
160  }
161  }
162 
163  s_tracker = SpawnStruct();
164  s_tracker._wait_count = 0;
165 
166  for ( i = 0; i < ‪a_ents.size; i++ )
167  {
168  ent = ‪a_ents[ i ];
169 
170  if ( isdefined( ent ) )
171  {
172  ent thread ‪_waitlogic( s_tracker, a_notifies[ i ] );
173  }
174  }
175 
176  if ( s_tracker._wait_count > 0 )
177  {
178  s_tracker waittill( "waitlogic_finished" );
179  }
180 }
181 
182 function ‪_waitlogic( s_tracker, notifies )
183 {
184  s_tracker._wait_count++;
185 
186  ‪ARRAY_ADD( notifies, "entityshutdown" );
187  ‪waittill_any_array( notifies );
188 
189  s_tracker._wait_count--;
190  if ( s_tracker._wait_count == 0 )
191  {
192  s_tracker notify( "waitlogic_finished" );
193  }
194 }
195 
212 function ‪waittill_any_return( string1, string2, string3, string4, string5, string6, string7 )
213 {
214  if ((!isdefined (string1) || string1 != "entityshutdown") &&
215  (!isdefined (string2) || string2 != "entityshutdown") &&
216  (!isdefined (string3) || string3 != "entityshutdown") &&
217  (!isdefined (string4) || string4 != "entityshutdown") &&
218  (!isdefined (string5) || string5 != "entityshutdown") &&
219  (!isdefined (string6) || string6 != "entityshutdown") &&
220  (!isdefined (string7) || string7 != "entityshutdown"))
221  self endon ("entityshutdown");
222 
223  ent = SpawnStruct();
224 
225  if (isdefined (string1))
226  self thread ‪waittill_string (string1, ent);
227 
228  if (isdefined (string2))
229  self thread ‪waittill_string (string2, ent);
230 
231  if (isdefined (string3))
232  self thread ‪waittill_string (string3, ent);
233 
234  if (isdefined (string4))
235  self thread ‪waittill_string (string4, ent);
236 
237  if (isdefined (string5))
238  self thread ‪waittill_string (string5, ent);
239 
240  if (isdefined (string6))
241  self thread ‪waittill_string (string6, ent);
242 
243  if (isdefined (string7))
244  self thread ‪waittill_string (string7, ent);
245 
246  ent waittill ("returned", msg);
247  ent notify ("die");
248  return msg;
249 }
250 
251 
270 function ‪waittill_any_ex( ... )
271 {
272  s_common = SpawnStruct();
273 
274  // You can run on an ent if you like instead of passing in an ent as the first argument.
275  e_current = self;
276 
277  // if the first parameter is a number, it's a timeout value
278  n_arg_index = 0;
279  if ( StrIsNumber( vararg[ 0 ] ) )
280  {
281  n_timeout = vararg[ 0 ];
282  n_arg_index++;
283 
284  if ( n_timeout > 0 )
285  {
286  s_common thread ‪_timeout( n_timeout );
287  }
288  }
289 
290  // If we have an array, use that as the argument list
291  if ( IsArray( vararg[ n_arg_index ] ) )
292  {
293  a_params = vararg[ n_arg_index ];
294  n_start_index = 0;
295  }
296  // Otherwise use the full parameter list.
297  else
298  {
299  a_params = vararg;
300  n_start_index = n_arg_index;
301  }
302 
303  // Run through the parameter list.
304  // If the parameter is a string, assume it's for the last specified ent
305  // If the paramter is not a string, assume it's a new ent specification.
306  for( i=n_start_index; i<a_params.size; i++ )
307  {
308  if ( !IsString( a_params[i] ) )
309  {
310  // Non string parameter == ent specification. All strings that follow are notifies to wait for on this ent.
311  e_current = a_params[i];
312  }
313  else
314  {
315  // string parameter == notify to check for
316  if ( isdefined( e_current ) )
317  {
318  e_current thread ‪waittill_string ( a_params[i], s_common );
319  }
320  }
321  }
322 
323  s_common waittill ( "returned", str_notify );
324  s_common notify ( "die" );
325  return str_notify;
326 }
327 
328 
339 function ‪waittill_any_array_return( a_notifies )
340 {
341  if ( IsInArray( a_notifies, "entityshutdown" ) )
342  {
343  self endon("entityshutdown");
344  }
345 
346  s_tracker = SpawnStruct();
347 
348  foreach ( str_notify in a_notifies )
349  {
350  if ( isdefined( str_notify ) )
351  {
352  self thread ‪waittill_string( str_notify, s_tracker );
353  }
354  }
355 
356  s_tracker waittill( "returned", msg );
357  s_tracker notify( "die" );
358  return msg;
359 }
360 
375 function ‪waittill_any( str_notify1, str_notify2, str_notify3, str_notify4, str_notify5 )
376 {
377  Assert( isdefined( str_notify1 ) );
378 
379  ‪waittill_any_array( ‪array( str_notify1, str_notify2, str_notify3, str_notify4, str_notify5 ) );
380 }
381 
392 function ‪waittill_any_array( a_notifies )
393 {
394  assert( isdefined( a_notifies[0] ),
395  "At least the first element has to be defined for waittill_any_array." );
396 
397  for ( i = 1; i < a_notifies.size; i++ )
398  {
399  if ( isdefined( a_notifies[i] ) )
400  {
401  self endon( a_notifies[i] );
402  }
403  }
404 
405  self waittill( a_notifies[0] );
406 }
407 
423 function ‪waittill_any_timeout( n_timeout, string1, string2, string3, string4, string5 )
424 {
425  if ( ( !isdefined( string1 ) || string1 != "entityshutdown" ) &&
426  ( !isdefined( string2 ) || string2 != "entityshutdown" ) &&
427  ( !isdefined( string3 ) || string3 != "entityshutdown" ) &&
428  ( !isdefined( string4 ) || string4 != "entityshutdown" ) &&
429  ( !isdefined( string5 ) || string5 != "entityshutdown" ) )
430  self endon( "entityshutdown" );
431 
432  ent = spawnstruct();
433 
434  if ( isdefined( string1 ) )
435  self thread ‪waittill_string( string1, ent );
436 
437  if ( isdefined( string2 ) )
438  self thread ‪waittill_string( string2, ent );
439 
440  if ( isdefined( string3 ) )
441  self thread ‪waittill_string( string3, ent );
442 
443  if ( isdefined( string4 ) )
444  self thread ‪waittill_string( string4, ent );
445 
446  if ( isdefined( string5 ) )
447  self thread ‪waittill_string( string5, ent );
448 
449  ent thread ‪_timeout( n_timeout );
450 
451  ent waittill( "returned", msg );
452  ent notify( "die" );
453  return msg;
454 }
455 
457 {
458  self endon( "die" );
459 
460  wait( ‪delay );
461  self notify( "returned", "timeout" );
462 }
463 
474 {
475  self endon( msg );
476  wait( ‪timer );
477 }
478 
496 function ‪waittill_any_ents( ent1, string1, ent2, string2, ent3, string3, ent4, string4, ent5, string5, ent6, string6,ent7, string7 )
497 {
498  assert( isdefined( ent1 ) );
499  assert( isdefined( string1 ) );
500 
501  if ( ( isdefined( ent2 ) ) && ( isdefined( string2 ) ) )
502  ent2 endon( string2 );
503 
504  if ( ( isdefined( ent3 ) ) && ( isdefined( string3 ) ) )
505  ent3 endon( string3 );
506 
507  if ( ( isdefined( ent4 ) ) && ( isdefined( string4 ) ) )
508  ent4 endon( string4 );
509 
510  if ( ( isdefined( ent5 ) ) && ( isdefined( string5 ) ) )
511  ent5 endon( string5 );
512 
513  if ( ( isdefined( ent6 ) ) && ( isdefined( string6 ) ) )
514  ent6 endon( string6 );
515 
516  if ( ( isdefined( ent7 ) ) && ( isdefined( string7 ) ) )
517  ent7 endon( string7 );
518 
519  ent1 waittill( string1 );
520 }
521 
535 function ‪waittill_any_ents_two( ent1, string1, ent2, string2 )
536 {
537  assert( isdefined( ent1 ) );
538  assert( isdefined( string1 ) );
539 
540  if ( ( isdefined( ent2 ) ) && ( isdefined( string2 ) ) )
541  ent2 endon( string2 );
542 
543  ent1 waittill( string1 );
544 }
545 
563 function ‪single_func( entity, func, arg1, arg2, arg3, arg4, arg5, arg6 )
564 {
565  if ( !isdefined( entity ) )
566  {
567  entity = level;
568  }
569 
570  if ( isdefined( arg6 ) )
571  {
572  return entity [[ func ]]( arg1, arg2, arg3, arg4, arg5, arg6 );
573  }
574  else if ( isdefined( arg5 ) )
575  {
576  return entity [[ func ]]( arg1, arg2, arg3, arg4, arg5 );
577  }
578  else if ( isdefined( arg4 ) )
579  {
580  return entity [[ func ]]( arg1, arg2, arg3, arg4 );
581  }
582  else if ( isdefined( arg3 ) )
583  {
584  return entity [[ func ]]( arg1, arg2, arg3 );
585  }
586  else if ( isdefined( arg2 ) )
587  {
588  return entity [[ func ]]( arg1, arg2 );
589  }
590  else if ( isdefined( arg1 ) )
591  {
592  return entity [[ func ]]( arg1 );
593  }
594  else
595  {
596  return entity [[ func ]]();
597  }
598 }
599 
616 function ‪new_func( func, arg1, arg2, arg3, arg4, arg5, arg6 )
617 {
618  s_func = SpawnStruct();
619  s_func.func = func;
620  s_func.arg1 = arg1;
621  s_func.arg2 = arg2;
622  s_func.arg3 = arg3;
623  s_func.arg4 = arg4;
624  s_func.arg5 = arg5;
625  s_func.arg6 = arg6;
626  return s_func;
627 }
628 
639 function ‪call_func( s_func )
640 {
641  return ‪single_func( self, s_func.func, s_func.arg1, s_func.arg2, s_func.arg3, s_func.arg4, s_func.arg5, s_func.arg6 );
642 }
643 
660 function ‪array_ent_thread( entities, func, arg1, arg2, arg3, arg4, arg5 )
661 {
662  Assert( isdefined( entities ), "Undefined entity array passed to util::array_ent_thread" );
663  Assert( isdefined( func ), "Undefined function passed to util::array_ent_thread" );
664 
665  if ( IsArray( entities ) )
666  {
667  if ( entities.size )
668  {
669  keys = GetArrayKeys( entities );
670  for ( i = 0; i < keys.size; i++ )
671  {
672  ‪single_thread( self, func, entities[keys[i]], arg1, arg2, arg3, arg4, arg5 );
673  }
674  }
675  }
676  else
677  {
678  ‪single_thread( self, func, entities, arg1, arg2, arg3, arg4, arg5 );
679  }
680 }
681 
699 function ‪single_thread(entity, func, arg1, arg2, arg3, arg4, arg5, arg6 )
700 {
701  Assert( isdefined( entity ), "Undefined entity passed to util::single_thread()" );
702 
703  if ( isdefined( arg6 ) )
704  {
705  entity thread [[ func ]]( arg1, arg2, arg3, arg4, arg5, arg6 );
706  }
707  else if ( isdefined( arg5 ) )
708  {
709  entity thread [[ func ]](arg1, arg2, arg3, arg4, arg5);
710  }
711  else if ( isdefined( arg4 ) )
712  {
713  entity thread [[ func ]]( arg1, arg2, arg3, arg4 );
714  }
715  else if ( isdefined( arg3 ) )
716  {
717  entity thread [[ func ]]( arg1, arg2, arg3 );
718  }
719  else if ( isdefined( arg2 ) )
720  {
721  entity thread [[ func ]]( arg1, arg2 );
722  }
723  else if ( isdefined( arg1 ) )
724  {
725  entity thread [[ func ]]( arg1 );
726  }
727  else
728  {
729  entity thread [[ func ]]();
730  }
731 }
732 
733 function ‪add_listen_thread( ‪wait_till, func, param1, param2, param3, param4, param5 )
734 {
735  level thread ‪add_listen_thread_internal( ‪wait_till, func, param1, param2, param3, param4, param5 );
736 }
737 
738 function ‪add_listen_thread_internal( ‪wait_till, func, param1, param2, param3, param4, param5 )
739 {
740  for( ;; )
741  {
742  level waittill( ‪wait_till );
743  ‪single_thread(level, func, param1, param2, param3, param4, param5);
744  }
745 }
746 
762 function ‪timeout( n_time, func, arg1, arg2, arg3, arg4, arg5, arg6 )
763 {
764  self endon( "entityshutdown" );
765  ‪TIMEOUT( n_time );
766 
767  ‪single_func( self, func, arg1, arg2, arg3, arg4, arg5, arg6 );
768 }
769 
784 function ‪delay( time_or_notify, str_endon, func, arg1, arg2, arg3, arg4, arg5, arg6 )
785 {
786  self thread ‪_delay( time_or_notify, str_endon, func, arg1, arg2, arg3, arg4, arg5, arg6 );
787 }
788 
789 function ‪_delay( time_or_notify, str_endon, func, arg1, arg2, arg3, arg4, arg5, arg6 )
790 {
791  self endon( "entityshutdown" );
792 
793  if ( isdefined( str_endon ) )
794  {
795  self endon( str_endon );
796  }
797 
798  if ( IsString( time_or_notify ) )
799  {
800  self waittill( time_or_notify );
801  }
802  else
803  {
804  wait time_or_notify;
805  }
806 
807  ‪single_func( self, func, arg1, arg2, arg3, arg4, arg5, arg6 );
808 }
809 
822 function ‪delay_notify( time_or_notify, str_notify, str_endon )
823 {
824  self thread ‪_delay_notify( time_or_notify, str_notify, str_endon );
825 }
826 
827 function ‪_delay_notify( time_or_notify, str_notify, str_endon )
828 {
829  self endon( "entityshutdown" );
830 
831  if ( isdefined( str_endon ) )
832  {
833  self endon( str_endon );
834  }
835 
836  if ( IsString( time_or_notify ) )
837  {
838  self waittill( time_or_notify );
839  }
840  else
841  {
842  wait time_or_notify;
843  }
844 
845  self notify( str_notify );
846 }
847 
848 // Time
849 
850 function ‪new_timer( n_timer_length )
851 {
852  s_timer = SpawnStruct();
853  s_timer.n_time_created = GetTime();
854  s_timer.n_length = n_timer_length;
855  return s_timer;
856 }
857 
858 function ‪get_time()
859 {
860  t_now = GetTime();
861  return t_now - self.n_time_created;
862 }
863 
865 {
866  return ‪get_time() / 1000;
867 }
868 
869 function ‪get_time_frac( n_end_time )
870 {
871  ‪DEFAULT( n_end_time, self.n_length );
872  return ( LerpFloat( 0, 1, ‪get_time_in_seconds() / n_end_time ) );
873 }
874 
876 {
877  if ( isdefined( self.n_length ) )
878  {
879  n_current_time = ‪get_time_in_seconds();
880  return ( Max( self.n_length - n_current_time, 0 ) );
881  }
882 
883  return -1;
884 }
885 
886 function ‪is_time_left()
887 {
888  return ( ‪get_time_left() != 0 );
889 }
890 
891 function ‪timer_wait( n_wait )
892 {
893  if ( isdefined( self.n_length ) )
894  {
895  n_wait = Min( n_wait, ‪get_time_left() );
896  }
897 
898  wait n_wait;
899 
900  n_current_time = ‪get_time_in_seconds();
901 
902  return n_current_time;
903 }
904 
905 function add_remove_list( &‪a, on_off )
906 {
907  ‪DEFAULT(‪a,[]);
908  if ( on_off )
909  {
910  if ( !IsInArray( ‪a, self ) )
911  {
912  ArrayInsert(‪a,self,‪a.size);
913  }
914  }
915  else
916  {
917  ArrayRemoveValue( ‪a, self, false );
918  }
919 }
920 
921 function clean_deleted( &‪array )
922 {
923  done = false;
924  while ( !done && ‪array.size > 0 )
925  {
926  done = true;
927  foreach( key, val in ‪array )
928  {
929  if (!IsDefined(val))
930  {
931  ArrayRemoveIndex(‪array,key,false);
932  done = false;
933  break;
934  }
935  }
936  }
937 }
938 
948 function ‪get_eye()
949 {
950  if( SessionModeIsCampaignGame() )
951  {
952  if (self IsPlayer())
953  {
954  linked_ent = self GetLinkedEnt();
955  if (isdefined(linked_ent) && (GetDvarInt("cg_cameraUseTagCamera") > 0))
956  {
957  camera = linked_ent GetTagOrigin("tag_camera");
958  if (isdefined(camera))
959  {
960  return camera;
961  }
962  }
963  }
964  }
965 
966  pos = self GetEye();
967  return pos;
968 }
969 
971 {
972  arms = ‪spawn(self GetLocalClientNumber(), self.origin + ( 0, 0, -1000 ), "script_model");
973 
974  if (isdefined(level.player_viewmodel))
975  {
976  // level specific viewarms
977  arms SetModel(level.player_viewmodel);
978  }
979  else
980  {
981  // default viewarms
982  arms SetModel("c_usa_cia_masonjr_viewhands"); // updated default viewarms to match _loadout.gsc - TravisJ 12/13/2011
983  }
984 
985  return arms;
986 }
987 
988 function ‪lerp_dvar( str_dvar, n_start_val, n_end_val, n_lerp_time, b_saved_dvar, b_client_dvar, n_client = 0 )
989 {
990  ‪DEFAULT( n_start_val, GetDvarFloat( str_dvar ) );
991 
992  s_timer = ‪new_timer();
993 
994  do
995  {
996  n_time_delta = s_timer ‪timer_wait( .01666 );
997  n_curr_val = LerpFloat( n_start_val, n_end_val, n_time_delta / n_lerp_time );
998 
999  if ( ‪IS_TRUE( b_saved_dvar ) )
1000  {
1001  SetSavedDvar( str_dvar, n_curr_val );
1002  }
1003  /*else if ( IS_TRUE( b_client_dvar ) )//TODO T7 - not supported in MP
1004  {
1005  SetClientDvar( str_dvar, n_curr_val );
1006  } */
1007  else
1008  {
1009  SetDvar( str_dvar, n_curr_val );
1010  }
1011  }
1012  while ( n_time_delta < n_lerp_time );
1013 }
1014 
1015 
1016 
1018 {
1019  switch(type)
1020  {
1021  case "actor":
1022  case "vehicle":
1023  case "player":
1024  case "NA":
1025  case "general":
1026  case "trigger":
1027  case "missile":
1028  case "scriptmover":
1029  case "turret":
1030  case "plane":
1031  case "helicopter":
1032  {
1033  return true;
1034  }
1035  default:
1036  {
1037  return false;
1038  }
1039  }
1040 }
1041 
1052 function ‪wait_till_not_touching( e_to_check, e_to_touch )
1053 {
1054  Assert( isdefined( e_to_check ), "Undefined check entity passed to util::wait_till_not_touching" );
1055  Assert( isdefined( e_to_touch ), "Undefined touch entity passed to util::wait_till_not_touching" );
1056 
1057  e_to_check endon( "entityshutdown" );
1058  e_to_touch endon( "entityshutdown" );
1059 
1060  while( e_to_check IsTouching( e_to_touch ) )
1061  {
1062  wait( 0.05 );
1063  }
1064 }
1065 
1066 /#
1067 function ‪error( message )
1068 {
1069  println( "^c * ERROR * ", message );
1070  wait 0.05;
1071  }
1072 #/
1073 
1074 function ‪register_system(sSysName, cbFunc)
1075 {
1076  if(!isdefined(level._systemStates))
1077  {
1078  level._systemStates = [];
1079  }
1080 
1081  if(level._systemStates.size >= 32)
1082  {
1083  /#‪error("Max num client systems exceeded.");#/
1084  return;
1085  }
1086 
1087  if(isdefined(level._systemStates[sSysName]))
1088  {
1089  /#‪error("Attempt to re-register client system : " + sSysName);#/
1090  return;
1091  }
1092  else
1093  {
1094  level._systemStates[sSysName] = spawnstruct();
1095  level._systemStates[sSysName].callback = cbFunc;
1096  }
1097 }
1098 
1099 function ‪field_set_lighting_ent( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump )
1100 {
1101  level.light_entity = self;
1102 }
1103 
1104 function ‪field_use_lighting_ent( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump )
1105 {
1106  //TODO T7 - SetLightingEntity not on MP
1107  /*if ( newVal )
1108  {
1109  self SetLightingEntity( level.light_entity );
1110  }
1111  else
1112  {
1113  self SetLightingEntity( self );
1114  }*/
1115 }
1116 
1117 function ‪waittill_dobj(localClientNum)
1118 {
1119  while( isdefined( self ) && !(self hasdobj(localClientNum)) )
1120  {
1122  }
1123 }
1124 
1125 function ‪server_wait( localClientNum, seconds, waitBetweenChecks, level_endon )//serverwait
1126 {
1127  if ( isdefined( level_endon ) )
1128  {
1129  level endon( level_endon );
1130  }
1131 
1132  if ( level.isDemoPlaying && seconds != 0 )
1133  {
1134  if ( !isdefined( waitBetweenChecks ) )
1135  {
1136  waitBetweenChecks = 0.2;
1137  }
1138 
1139  waitCompletedSuccessfully = false;
1140  ‪startTime = level.serverTime;
1141  lastTime = ‪startTime;
1142  endTime = ‪startTime + (seconds * 1000);
1143 
1144  while( level.serverTime < endTime && level.serverTime >= lastTime )
1145  {
1146  lastTime = level.serverTime;
1147  wait( waitBetweenChecks );
1148  }
1149 
1150  if ( lastTime < level.serverTime )
1151  {
1152  waitCompletedSuccessfully = true;
1153  }
1154  }
1155  else
1156  {
1157  waitrealtime( seconds );
1158  waitCompletedSuccessfully = true;
1159  }
1160 
1161  return waitCompletedSuccessfully;
1162 }
1163 
1164 function ‪friend_not_foe( localClientIndex, predicted )//friendnotfoe
1165 {
1166  player = GetNonPredictedLocalPlayer( localClientIndex ); // Get the local client player not the predicted player
1167 
1168  // use the predicted local player when we want to see what they saw
1169  if ( ‪IS_TRUE( predicted ) || isdefined( player ) && isdefined( player.team ) && ( player.team == "spectator" ))
1170  {
1171  player = GetLocalPlayer( localClientIndex ); // if spectating use the team info from the predicted/spectated client
1172  }
1173 
1174  if ( isdefined( player ) && isdefined( player.team ))
1175  {
1176  team = player.team;
1177 
1178  // using the player team to determine team base games
1179  if ( team == "free" )
1180  {
1181  owner = self GetOwner( localClientIndex );
1182 
1183  if ( isdefined( owner ) && owner == player )
1184  {
1185  return true;
1186  }
1187  }
1188  else if ( self.team == team )
1189  {
1190  return true;
1191  }
1192  }
1193 
1194  return false;
1195 }
1196 
1197 
1198 function ‪friend_not_foe_team( localClientIndex, team, predicted )//friendnotfoe
1199 {
1200  player = GetNonPredictedLocalPlayer( localClientIndex ); // Get the local client player not the predicted player
1201 
1202  // use the predicted local player when we want to see what they saw
1203  if ( ‪IS_TRUE( predicted ) || isdefined( player ) && isdefined( player.team ) && ( player.team == "spectator" ))
1204  {
1205  player = GetLocalPlayer( localClientIndex ); // if spectating use the team info from the predicted/spectated client
1206  }
1207 
1208  if ( isdefined( player ) && isdefined( player.team ))
1209  {
1210  if ( player.team == team )
1211  {
1212  return true;
1213  }
1214  }
1215 
1216  return false;
1217 }
1218 
1219 
1220 function ‪IsEnemyPlayer( player )
1221 {
1222  assert( isdefined( player ) );
1223 
1224  if( !player IsPlayer() )
1225  return false;
1226 
1227  if( player.team != "free" )
1228  {
1229  if ( player.team == self.team )
1230  {
1231  return false;
1232  }
1233  }
1234  else
1235  {
1236  if ( player == self )
1237  {
1238  return false;
1239  }
1240  }
1241  return true;
1242 }
1243 
1244 function ‪is_player_view_linked_to_entity(localClientNum)//isplayerviewlinkedtoentity
1245 {
1246  if ( self IsDriving( localClientNum ) )
1247  {
1248  return true;
1249  }
1250 
1251  if ( self IsLocalPlayerWeaponViewOnlyLinked( ) )
1252  {
1253  return true;
1254  }
1255 
1256  return false;
1257 }
1258 
1260 {
1261  level.IsDemoPlaying = IsDemoPlaying();
1262  level.localPlayers = [];
1263  level.numGametypeReservedObjectives = [];
1264  level.releasedObjectives = [];
1265 
1266  maxLocalClients = GetMaxLocalClients();
1267  for( localClientNum = 0; localClientNum < maxLocalClients; localClientNum++ )
1268  {
1269  level.releasedObjectives[localClientNum] = [];
1270  level.numGametypeReservedObjectives[localClientNum] = 0;
1271  }
1272 
1273 
1274  util::WaitForClient( 0 );
1275  level.localPlayers = GetLocalPlayers();
1276 }
1277 
1291 function ‪within_fov( start_origin, start_angles, end_origin, fov )
1292 {
1293  normal = VectorNormalize( end_origin - start_origin );
1294  forward = AnglesToForward( start_angles );
1295  dot = VectorDot( forward, normal );
1296 
1297  return dot >= fov;
1298 }
1299 
1300 function ‪is_mature()
1301 {
1302  return IsMatureContentEnabled();
1303 }
1304 
1306 {
1307  if( !(IsMatureContentEnabled() && IsShowGibsEnabled() ))
1308  {
1309  return true;
1310  }
1311 
1312  return false;
1313 }
1314 
1315 // fancy quicker struct array handling, assumes array elements are objects with which an index can be asigned to( IE: can't do 5.struct_array_index )
1316 // also have to be sure that objects can't be a part of another structarray setup as the index position is asigned to the object
1317 
1318 function ‪registerSystem(sSysName, cbFunc)
1319 {
1320  if(!isdefined(level._systemStates))
1321  {
1322  level._systemStates = [];
1323  }
1324 
1325  if(level._systemStates.size >= 32)
1326  {
1327  /#‪error("Max num client systems exceeded.");#/
1328  return;
1329  }
1330 
1331  if(isdefined(level._systemStates[sSysName]))
1332  {
1333  /#‪error("Attempt to re-register client system : " + sSysName);#/
1334  return;
1335  }
1336  else
1337  {
1338  level._systemStates[sSysName] = spawnstruct();
1339  level._systemStates[sSysName].callback = cbFunc;
1340  }
1341 }
1342 
1344 {
1345  if ( SessionModeIsCampaignGame() )
1346  {
1347  return ‪STATS_TABLE_CP;
1348  }
1349  else if ( SessionModeIsZombiesGame() )
1350  {
1351  return ‪STATS_TABLE_ZM;
1352  }
1353  else
1354  {
1355  return ‪STATS_TABLE_MP;
1356  }
1357 }
1358 
1359 /*setFootstepEffect(name, fx)
1360 {
1361  assert(isdefined(name), "Need to define the footstep surface type.");
1362  assert(isdefined(fx), "Need to define the " + name + " effect.");
1363  if (!isdefined(level._optionalStepEffects))
1364  level._optionalStepEffects = [];
1365  level._optionalStepEffects[level._optionalStepEffects.size] = name;
1366  level._effect["step_" + name] = fx;
1367 }*/
1368 
1369 function ‪add_trigger_to_ent(ent, trig)
1370 {
1371  if(!isdefined(ent._triggers))
1372  {
1373  ent._triggers = [];
1374  }
1375 
1376  ent._triggers[trig getentitynumber()] = 1;
1377 }
1378 
1379 function ‪remove_trigger_from_ent(ent, trig)
1380 {
1381  if(!isdefined(ent._triggers))
1382  return;
1383 
1384  if(!isdefined(ent._triggers[trig getentitynumber()]))
1385  return;
1386 
1387  ent._triggers[trig getentitynumber()] = 0;
1388 }
1389 
1391 {
1392  if(!isdefined(self._triggers))
1393  return false;
1394 
1395  if(!isdefined(self._triggers[trig getentitynumber()]))
1396  return false;
1397 
1398  if(!self._triggers[trig getentitynumber()])
1399  return false;
1400 
1401  return true; // We're already in this trigger volume.
1402 }
1403 
1404 function ‪trigger_thread(ent, on_enter_payload, on_exit_payload)
1405 {
1406  ent endon("entityshutdown");
1407 
1408  if(ent ‪ent_already_in_trigger(self))
1409  return;
1410 
1411  ‪add_trigger_to_ent(ent, self);
1412 
1413 // iprintlnbold("Trigger " + self.targetname + " hit by ent " + ent getentitynumber());
1414 
1415  if(isdefined(on_enter_payload))
1416  {
1417  [[on_enter_payload]](ent);
1418  }
1419 
1420  while(isdefined(ent) && ent istouching(self))
1421  {
1423  }
1424 
1425 // iprintlnbold(ent getentitynumber() + " leaves trigger " + self.targetname + ".");
1426 
1427  if(isdefined(ent) && isdefined(on_exit_payload))
1428  {
1429  [[on_exit_payload]](ent);
1430  }
1431 
1432  if(isdefined(ent))
1433  {
1434  ‪remove_trigger_from_ent(ent, self);
1435  }
1436 }
1437 
1438 // This function differs from trigger_thread in that it does not end on entityshutdown
1439 // and it will always call the on_exit_payload even if the ent is not defined.
1440 // Use cases are on players where you want the exit to be called even if the player goes into killcam
1441 function ‪local_player_trigger_thread_always_exit( ent, on_enter_payload, on_exit_payload)
1442 {
1443  if(ent ‪ent_already_in_trigger(self))
1444  return;
1445 
1446  ‪add_trigger_to_ent(ent, self);
1447 
1448  if(isdefined(on_enter_payload))
1449  {
1450  [[on_enter_payload]](ent);
1451  }
1452 
1453  while(isdefined(ent) && ent istouching(self) && ent issplitscreenhost() )
1454  {
1456  }
1457 
1458  if(isdefined(on_exit_payload))
1459  {
1460  [[on_exit_payload]](ent);
1461  }
1462 
1463  if(isdefined(ent))
1464  {
1465  ‪remove_trigger_from_ent(ent, self);
1466  }
1467 }
1468 
1469 function ‪local_player_entity_thread( localClientNum, entity, func, arg1, arg2, arg3, arg4 )
1470 {
1471  entity endon("entityshutdown");
1472 
1473  entity ‪waittill_dobj( localClientNum );
1474 
1475  ‪single_thread(entity, func, localClientNum, arg1, arg2, arg3, arg4);
1476 }
1477 
1493 function ‪local_players_entity_thread( entity, func, arg1, arg2, arg3, arg4 )
1494 {
1495  players = level.localPlayers;
1496  for (i = 0; i < players.size; i++)
1497  {
1498  players[i] thread ‪local_player_entity_thread( i, entity, func, arg1, arg2, arg3, arg4 );
1499  }
1500 }
1501 
1502 function ‪debug_line( from, to, color, time )
1503 {
1504 /#
1505  level.debug_line = GetDvarInt( "scr_debug_line", 0 ); // debug mode, draws debugging info on screen
1506 
1507  if ( isdefined( level.debug_line ) && level.debug_line == 1.0 )
1508  {
1509  if ( !isdefined(time) )
1510  {
1511  time = 1000;
1512  }
1513  Line( from, to, color, 1, 1, time);
1514  }
1515 #/
1516 
1517 }
1518 
1519 function ‪debug_star( origin, color, time )
1520 {
1521 /#
1522  level.debug_star = GetDvarInt( "scr_debug_star", 0 ); // debug mode, draws debugging info on screen
1523 
1524  if ( isdefined( level.debug_star ) && level.debug_star == 1.0 )
1525  {
1526  if ( !isdefined(time) )
1527  {
1528  time = 1000;
1529  }
1530  if ( !isdefined(color) )
1531  {
1532  color = (1,1,1);
1533  }
1534  debugstar( origin, time, color );
1535  }
1536 #/
1537 }
1538 
1539 
1540 function ‪serverTime()
1541 {
1542  for (;;)
1543  {
1544  level.serverTime = getServerTime( 0 );
1546  }
1547 }
1548 
1549 function ‪getNextObjID( localClientNum )
1550 {
1551  nextID = 0;
1552 
1553  if ( level.releasedObjectives[localClientNum].size > 0 )
1554  {
1555  nextID = level.releasedObjectives[localClientNum][ level.releasedObjectives[localClientNum].size - 1 ];
1556  level.releasedObjectives[localClientNum][ level.releasedObjectives[localClientNum].size - 1 ] = undefined;
1557  }
1558  else
1559  {
1560  nextID = level.numGametypeReservedObjectives[localClientNum];
1561  level.numGametypeReservedObjectives[localClientNum]++;
1562  }
1563 
1564 /#
1565  //No longer an assert, but still print a warning so we know when it happens.
1566  if( nextId > ‪MAX_CLIENT_OBJECTIVE_IDS - 1 )
1567  {
1568  println("^3SCRIPT WARNING: Ran out of objective IDs");
1569  }
1570  assert( nextId < ‪MAX_CLIENT_OBJECTIVE_IDS );
1571 #/
1572 
1573  // if for some reason we ever overrun the objective array then just going
1574  // to keep using the last objective id. This should only happen in extreme
1575  // situations (ie. trying to make this happen).
1576  if ( nextId > ‪MAX_CLIENT_OBJECTIVE_IDS - 1 )
1577  nextId = ‪MAX_CLIENT_OBJECTIVE_IDS - 1;
1578 
1579  return nextID;
1580 }
1581 
1582 function ‪releaseObjID( localClientNum, objID )
1583 {
1584  assert( objID < level.numGametypeReservedObjectives[localClientNum] );
1585  for( i = 0; i < level.releasedObjectives[localClientNum].size; i++ )
1586  {
1587  if( objID == level.releasedObjectives[localClientNum][i] )
1588  return;
1589  }
1590  level.releasedObjectives[localClientNum][level.releasedObjectives[localClientNum].size] = objID;
1591 }
1592 
1593 function ‪get_next_safehouse( str_next_map )
1594 {
1595  switch( str_next_map )
1596  {
1597  case "cp_mi_sing_blackstation":
1598  case "cp_mi_sing_biodomes":
1599  case "cp_mi_sing_sgen":
1600 
1601  return "cp_sh_singapore";
1602 
1603  case "cp_mi_cairo_infection":
1604  case "cp_mi_cairo_aquifer":
1605  case "cp_mi_cairo_lotus":
1606 
1607  return "cp_sh_cairo";
1608 
1609  default:
1610 
1611  return "cp_sh_mobile";
1612  }
1613 }
1614 
1615 function ‪is_safehouse( str_next_map )
1616 {
1617  ‪DEFAULT( str_next_map, ToLower( GetDvarString( "mapname" ) ) );
1618 
1619  switch ( str_next_map )
1620  {
1621  case "cp_sh_cairo":
1622  case "cp_sh_mobile":
1623  case "cp_sh_singapore":
1624 
1625  return true;
1626 
1627  default:
1628 
1629  return false;
1630  }
1631 }
1632 
1633 
‪trigger_thread
‪function trigger_thread(ent, on_enter_payload, on_exit_payload)
Definition: util_shared.csc:1404
‪waitforclient
‪function waitforclient(client)
Definition: util_shared.csc:60
‪timeout
‪function timeout(n_time, func, arg1, arg2, arg3, arg4, arg5, arg6)
Definition: util_shared.csc:762
‪is_time_left
‪function is_time_left()
Definition: util_shared.csc:886
‪startTime
‪class AnimationAdjustmentInfoZ startTime
‪is_gib_restricted_build
‪function is_gib_restricted_build()
Definition: util_shared.csc:1305
‪empty
‪function empty(a, b, c, d, e)
Definition: util_shared.csc:32
‪waittill_any_array
‪function waittill_any_array(a_notifies)
Definition: util_shared.csc:392
‪local_player_entity_thread
‪function local_player_entity_thread(localClientNum, entity, func, arg1, arg2, arg3, arg4)
Definition: util_shared.csc:1469
‪is_player_view_linked_to_entity
‪function is_player_view_linked_to_entity(localClientNum)
Definition: util_shared.csc:1244
‪array
‪function clean_deleted array
Definition: util_shared.csc:922
‪timer
‪function timer(n_time, str_endon, x, y, height)
Definition: lui_shared.gsc:163
‪is_mature
‪function is_mature()
Definition: util_shared.csc:1300
‪waittill_any_array_return
‪function waittill_any_array_return(a_notifies)
Definition: util_shared.csc:339
‪friend_not_foe_team
‪function friend_not_foe_team(localClientIndex, team, predicted)
Definition: util_shared.csc:1198
‪within_fov
‪function within_fov(start_origin, start_angles, end_origin, fov)
Definition: util_shared.csc:1291
‪remove_trigger_from_ent
‪function remove_trigger_from_ent(ent, trig)
Definition: util_shared.csc:1379
‪waittill_any_return
‪function waittill_any_return(string1, string2, string3, string4, string5, string6, string7)
Definition: util_shared.csc:212
‪get_time_in_seconds
‪function get_time_in_seconds()
Definition: util_shared.csc:864
‪friend_not_foe
‪function friend_not_foe(localClientIndex, predicted)
Definition: util_shared.csc:1164
‪waittill_multiple_ents
‪function waittill_multiple_ents(...)
Definition: util_shared.csc:146
‪lerp_dvar
‪function lerp_dvar(str_dvar, n_start_val, n_end_val, n_lerp_time, b_saved_dvar, b_client_dvar, n_client=0)
Definition: util_shared.csc:988
‪debug_star
‪function debug_star(origin, color, time)
Definition: util_shared.csc:1519
‪is_safehouse
‪function is_safehouse(str_next_map)
Definition: util_shared.csc:1615
‪_delay
‪function _delay(time_or_notify, str_endon, func, arg1, arg2, arg3, arg4, arg5, arg6)
Definition: util_shared.csc:789
‪spawn
‪function spawn(v_origin=(0, 0, 0), v_angles=(0, 0, 0))
Definition: struct.csc:23
‪waittill_any_timeout
‪function waittill_any_timeout(n_timeout, string1, string2, string3, string4, string5)
Definition: util_shared.csc:423
‪IS_TRUE
‪#define IS_TRUE(__a)
Definition: shared.gsh:251
‪field_use_lighting_ent
‪function field_use_lighting_ent(localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump)
Definition: util_shared.csc:1104
‪add_trigger_to_ent
‪function add_trigger_to_ent(ent, trig)
Definition: util_shared.csc:1369
‪a
‪function add_remove_list a
Definition: util_shared.csc:906
‪get_dvar_int_default
‪function get_dvar_int_default(str_dvar, default_val)
Definition: util_shared.csc:75
‪delay
‪function delay(time_or_notify, str_endon, func, arg1, arg2, arg3, arg4, arg5, arg6)
Definition: util_shared.csc:784
‪waittill_multiple
‪function waittill_multiple(...)
Definition: util_shared.csc:123
‪get_time_left
‪function get_time_left()
Definition: util_shared.csc:875
‪get_next_safehouse
‪function get_next_safehouse(str_next_map)
Definition: util_shared.csc:1593
‪spawn_model
‪function spawn_model(n_client, str_model, origin=(0, 0, 0), angles=(0, 0, 0))
Definition: util_shared.csc:92
‪getNextObjID
‪function getNextObjID(localClientNum)
Definition: util_shared.csc:1549
‪STATS_TABLE_CP
‪#define STATS_TABLE_CP
Definition: shared.gsh:450
‪IsEnemyPlayer
‪function IsEnemyPlayer(player)
Definition: util_shared.csc:1220
‪spawn_player_arms
‪function spawn_player_arms()
Definition: util_shared.csc:970
‪new_func
‪function new_func(func, arg1, arg2, arg3, arg4, arg5, arg6)
Definition: util_shared.csc:616
‪_delay_notify
‪function _delay_notify(time_or_notify, str_notify, str_endon)
Definition: util_shared.csc:827
‪field_set_lighting_ent
‪function field_set_lighting_ent(localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump)
Definition: util_shared.csc:1099
‪array_ent_thread
‪function array_ent_thread(entities, func, arg1, arg2, arg3, arg4, arg5)
Definition: util_shared.csc:660
‪DEFAULT
‪#define DEFAULT(__var, __default)
Definition: shared.gsh:270
‪local_players_entity_thread
‪function local_players_entity_thread(entity, func, arg1, arg2, arg3, arg4)
Definition: util_shared.csc:1493
‪waittill_any_ex
‪function waittill_any_ex(...)
Definition: util_shared.csc:270
‪STATS_TABLE_MP
‪#define STATS_TABLE_MP
Definition: shared.gsh:451
‪add_listen_thread
‪function add_listen_thread(wait_till, func, param1, param2, param3, param4, param5)
Definition: util_shared.csc:733
‪wait_till_not_touching
‪function wait_till_not_touching(e_to_check, e_to_touch)
Definition: util_shared.csc:1052
‪MAX_CLIENT_OBJECTIVE_IDS
‪#define MAX_CLIENT_OBJECTIVE_IDS
Definition: util_shared.csc:7
‪register_system
‪function register_system(sSysName, cbFunc)
Definition: util_shared.csc:1074
‪get_time_frac
‪function get_time_frac(n_end_time)
Definition: util_shared.csc:869
‪init_utility
‪function init_utility()
Definition: util_shared.csc:1259
‪TIMEOUT
‪#define TIMEOUT(__t)
Definition: shared.gsh:218
‪waittill_notify_or_timeout
‪function waittill_notify_or_timeout(msg, timer)
Definition: util_shared.csc:473
‪get_dvar_float_default
‪function get_dvar_float_default(str_dvar, default_val)
Definition: util_shared.csc:69
‪waittill_any
‪function waittill_any(str_notify1, str_notify2, str_notify3, str_notify4, str_notify5)
Definition: util_shared.csc:375
‪ARRAY_ADD
‪#define ARRAY_ADD(__array, __item)
Definition: shared.gsh:304
‪waittill_string
‪function waittill_string(msg, ent)
Definition: util_shared.csc:104
‪new_timer
‪function new_timer(n_timer_length)
Definition: util_shared.csc:850
‪delay_notify
‪function delay_notify(time_or_notify, str_notify, str_endon)
Definition: util_shared.csc:822
‪wait_till
‪function wait_till(str_flag)
Definition: flag_shared.csc:189
‪ent_already_in_trigger
‪function ent_already_in_trigger(trig)
Definition: util_shared.csc:1390
‪local_player_trigger_thread_always_exit
‪function local_player_trigger_thread_always_exit(ent, on_enter_payload, on_exit_payload)
Definition: util_shared.csc:1441
‪debug_line
‪function debug_line(from, to, color, time)
Definition: util_shared.csc:1502
‪waittill_any_ents_two
‪function waittill_any_ents_two(ent1, string1, ent2, string2)
Definition: util_shared.csc:535
‪Spawn
‪function Spawn(parent, onDeathCallback)
Definition: _flak_drone.gsc:427
‪STATS_TABLE_ZM
‪#define STATS_TABLE_ZM
Definition: shared.gsh:452
‪waittill_any_ents
‪function waittill_any_ents(ent1, string1, ent2, string2, ent3, string3, ent4, string4, ent5, string5, ent6, string6, ent7, string7)
Definition: util_shared.csc:496
‪call_func
‪function call_func(s_func)
Definition: util_shared.csc:639
‪error
‪function error(message)
Definition: util_shared.csc:1067
‪a_ents
‪function _query_ents_by_substring_helper a_ents
Definition: util_shared.gsc:3334
‪is_valid_type_for_callback
‪function is_valid_type_for_callback(type)
Definition: util_shared.csc:1017
‪releaseObjID
‪function releaseObjID(localClientNum, objID)
Definition: util_shared.csc:1582
‪waittill_dobj
‪function waittill_dobj(localClientNum)
Definition: util_shared.csc:1117
‪waitforallclients
‪function waitforallclients()
Definition: util_shared.csc:36
‪timer_wait
‪function timer_wait(n_wait)
Definition: util_shared.csc:891
‪_waitlogic
‪function _waitlogic(s_tracker, notifies)
Definition: util_shared.csc:182
‪single_thread
‪function single_thread(entity, func, arg1, arg2, arg3, arg4, arg5, arg6)
Definition: util_shared.csc:699
‪get_time
‪function get_time()
Definition: util_shared.csc:858
‪registerSystem
‪function registerSystem(sSysName, cbFunc)
Definition: util_shared.csc:1318
‪single_func
‪function single_func(entity, func, arg1, arg2, arg3, arg4, arg5, arg6)
Definition: util_shared.csc:563
‪server_wait
‪function server_wait(localClientNum, seconds, waitBetweenChecks, level_endon)
Definition: util_shared.csc:1125
‪WAIT_CLIENT_FRAME
‪#define WAIT_CLIENT_FRAME
Definition: shared.gsh:266
‪_timeout
‪function _timeout(delay)
Definition: util_shared.csc:456
‪getStatsTableName
‪function getStatsTableName()
Definition: util_shared.csc:1343
‪add_listen_thread_internal
‪function add_listen_thread_internal(wait_till, func, param1, param2, param3, param4, param5)
Definition: util_shared.csc:738
‪get_eye
‪function get_eye()
Definition: util_shared.csc:948
‪serverTime
‪function serverTime()
Definition: util_shared.csc:1540