‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
enemy_highlight.csc
Go to the documentation of this file.
1 #using scripts\codescripts\struct;
2 #using scripts\shared\util_shared;
3 #using scripts\shared\clientfield_shared;
4 
5 #insert scripts\shared\shared.gsh;
6 #insert scripts\shared\version.gsh;
7 
8 
9 function ‪enemy_highlight_display( localClientNum, materialName, size, fovPercent, traceTimeCheck, actorsOnly, allyMaterialName )
10 {
11  self notify( "enemy_highlight_display" );
12 
13  self.enemy_highlight_display = true;
14 
15  self thread ‪enemy_highlight_display_pulse( localClientNum, actorsOnly, allyMaterialName );
16  self thread ‪enemy_highlight_display_frame( localClientNum, materialName, size, fovPercent, traceTimeCheck, allyMaterialName );
17 }
18 
19 function ‪enemy_highlight_display_pulse( localClientNum, actorsOnly, allyMaterialName )
20 {
21  self endon( "enemy_highlight_display" );
22 
23  if ( !isDefined( actorsOnly ) )
24  actorsOnly = false;
25 
26  if ( !isDefined( self.enemy_highlight_elems ) )
27  self.enemy_highlight_elems = [];
28 
29  while ( isDefined( self ) )
30  {
31  // Wipe menu handles when client menus are cleaned up internally due to save_restore
32  if ( !isDefined( GetLuiMenu( localClientNum, "HudElementImage" ) ) )
33  self.enemy_highlight_elems = [];
34 
35  a_all_entities = GetEntArray( localClientNum );
36 
37  self.enemy_highlight_ents = [];
38 
39  foreach( entity in a_all_entities )
40  {
41  if( entity.type == "zbarrier" )
42  continue;
43 
44  if ( actorsOnly && entity.type != "actor" && entity.type != "player" )
45  continue;
46 
47  entNum = entity GetEntityNumber();
48 
49  isEnemy = isDefined( entity.team ) && entity.team == "axis";
50  isAlly = !isEnemy && isDefined( allyMaterialName );
51  showIt = isAlive( entity ) && (isEnemy || isAlly) && !‪IS_TRUE( entity.no_highlight );
52 
53  if ( showIt && !isDefined( self.enemy_highlight_ents[entNum] ) )
54  {
55  self.enemy_highlight_ents[entNum] = entity;
56  }
57  else if ( !showIt && isDefined( self.enemy_highlight_ents[entNum] ) )
58  {
59  self.enemy_highlight_ents[entNum] = undefined;
60 
61  if ( isDefined( self.enemy_highlight_elems[entNum] ) )
62  {
63  CloseLUIMenu( localclientnum, self.enemy_highlight_elems[entNum] );
64  self.enemy_highlight_elems[entNum] = undefined;
65  }
66  }
67  }
68 
69  wait 1.0;
70  }
71 }
72 
73 function ‪enemy_highlight_display_frame( localClientNum, materialName, size, fovPercent, traceTimeCheck, allyMaterialName )
74 {
75  self endon( "enemy_highlight_display" );
76 
77  const MENU_LIMIT = 32;
78 
79  if ( !isDefined( self.enemy_highlight_elems ) )
80  self.enemy_highlight_elems = [];
81 
82  if ( !IsDefined( traceTimeCheck ) )
83  traceTimeCheck = 1.0;
84  traceTimeCheckHalfMs = int( traceTimeCheck * 500 );
85 
86  while ( isDefined( self ) )
87  {
88  // Wipe menu handles when client menus are cleaned up internally due to save_restore
89  if ( !isDefined( GetLuiMenu( localClientNum, "HudElementImage" ) ) )
90  self.enemy_highlight_elems = [];
91 
92  // Get Player's eye and look angles
93  eye = GetLocalClientEyePos( localClientNum );
94  angles = GetLocalClientAngles( localClientNum );
95  if ( isDefined( self.vehicle_camera_pos ) )
96  {
97  eye = self.vehicle_camera_pos;
98  angles = self.vehicle_camera_ang;
99  }
100 
101  dotLimit = cos( GetLocalClientFOV( localClientNum ) * fovPercent );
102  viewDir = AnglesToForward( angles );
103 
104  visibleEnts = [];
105 
106  foreach( entNum, entity in self.enemy_highlight_ents )
107  {
108  if ( !isDefined( entity ) || !isDefined( entity.origin ) )
109  continue;
110 
111  entPos = undefined;
112  radialCoef = 0;
113 
114  isEnemy = isDefined( entity.team ) && entity.team == "axis";
115  isAlly = !isEnemy && isDefined( allyMaterialName );
116  showIt = isAlive( entity ) && (isEnemy || isAlly) && !‪IS_TRUE( entity.no_highlight ) && entity != self;
117 
118  if ( showIt && self.enemy_highlight_elems.size >= MENU_LIMIT && !isDefined( self.enemy_highlight_elems[entNum] ) )
119  showIt = false;
120 
121  if ( showIt )
122  {
123  if ( entity.type == "actor" || entity.type == "player" )
124  entPos = entity GetTagOrigin( "J_Spine4" );
125  if ( !isDefined( entPos ) )
126  entPos = entity.origin + ( 0, 0, 40 );
127  assert( isDefined( entPos ) );
128  assert( isDefined( eye ) );
129  deltaDir = VectorNormalize( entPos - eye );
130  dot = VectorDot( deltaDir, viewDir );
131  if ( dot < dotLimit )
132  showIt = false;
133  else
134  radialCoef = max( ( ( 1.0 - dot ) / ( 1.0 - dotLimit ) ) - 0.5, 0.0 );
135 
136  if ( showIt && ( !isDefined( entity.highlight_trace_next ) || entity.highlight_trace_next <= GetServerTime( localClientNum ) ) )
137  {
138  from = eye + deltaDir * 100;
139  to = entPos + deltaDir * -100;
140  trace_point = TracePoint( from, to );
141  entity.highlight_trace_result = ( trace_point["fraction"] >= 1.0 );
142  entity.highlight_trace_next = GetServerTime( localClientNum ) + ( traceTimeCheckHalfMs ) + RandomIntRange( 0, traceTimeCheckHalfMs );
143  }
144  }
145 
146  if ( showIt && entity.highlight_trace_result )
147  {
148  screenProj = Project3Dto2D( localClientNum, entPos );
149 
150  if ( !isDefined( self.enemy_highlight_elems[entNum] ) )
151  {
152  if ( isEnemy )
153  self.enemy_highlight_elems[entNum] = self ‪create_target_indicator( localClientNum, entity, materialName, size );
154  else
155  self.enemy_highlight_elems[entNum] = self ‪create_target_indicator( localClientNum, entity, allyMaterialName, size );
156  }
157 
158  elem = self.enemy_highlight_elems[entNum];
159 
160  if ( isDefined( elem ) )
161  {
162  visibleEnts[entNum] = elem;
163 
164  SetLuiMenuData( localClientNum, elem, "x", screenProj[0] - ( size * 0.5 ) );
165  SetLuiMenuData( localClientNum, elem, "y", screenProj[1] - ( size * 0.5 ) );
166  SetLuiMenuData( localClientNum, elem, "alpha", 1.0 - radialCoef );
167  if ( isEnemy )
168  {
169  // Enemy - white material
170  SetLuiMenuData( localClientNum, elem, "red", 1.0 );
171  SetLuiMenuData( localClientNum, elem, "green", 0.0 );
172  }
173  else
174  {
175  // Ally - pre-colored
176  SetLuiMenuData( localClientNum, elem, "red", 0.0 );
177  SetLuiMenuData( localClientNum, elem, "green", 1.0 );
178  }
179  }
180  }
181  }
182 
183  // Cleanup icons that no longer have a visible entity for them
184  removeEnts = [];
185  foreach ( entNum, val in self.enemy_highlight_elems )
186  {
187  if ( !isDefined( visibleEnts[entNum] ) )
188  removeEnts[entNum] = entNum;
189  }
190  foreach ( entNum, val in removeEnts )
191  {
192  CloseLUIMenu( localclientnum, self.enemy_highlight_elems[entNum] );
193  self.enemy_highlight_elems[entNum] = undefined;
194  }
195 
197  }
198 }
199 
200 function ‪enemy_highlight_display_stop( localClientNum )
201 {
202  self notify( "enemy_highlight_display" );
203  self endon( "enemy_highlight_display" );
204 
206 
207  if ( isDefined( self.enemy_highlight_elems ) )
208  {
209  foreach ( hudelem in self.enemy_highlight_elems )
210  CloseLUIMenu( localclientnum, hudelem );
211 
212  self.enemy_highlight_elems = undefined;
213  }
214 
215  self.enemy_highlight_display = undefined;
216 }
217 
218 function ‪create_target_indicator( localClientNum, entity, materialName, size ) // self = player
219 {
220  hudelem = CreateLUIMenu( localClientNum, "HudElementImage" );
221 
222  if ( isDefined( hudelem ) )
223  {
224  // These must be set prior to calling OpenLUIMenu so that the values will be subscribed and updated each frame
225 
226  SetLuiMenuData( localClientNum, hudelem, "x", 0 );
227  SetLuiMenuData( localClientNum, hudelem, "y", 0 );
228  SetLuiMenuData( localClientNum, hudelem, "width", size );
229  SetLuiMenuData( localClientNum, hudelem, "height", size );
230  SetLuiMenuData( localClientNum, hudelem, "alpha", 1.0 );
231  SetLuiMenuData( localClientNum, hudelem, "material", materialName );
232  SetLuiMenuData( localClientNum, hudelem, "red", 1.0 );
233  SetLuiMenuData( localClientNum, hudelem, "green", 0.0 );
234  SetLuiMenuData( localClientNum, hudelem, "blue", 0.0 );
235  SetLuiMenuData( localClientNum, hudelem, "zRot", 0.0 );
236 
237  OpenLUIMenu( localclientnum, hudelem );
238  }
239 
240  return hudelem;
241 }
242 
‪IS_TRUE
‪#define IS_TRUE(__a)
Definition: shared.gsh:251
‪enemy_highlight_display_stop
‪function enemy_highlight_display_stop(localClientNum)
Definition: enemy_highlight.csc:200
‪enemy_highlight_display_frame
‪function enemy_highlight_display_frame(localClientNum, materialName, size, fovPercent, traceTimeCheck, allyMaterialName)
Definition: enemy_highlight.csc:73
‪enemy_highlight_display
‪function enemy_highlight_display(localClientNum, materialName, size, fovPercent, traceTimeCheck, actorsOnly, allyMaterialName)
Definition: enemy_highlight.csc:9
‪enemy_highlight_display_pulse
‪function enemy_highlight_display_pulse(localClientNum, actorsOnly, allyMaterialName)
Definition: enemy_highlight.csc:19
‪create_target_indicator
‪function create_target_indicator(localClientNum, entity, materialName, size)
Definition: enemy_highlight.csc:218
‪WAIT_CLIENT_FRAME
‪#define WAIT_CLIENT_FRAME
Definition: shared.gsh:266