‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
_zm_placeable_mine.gsc
Go to the documentation of this file.
1 #using scripts\codescripts\struct;
2 
3 #using scripts\shared\array_shared;
4 #using scripts\shared\clientfield_shared;
5 #using scripts\shared\flag_shared;
6 #using scripts\shared\trigger_shared;
7 #using scripts\shared\util_shared;
8 #using scripts\shared\weapons\_weaponobjects;
9 
10 #insert scripts\shared\shared.gsh;
11 #using scripts\shared\system_shared;
12 
13 #using scripts\zm\_zm_audio;
14 #using scripts\zm\_zm_equipment;
15 #using scripts\zm\_zm_score;
16 #using scripts\zm\_zm_stats;
17 #using scripts\zm\_zm_utility;
18 #using scripts\zm\_zm_weapons;
19 
20 #insert scripts\zm\_zm_utility.gsh;
21 
22 #namespace zm_placeable_mine;
23 
24 ‪REGISTER_SYSTEM_EX( "placeable_mine", undefined, &‪__main__, undefined )
25 
26 
27 function private ‪__main__()
28 {
29  if ( isdefined( level.placeable_mines ) )
30  {
31  level thread ‪replenish_after_rounds();
32  }
33 }
34 
35 function private ‪init_internal()
36 {
37  if ( isdefined( level.placeable_mines ) )
38  {
39  return;
40  }
41 
42  level.placeable_mines = [];
43 
44  level.placeable_mines_on_damage = &‪placeable_mine_damage;
45  level.pickup_placeable_mine = &‪pickup_placeable_mine;
46  level.pickup_placeable_mine_trigger_listener = &‪pickup_placeable_mine_trigger_listener;
47  level.placeable_mine_planted_callbacks = [];
48 }
49 
51 {
52  if ( isdefined( level.placeable_mines ) && level.placeable_mines.size > 0 )
53  {
54  str_key = GetArrayKeys( level.placeable_mines )[0];
55  return level.placeable_mines[str_key];
56  }
57 
58  return level.weaponNone;
59 }
60 
61 function ‪add_mine_type( mine_name, str_retrieval_prompt )
62 {
63  // Automatically initialize the placeable mine system when registering your first placeable mine.
65 
66  ‪weaponobjects::createRetrievableHint( mine_name, str_retrieval_prompt );
67  level.placeable_mines[ mine_name ] = GetWeapon( mine_name );
68  level.placeable_mine_planted_callbacks[mine_name] = [];
69 }
70 
71 function ‪add_weapon_to_mine_slot( mine_name )
72 {
73  // Automatically initialize the placeable mine system when registering your first placeable mine.
75 
76  //weaponobjects::createRetrievableHint( mine_name, str_retrieval_prompt );
77  level.placeable_mines[ mine_name ] = GetWeapon( mine_name );
78  level.placeable_mine_planted_callbacks[mine_name] = [];
79  ‪DEFAULT(level.placeable_mines_in_name_only,[]);
80  level.placeable_mines_in_name_only[ mine_name ] = GetWeapon( mine_name );
81 }
82 
83 function ‪set_max_per_player( n_max_per_player )
84 {
85  level.placeable_mines_max_per_player = n_max_per_player;
86 }
87 
88 function ‪add_planted_callback( fn_planted_cb, wpn_name )
89 {
90  ‪ARRAY_ADD( level.placeable_mine_planted_callbacks[wpn_name], fn_planted_cb );
91 }
92 
93 function private ‪run_planted_callbacks( e_planter )
94 {
95  foreach ( fn in level.placeable_mine_planted_callbacks[self.weapon.name] )
96  {
97  self thread [[fn]]( e_planter );
98  }
99 }
100 
101 function private ‪safe_to_plant()
102 {
103  if ( isdefined( level.placeable_mines_max_per_player ) && self.owner.placeable_mines.size >= level.placeable_mines_max_per_player )
104  {
105  return false;
106  }
107 
108  return true;
109 }
110 
111 function private ‪wait_and_detonate()
112 {
113  wait 0.1;
114 
115  self ‪detonate( self.owner );
116 }
117 
118 function private ‪mine_watch( wpn_type )
119 {
120  self endon( "death" );
121  self notify( "mine_watch" );
122  self endon( "mine_watch" );
123 
124  while(1)
125  {
126  self waittill( "grenade_fire", mine, fired_weapon );
127  if ( fired_weapon == wpn_type )
128  {
129  mine.owner = self;
130  mine.team = self.team;
131  mine.weapon = fired_weapon;
132 
133  self notify( "zmb_enable_" + fired_weapon.name + "_prompt" );
134 
135  if ( mine ‪safe_to_plant() )
136  {
137  mine ‪run_planted_callbacks( self );
138 
139  //stat tracking
140  self ‪zm_stats::increment_client_stat( fired_weapon.name + "_planted" );
141  self ‪zm_stats::increment_player_stat( fired_weapon.name + "_planted" );
142  }
143  else
144  {
145  mine thread ‪wait_and_detonate();
146  }
147  }
148  }
149 }
150 
151 function ‪is_true_placeable_mine( mine_name )
152 {
153  if ( !isdefined(level.placeable_mines_in_name_only ) )
154  return true;
155  if ( !isdefined(level.placeable_mines_in_name_only[ mine_name ] ) )
156  return true;
157  return false;
158 }
159 
160 
161 function ‪setup_for_player( wpn_type, ui_model = "hudItems.showDpadRight" )
162 {
163  if ( !isdefined( self.placeable_mines ) )
164  {
165  self.placeable_mines = [];
166  }
167 
168  if ( isdefined( self.last_placeable_mine_uimodel ) )
169  {
170  self ‪clientfield::set_player_uimodel( self.last_placeable_mine_uimodel, 0 );
171  }
172 
173  if ( ‪is_true_placeable_mine( wpn_type.name ) )
174  {
175  self thread ‪mine_watch( wpn_type );
176  }
177 
178  self giveweapon( wpn_type );
180  self setactionslot( 4, "weapon", wpn_type );
181  startammo = wpn_type.startammo;
182  if ( startammo )
183  {
184  self setweaponammostock( wpn_type, startammo );
185  }
186 
187  if ( isdefined( ui_model ) )
188  {
189  self ‪clientfield::set_player_uimodel( ui_model, 1 );
190  }
191  self.last_placeable_mine_uimodel = ui_model;
192 }
193 
194 function ‪disable_prompt_for_player( wpn_type )
195 {
196  self notify( "zmb_disable_" + wpn_type.name + "_prompt" );
197 }
198 
200 {
201  foreach( mine in level.placeable_mines )
202  {
203  self ‪disable_prompt_for_player( mine );
204  }
205 }
206 
207 function private ‪pickup_placeable_mine()
208 {
209  player = self.owner;
210  wpn_type = self.weapon;
211 
212  if( ‪IS_DRINKING(player.is_drinking) )
213  return;
214 
215  current_player_mine = player ‪zm_utility::get_player_placeable_mine();
216 
217  // Holding a different weapon? Take the old one and give them the new one.
218  if ( current_player_mine != wpn_type )
219  {
220  player TakeWeapon( current_player_mine );
221  }
222 
223  // If they laid them all down, you'll need to give them the weapon back.
224  if ( !player HasWeapon( wpn_type ) )
225  {
226  player thread ‪mine_watch( wpn_type );
227 
228  player giveweapon(wpn_type);
230  player setactionslot(4,"weapon",wpn_type);
231  player setweaponammoclip(wpn_type,0);
232  player notify( "zmb_enable_" + wpn_type.name + "_prompt" );
233  }
234  else
235  {
236  clip_ammo = player GetWeaponAmmoClip( wpn_type );
237  clip_max_ammo = wpn_type.clipSize;
238  if ( clip_ammo >= clip_max_ammo )
239  {
241  player ‪disable_prompt_for_player( wpn_type );
242  return;
243  }
244  }
245 
246  self ‪zm_utility::pick_up();
247 
248  clip_ammo = player GetWeaponAmmoClip( wpn_type );
249  clip_max_ammo = wpn_type.clipSize;
250  if ( clip_ammo >= clip_max_ammo )
251  {
252  player ‪disable_prompt_for_player( wpn_type );
253  }
254  //stat tracking
255  player ‪zm_stats::increment_client_stat( wpn_type.name + "_pickedup" );
256  player ‪zm_stats::increment_player_stat( wpn_type.name + "_pickedup" );
257 }
258 
259 function private ‪pickup_placeable_mine_trigger_listener( trigger, player )
260 {
261  self thread ‪pickup_placeable_mine_trigger_listener_enable( trigger, player );
262  self thread ‪pickup_placeable_mine_trigger_listener_disable( trigger, player );
263 }
264 
265 function private ‪pickup_placeable_mine_trigger_listener_enable( trigger, player )
266 {
267  self endon( "delete" );
268  self endon( "death" );
269 
270  while ( true )
271  {
272  player ‪util::waittill_any( "zmb_enable_" + self.weapon.name + "_prompt", "spawned_player" );
273 
274  if ( !isDefined( trigger ) )
275  {
276  return;
277  }
278 
279  trigger TriggerEnable( true );
280  trigger linkto( self );
281  }
282 }
283 
284 function private ‪pickup_placeable_mine_trigger_listener_disable( trigger, player )
285 {
286  self endon( "delete" );
287  self endon( "death" );
288 
289  while ( true )
290  {
291  player waittill( "zmb_disable_" + self.weapon.name + "_prompt" );
292 
293  if ( !isDefined( trigger ) )
294  {
295  return;
296  }
297 
298  trigger unlink();
299  trigger TriggerEnable( false );
300  }
301 }
302 
303 function private ‪placeable_mine_damage()
304 {
305  self endon( "death" );
306 
307  self setcandamage(true);
308  self.health = 100000;
309  self.maxhealth = self.health;
310 
311  attacker = undefined;
312 
313  while(1)
314  {
315  self waittill("damage", amount, attacker);
316 
317  if ( !isdefined( self ) ) // something else killed it
318  {
319  return;
320  }
321 
322  self.health = self.maxhealth;
323  if ( !isplayer(attacker) )
324  continue;
325 
326  if ( isdefined( self.owner ) && attacker == self.owner )
327  continue;
328 
329  if( isDefined( attacker.pers ) && isDefined( attacker.pers["team"] ) && attacker.pers["team"] != level.zombie_team )
330  continue;
331 
332  break;
333  }
334 
335  if ( level.satchelexplodethisframe )
336  wait .1 + randomfloat(.4);
337  else
338  wait .05;
339 
340  if (!isdefined(self))
341  return;
342 
343  level.satchelexplodethisframe = true;
344 
346 
347  self ‪detonate( attacker );
348  // won't get here; got death notify.
349 }
350 
352 {
353  wait .05;
354  level.satchelexplodethisframe = false;
355 }
356 
357 function private ‪replenish_after_rounds()
358 {
359  while( true )
360  {
361  level waittill( "between_round_over" );
362 
363  if ( isdefined( level.func_custom_placeable_mine_round_replenish ) )
364  {
365  [[ level.func_custom_placeable_mine_round_replenish ]]();
366  continue;
367  }
368 
369  if ( !level ‪flag::exists( "teleporter_used" ) || !level ‪flag::get( "teleporter_used" ) )
370  {
371  players = GetPlayers();
372  for ( i = 0;i < players.size;i++ )
373  {
374  foreach( mine in level.placeable_mines )
375  {
376  if ( players[ i ] ‪zm_utility::is_player_placeable_mine( mine ) &&
377  ‪is_true_placeable_mine( mine.name ) )
378  {
379  players[ i ] giveweapon( mine );
380  players[ i ] ‪zm_utility::set_player_placeable_mine( mine );
381  players[ i ] setactionslot( 4, "weapon", mine );
382  players[ i ] setweaponammoclip( mine, 2 );
383  break;
384  }
385  }
386  }
387  }
388  }
389 }
390 
391 function ‪setup_watchers() // self == player
392 {
393  if ( isdefined( level.placeable_mines ) )
394  {
395  foreach( mine_type in level.placeable_mines )
396  {
397  watcher = self ‪weaponobjects::createUseWeaponObjectWatcher( mine_type.name, self.team );
398  watcher.onSpawnRetrieveTriggers = &‪on_spawn_retrieve_trigger;
399  watcher.adjustTriggerOrigin = &‪adjust_trigger_origin;
400  watcher.pickup = level.pickup_placeable_mine;
401  watcher.pickup_trigger_listener = level.pickup_placeable_mine_trigger_listener;
402  watcher.skip_weapon_object_damage = true;
403  watcher.headIcon = false;
404  watcher.watchForFire = true;
405  watcher.onDetonateCallback = &‪placeable_mine_detonate;
406  watcher.onDamage = level.placeable_mines_on_damage;
407  }
408  }
409 }
410 
411 function private ‪on_spawn_retrieve_trigger( watcher, player )
412 {
413  self ‪weaponobjects::onSpawnRetrievableWeaponObject( watcher, player ); // self == weapon (for example: the mine)
414  if (isdefined(self.pickUpTrigger))
415  self.pickUpTrigger SetHintLowPriority( false );
416 }
417 
418 function private ‪adjust_trigger_origin( origin )
419 {
420  origin = origin + (0,0,20);
421  return origin;
422 }
423 
424 function private ‪placeable_mine_detonate(attacker, weapon, target )
425 {
426  if ( weapon.isEmp )
427  {
428  self delete();
429  return;
430  }
431 
432  if ( IsDefined( attacker ) )
433  {
434  self Detonate( attacker );
435  }
436  else if ( isdefined( self.owner ) && isplayer( self.owner ) )
437  {
438  self Detonate( self.owner );
439  }
440  else
441  {
442  self Detonate();
443  }
444 }
445 
‪setup_for_player
‪function setup_for_player(wpn_type, ui_model="hudItems.showDpadRight")
Definition: _zm_placeable_mine.gsc:161
‪increment_client_stat
‪function increment_client_stat(stat_name, include_gametype)
Definition: _zm_stats.gsc:389
‪pickup_placeable_mine_trigger_listener_enable
‪function private pickup_placeable_mine_trigger_listener_enable(trigger, player)
Definition: _zm_placeable_mine.gsc:265
‪increment_player_stat
‪function increment_player_stat(stat_name)
Definition: _zm_stats.gsc:369
‪detonate
‪function detonate(attacker)
Definition: vehicle_ai_shared.gsc:1650
‪pickup_placeable_mine_trigger_listener
‪function private pickup_placeable_mine_trigger_listener(trigger, player)
Definition: _zm_placeable_mine.gsc:259
‪is_true_placeable_mine
‪function is_true_placeable_mine(mine_name)
Definition: _zm_placeable_mine.gsc:151
‪set_max_per_player
‪function set_max_per_player(n_max_per_player)
Definition: _zm_placeable_mine.gsc:83
‪get
‪function get(kvp_value, kvp_key="targetname")
Definition: struct.csc:13
‪mine_watch
‪function private mine_watch(wpn_type)
Definition: _zm_placeable_mine.gsc:118
‪replenish_after_rounds
‪function private replenish_after_rounds()
Definition: _zm_placeable_mine.gsc:357
‪reset_satchel_explode_this_frame
‪function private reset_satchel_explode_this_frame()
Definition: _zm_placeable_mine.gsc:351
‪add_weapon_to_mine_slot
‪function add_weapon_to_mine_slot(mine_name)
Definition: _zm_placeable_mine.gsc:71
‪disable_prompt_for_player
‪function disable_prompt_for_player(wpn_type)
Definition: _zm_placeable_mine.gsc:194
‪__main__
‪function private __main__()
Definition: _zm_placeable_mine.gsc:27
‪DEFAULT
‪#define DEFAULT(__var, __default)
Definition: shared.gsh:270
‪run_planted_callbacks
‪function private run_planted_callbacks(e_planter)
Definition: _zm_placeable_mine.gsc:93
‪safe_to_plant
‪function private safe_to_plant()
Definition: _zm_placeable_mine.gsc:101
‪pick_up
‪function pick_up(player)
Definition: _ballistic_knife.gsc:202
‪pickup_placeable_mine
‪function private pickup_placeable_mine()
Definition: _zm_placeable_mine.gsc:207
‪REGISTER_SYSTEM_EX
‪#define REGISTER_SYSTEM_EX(__sys, __func_init_preload, __func_init_postload, __reqs)
Definition: shared.gsh:209
‪set_player_placeable_mine
‪function set_player_placeable_mine(weapon)
Definition: _zm_utility.gsc:4304
‪add_planted_callback
‪function add_planted_callback(fn_planted_cb, wpn_name)
Definition: _zm_placeable_mine.gsc:88
‪pickup_placeable_mine_trigger_listener_disable
‪function private pickup_placeable_mine_trigger_listener_disable(trigger, player)
Definition: _zm_placeable_mine.gsc:284
‪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
‪adjust_trigger_origin
‪function private adjust_trigger_origin(origin)
Definition: _zm_placeable_mine.gsc:418
‪get_player_placeable_mine
‪function get_player_placeable_mine()
Definition: _zm_utility.gsc:4291
‪add_mine_type
‪function add_mine_type(mine_name, str_retrieval_prompt)
Definition: _zm_placeable_mine.gsc:61
‪destroy_ent
‪function destroy_ent()
Definition: _ballistic_knife.gsc:234
‪is_player_placeable_mine
‪function is_player_placeable_mine(weapon)
Definition: _zm_utility.gsc:4280
‪createRetrievableHint
‪function createRetrievableHint(name, hint)
Definition: _weaponobjects.gsc:3425
‪placeable_mine_damage
‪function private placeable_mine_damage()
Definition: _zm_placeable_mine.gsc:303
‪createUseWeaponObjectWatcher
‪function createUseWeaponObjectWatcher(weaponname, ownerTeam)
Definition: _weaponobjects.gsc:1297
‪exists
‪function exists(str_flag)
Definition: flag_shared.csc:43
‪onSpawnRetrievableWeaponObject
‪function onSpawnRetrievableWeaponObject(watcher, player)
Definition: _weaponobjects.gsc:3135
‪set_player_uimodel
‪function set_player_uimodel(str_field_name, n_value)
Definition: clientfield_shared.gsc:75
‪init_internal
‪function private init_internal()
Definition: _zm_placeable_mine.gsc:35
‪setup_watchers
‪function setup_watchers()
Definition: _zm_placeable_mine.gsc:391
‪disable_all_prompts_for_player
‪function disable_all_prompts_for_player()
Definition: _zm_placeable_mine.gsc:199
‪placeable_mine_detonate
‪function private placeable_mine_detonate(attacker, weapon, target)
Definition: _zm_placeable_mine.gsc:424
‪on_spawn_retrieve_trigger
‪function private on_spawn_retrieve_trigger(watcher, player)
Definition: _zm_placeable_mine.gsc:411
‪IS_DRINKING
‪#define IS_DRINKING(_is_drinking)
Definition: _zm_utility.gsh:1
‪get_first_available
‪function get_first_available()
Definition: _zm_placeable_mine.gsc:50
‪wait_and_detonate
‪function private wait_and_detonate()
Definition: _zm_placeable_mine.gsc:111