‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
entityheadicons_shared.gsc
Go to the documentation of this file.
1 #using scripts\codescripts\struct;
2 
3 #using scripts\shared\callbacks_shared;
4 #using scripts\shared\gameobjects_shared;
5 #using scripts\shared\system_shared;
6 #using scripts\shared\util_shared;
7 
8 #insert scripts\shared\shared.gsh;
9 
10 #namespace entityheadicons;
11 
12 function ‪init_shared()
13 {
15 }
16 
18 {
19  if ( isdefined( level.initedEntityHeadIcons ) )
20  {
21  return;
22  }
23 
24  level.initedEntityHeadIcons = true;
25 
26  assert( isdefined(game["entity_headicon_allies"]), "Allied head icons are not defined. Check the team set for the level.");
27  assert( isdefined(game["entity_headicon_axis"]), "Axis head icons are not defined. Check the team set for the level.");
28 
29  if ( !level.teamBased )
30  {
31  return;
32  }
33 
34  if (!IsDefined(level.setEntityHeadIcon) )
35  {
36  level.setEntityHeadIcon = &‪setEntityHeadIcon;
37  }
38 
39  level.entitiesWithHeadIcons = [];
40 }
41 
42 
43 function ‪setEntityHeadIcon(team, owner, offset, objective, constant_size) // "allies", "axis", "team3", "all", "none"
44 {
45  if (!level.teamBased && !isdefined(owner) )
46  {
47  return;
48  }
49 
50  if( !isdefined( constant_size ) )
51  {
52  constant_size = false;
53  }
54 
55  if (!isdefined(self.entityHeadIconTeam))
56  {
57  self.entityHeadIconTeam = "none";
58  self.entityHeadIcons = [];
59  self.entityHeadObjectives = [];
60  }
61 
62  if ( level.teamBased && !isdefined(owner) )
63  {
64  if (team == self.entityHeadIconTeam)
65  {
66  return;
67  }
68 
69  self.entityHeadIconTeam = team;
70  }
71 
72  if (isdefined(offset))
73  {
74  self.entityHeadIconOffset = offset;
75  }
76  else
77  {
78  self.entityHeadIconOffset = (0,0,0);
79  }
80 
81  // destroy existing head icons for this entity
82  if ( isdefined( self.entityHeadIcons ) )
83  {
84  for (i = 0; i < self.entityHeadIcons.size; i++)
85  {
86  if (isdefined(self.entityHeadIcons[i]))
87  {
88  self.entityHeadIcons[i] ‪destroy();
89  }
90  }
91  }
92 
93  // destroy existing head objectives for this entity
94  if ( isdefined( self.entityHeadObjectives ) )
95  {
96  for (i = 0; i < self.entityHeadObjectives.size; i++)
97  {
98  if (isdefined(self.entityHeadObjectives[i]))
99  {
100  Objective_Delete(self.entityHeadObjectives[i]);
101  self.entityHeadObjectives[i] = undefined;
102  }
103  }
104  }
105 
106  self.entityHeadIcons = [];
107  self.entityHeadObjectives = [];
108 
109  self notify("kill_entity_headicon_thread");
110 
111  if ( !isdefined( objective ) )
112  {
113  objective = game["entity_headicon_" + team];
114  }
115 
116  if ( isdefined( objective ) )
117  {
118  if ( isdefined(owner) && !level.teamBased )
119  {
120  // sometimes owner comes in as not a player, for instance, the care package crate
121  // unfortunately the updateEntityHeadClientObjective/Icon needs to be a player entity so UI knows which player to draw it for
122  if( !IsPlayer( owner ) )
123  {
124  assert( isdefined( owner.owner ), "entity has to have an owner if it's not a player");
125  owner = owner.owner;
126  }
127  if( isstring(objective) )
128  {
129  owner ‪updateEntityHeadClientIcon(self, objective, constant_size );
130  }
131  else
132  {
133  owner ‪updateEntityHeadClientObjective(self, objective, constant_size );
134  }
135  }
136  else if ( isdefined(owner) && team != "none")
137  {
138  if( isstring(objective) )
139  {
140  owner ‪updateEntityHeadTeamIcon(self, team, objective, constant_size );
141  }
142  else
143  {
144  owner ‪updateEntityHeadTeamObjective(self, team, objective, constant_size );
145  }
146  }
147  }
148 
149  self thread ‪destroyHeadIconsOnDeath();
150 }
151 
152 function ‪updateEntityHeadTeamIcon(entity, team, icon, constant_size )
153 {
154  //hard-coded the friendly blue color
155  friendly_blue_color = ‪array( 0.584, 0.839, 0.867 );
156  headicon = NewTeamHudElem(team);
157  headicon.archived = true;
158  headicon.x = entity.entityHeadIconOffset[0];
159  headicon.y = entity.entityHeadIconOffset[1];
160  headicon.z = entity.entityHeadIconOffset[2];
161  headicon.alpha = .8;
162  headicon.color = ( friendly_blue_color[0], friendly_blue_color[1], friendly_blue_color[2] );
163  headicon setShader(icon, 6, 6);
164  headicon setwaypoint( constant_size ); // false = uniform size in 3D instead of uniform size in 2D
165  headicon SetTargetEnt( entity );
166 
167  // update entityHeadIcons arrays so we can delete this later when either the entity or the player don't want it
168  entity.entityHeadIcons[entity.entityHeadIcons.size] = headicon;
169 }
170 
171 function ‪updateEntityHeadClientIcon(entity, icon, constant_size )
172 {
173  headicon = newClientHudElem(self);
174  headicon.archived = true;
175  headicon.x = entity.entityHeadIconOffset[0];
176  headicon.y = entity.entityHeadIconOffset[1];
177  headicon.z = entity.entityHeadIconOffset[2];
178  headicon.alpha = .8;
179  headicon setShader(icon, 6, 6);
180  headicon setwaypoint( constant_size ); // false = uniform size in 3D instead of uniform size in 2D
181  headicon SetTargetEnt( entity );
182 
183  // update entityHeadIcons arrays so we can delete this later when either the entity or the player don't want it
184  entity.entityHeadIcons[entity.entityHeadIcons.size] = headicon;
185 }
186 function ‪updateEntityHeadTeamObjective(entity, team, objective, constant_size )
187 {
188  headIconObjectiveId = ‪gameobjects::get_next_obj_id();
189  Objective_Add( headIconObjectiveId, "active", entity, objective );
190  Objective_Team( headIconObjectiveId, team );
191  Objective_SetColor( headIconObjectiveId, &"FriendlyBlue" );
192 
193  // update entityHeadObjectives arrays so we can delete this later when either the entity or the player don't want it
194  entity.entityHeadObjectives[entity.entityHeadObjectives.size] = headIconObjectiveId;
195 }
196 
197 function ‪updateEntityHeadClientObjective(entity, objective, constant_size )
198 {
199  headIconObjectiveId = ‪gameobjects::get_next_obj_id();
200  Objective_Add( headIconObjectiveId, "active", entity, objective );
201  Objective_SetInvisibleToAll( headIconObjectiveId );
202  Objective_SetVisibleToPlayer( headIconObjectiveId, self );
203  Objective_SetColor( headIconObjectiveId, &"FriendlyBlue" );
204 
205  // update entityHeadObjectives arrays so we can delete this later when either the entity or the player don't want it
206  entity.entityHeadObjectives[entity.entityHeadObjectives.size] = headIconObjectiveId;
207 }
208 
210 {
211  self notify( "destroyHeadIconsOnDeath_singleton" );
212  self endon( "destroyHeadIconsOnDeath_singleton" );
213 
214  self ‪util::waittill_any ( "death", "hacked" );
215 
216  for (i = 0; i < self.entityHeadIcons.size; i++)
217  {
218  if (isdefined(self.entityHeadIcons[i]))
219  {
220  self.entityHeadIcons[i] ‪destroy();
221  }
222  }
223 
224  for (i = 0; i < self.entityHeadObjectives.size; i++)
225  {
226  if (isdefined(self.entityHeadObjectives[i]))
227  {
228  ‪gameobjects::release_obj_id( self.entityHeadObjectives[i] );
229  Objective_Delete( self.entityHeadObjectives[i] );
230  }
231  }
232 }
233 
235 {
236  if( isdefined( self.entityHeadIcons ) )
237  {
238  for (i = 0; i < self.entityHeadIcons.size; i++)
239  {
240  if (isdefined(self.entityHeadIcons[i]))
241  {
242  self.entityHeadIcons[i] ‪destroy();
243  }
244  }
245  }
246 
247  if( isdefined( self.entityHeadObjectives ) )
248  {
249  for (i = 0; i < self.entityHeadObjectives.size; i++)
250  {
251  if (isdefined(self.entityHeadObjectives[i]))
252  {
253  ‪gameobjects::release_obj_id( self.entityHeadObjectives[i] );
254  Objective_Delete( self.entityHeadObjectives[i] );
255  }
256  }
257  }
258 
259  self.entityHeadObjectives = [];
260 }
261 
262 function ‪updateEntityHeadIconPos(headicon)
263 {
264  headicon.x = self.origin[0] + self.entityHeadIconOffset[0];
265  headicon.y = self.origin[1] + self.entityHeadIconOffset[1];
266  headicon.z = self.origin[2] + self.entityHeadIconOffset[2];
267 }
268 
270 {
271  if( isdefined( self.entityHeadIcons ) )
272  {
273  foreach( icon in self.entityHeadIcons )
274  {
275  icon.hidewhileremotecontrolling = true;
276  }
277  }
278 }
‪updateEntityHeadTeamIcon
‪function updateEntityHeadTeamIcon(entity, team, icon, constant_size)
Definition: entityheadicons_shared.gsc:152
‪setEntityHeadIconsHiddenWhileControlling
‪function setEntityHeadIconsHiddenWhileControlling()
Definition: entityheadicons_shared.gsc:269
‪start_gametype
‪function start_gametype()
Definition: entityheadicons_shared.gsc:17
‪destroyEntityHeadIcons
‪function destroyEntityHeadIcons()
Definition: entityheadicons_shared.gsc:234
‪on_start_gametype
‪function on_start_gametype(func, obj)
Definition: callbacks_shared.csc:285
‪destroyHeadIconsOnDeath
‪function destroyHeadIconsOnDeath()
Definition: entityheadicons_shared.gsc:209
‪get_next_obj_id
‪function get_next_obj_id()
Definition: gameobjects_shared.gsc:4132
‪updateEntityHeadClientObjective
‪function updateEntityHeadClientObjective(entity, objective, constant_size)
Definition: entityheadicons_shared.gsc:197
‪release_obj_id
‪function release_obj_id(objID)
Definition: gameobjects_shared.gsc:4166
‪waittill_any
‪function waittill_any(str_notify1, str_notify2, str_notify3, str_notify4, str_notify5)
Definition: util_shared.csc:375
‪updateEntityHeadIconPos
‪function updateEntityHeadIconPos(headicon)
Definition: entityheadicons_shared.gsc:262
‪array
‪function filter array
Definition: array_shared.csc:16
‪init_shared
‪function init_shared()
Definition: entityheadicons_shared.gsc:12
‪setEntityHeadIcon
‪function setEntityHeadIcon(team, owner, offset, objective, constant_size)
Definition: entityheadicons_shared.gsc:43
‪updateEntityHeadTeamObjective
‪function updateEntityHeadTeamObjective(entity, team, objective, constant_size)
Definition: entityheadicons_shared.gsc:186
‪destroy
‪function destroy(watcher, owner)
Definition: _decoy.gsc:108
‪updateEntityHeadClientIcon
‪function updateEntityHeadClientIcon(entity, icon, constant_size)
Definition: entityheadicons_shared.gsc:171