‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
_emp.csc
Go to the documentation of this file.
1 #using scripts\codescripts\struct;
2 
3 #using scripts\shared\clientfield_shared;
4 #using scripts\shared\system_shared;
5 #using scripts\shared\util_shared;
6 #using scripts\shared\vehicle_shared;
7 
8 #insert scripts\shared\shared.gsh;
9 #insert scripts\shared\version.gsh;
10 #insert scripts\mp\killstreaks\_killstreaks.gsh;
11 
12 
13 #using_animtree ( "mp_emp_power_core" );
14 
15 #precache( "client_fx", "killstreaks/fx_emp_core" );
16 
17 #namespace emp;
18 
19 
20 #define EMP_UPDATE_DISTANCE_DELAY 0.1
21 #define EMP_UPDATE_DISTANCE_NO_EMP_DELAY 0.7
22 
23 
24 ‪REGISTER_SYSTEM( "emp", &‪__init__, undefined )
25 
26 function ‪__init__()
27 {
30 
32 }
33 
35 {
36  level endon( "disconnect" );
37 
38  if ( !isdefined( level.emp_killstreaks ) )
39  level.emp_killstreaks = [];
40 
41  for(;;)
42  {
43  has_at_least_one_active_enemy_turret = false;
44  ArrayRemoveValue( level.emp_killstreaks, undefined );
45  local_players = GetLocalPlayers();
46 
47  foreach( local_player in local_players )
48  {
49  if ( local_player IsLocalPlayer() == false )
50  continue; // Note: a player joining a game is not a local player until after spawning in (is this a bug?)
51 
52  closest_enemy_emp = ‪emp::get_closest_enemy_emp_killstreak( local_player );
53 
54  if ( isdefined( closest_enemy_emp ) )
55  {
56  has_at_least_one_active_enemy_turret = true;
57 
58  localClientNum = local_player GetLocalClientNumber();
59  ‪update_distance_to_closest_emp( localClientNum, Distance( local_player.origin, closest_enemy_emp.origin ) );
60  }
61  }
62 
63  wait ( has_at_least_one_active_enemy_turret ? ‪EMP_UPDATE_DISTANCE_DELAY : ‪EMP_UPDATE_DISTANCE_NO_EMP_DELAY );
64  }
65 }
66 
67 function ‪get_closest_enemy_emp_killstreak( local_player )
68 {
69  closest_emp = undefined;
70  closest_emp_distance_squared = 99999999;
71 
72  foreach( emp in level.emp_killstreaks )
73  {
74  if ( emp.owner == local_player || emp.team == local_player.team )
75  continue;
76 
77  distance_squared = DistanceSquared( local_player.origin, emp.origin );
78  if ( distance_squared < closest_emp_distance_squared )
79  {
80  closest_emp = emp;
81  closest_emp_distance_squared = distance_squared;
82  }
83  }
84 
85  return closest_emp;
86 }
87 
88 function ‪update_distance_to_closest_emp( localClientNum, new_value )
89 {
90  if ( !isdefined( localClientNum ) )
91  return;
92 
93  distance_to_closest_enemy_emp_ui_model = GetUIModel( GetUIModelForController( localClientNum ), "distanceToClosestEnemyEmpKillstreak" );
94 
95  if ( isdefined( distance_to_closest_enemy_emp_ui_model ) )
96  SetUIModelValue( distance_to_closest_enemy_emp_ui_model, new_value );
97 
98  // /# IPrintLnBold( "Distance to Closest Enemy EMP: " + new_value ); #/
99 }
100 
101 function ‪emp_turret_init( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump )
102 {
103  self endon("entityshutdown");
104 
105  if ( !newVal )
106  return;
107 
108  self UseAnimTree( #animtree );
109  self SetAnimRestart( %o_turret_emp_core_deploy, 1.0, 0.0, 0.0 );
110  self SetAnimTime( %o_turret_emp_core_deploy, 0.0 );
111 }
112 
113 function ‪cleanup_fx_on_shutdown( localClientNum, handle )
114 {
115  self endon("kill_fx_cleanup");
116  self waittill( "entityshutdown" );
117  StopFx( localClientNum, handle );
118 }
119 
120 function ‪emp_turret_deploy_start( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump )
121 {
122  self endon("entityshutdown");
123 
124  self ‪util::waittill_dobj( localClientNum );
125 
126  if ( !isdefined(self) )
127  return;
128 
129  if ( newVal )
130  {
131  self thread ‪emp_turret_deploy(localClientNum);
132  }
133  else
134  {
135  self notify("kill_fx_cleanup");
136  if ( isdefined( self.fxHandle ) )
137  {
138  StopFx( localClientNum, self.fxHandle );
139  self.fxHandle = undefined;
140  }
141  }
142 }
143 
144 function ‪emp_turret_deploy( localClientNum )
145 {
146  self endon("entityshutdown");
147 
148  self UseAnimTree( #animtree );
149  self SetAnimRestart( %o_turret_emp_core_deploy, 1.0, 0.0, 1.0 );
150  length = GetAnimLength( %o_turret_emp_core_deploy );
151  wait length * 0.75;
152 
153  self UseAnimTree( #animtree );
154  self SetAnim( %o_turret_emp_core_spin, 1.0 );
155  self.fxHandle = PlayFxOnTag( localClientNum, "killstreaks/fx_emp_core", self, ‪EMP_FX_TAG );
156 
157  self thread ‪cleanup_fx_on_shutdown( localClientNum, self.fxHandle );
158 
159  wait length * 0.25;
160  self SetAnim( %o_turret_emp_core_deploy, 0.0 ); // stop deploy anim
161 }
‪emp_turret_deploy_start
‪function emp_turret_deploy_start(localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump)
Definition: _emp.csc:120
‪cleanup_fx_on_shutdown
‪function cleanup_fx_on_shutdown(localClientNum, handle)
Definition: _emp.csc:113
‪update_distance_to_closest_emp
‪function update_distance_to_closest_emp(localClientNum, new_value)
Definition: _emp.csc:88
‪EMP_UPDATE_DISTANCE_NO_EMP_DELAY
‪#define EMP_UPDATE_DISTANCE_NO_EMP_DELAY
Definition: _emp.csc:21
‪monitor_emp_killstreaks
‪function monitor_emp_killstreaks()
Definition: _emp.csc:34
‪CF_CALLBACK_ZERO_ON_NEW_ENT
‪#define CF_CALLBACK_ZERO_ON_NEW_ENT
Definition: version.gsh:103
‪VERSION_SHIP
‪#define VERSION_SHIP
Definition: version.gsh:36
‪EMP_FX_TAG
‪#define EMP_FX_TAG
Definition: _killstreaks.gsh:200
‪__init__
‪function __init__()
Definition: _emp.csc:26
‪emp_turret_init
‪function emp_turret_init(localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump)
Definition: _emp.csc:101
‪EMP_UPDATE_DISTANCE_DELAY
‪#define EMP_UPDATE_DISTANCE_DELAY
Definition: _emp.csc:20
‪CF_HOST_ONLY
‪#define CF_HOST_ONLY
Definition: version.gsh:102
‪emp_turret_deploy
‪function emp_turret_deploy(localClientNum)
Definition: _emp.csc:144
‪get_closest_enemy_emp_killstreak
‪function get_closest_enemy_emp_killstreak(local_player)
Definition: _emp.csc:67
‪REGISTER_SYSTEM
‪#define REGISTER_SYSTEM(__sys, __func_init_preload, __reqs)
Definition: shared.gsh:204
‪waittill_dobj
‪function waittill_dobj(localClientNum)
Definition: util_shared.csc:1117
‪register
‪function register()
Definition: _ai_tank.gsc:126