‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
_zm_attackables.gsc
Go to the documentation of this file.
1 #using scripts\codescripts\struct;
2 
3 #insert scripts\shared\shared.gsh;
4 
5 #using scripts\shared\array_shared;
6 #using scripts\shared\callbacks_shared;
7 #using scripts\shared\killstreaks_shared;
8 #using scripts\shared\laststand_shared;
9 #using scripts\shared\math_shared;
10 #using scripts\shared\system_shared;
11 #using scripts\shared\table_shared;
12 #using scripts\shared\util_shared;
13 #using scripts\shared\weapons_shared;
14 
15 #using scripts\zm\_zm;
16 #using scripts\zm\_zm_powerups;
17 #using scripts\zm\_zm_spawner;
18 #using scripts\zm\_zm_stats;
19 #using scripts\zm\_zm_utility;
20 #using scripts\zm\_zm_weapons;
21 
22 #insert scripts\zm\_zm_attackables.gsh;
23 
24 #namespace zm_attackables;
25 
26 ‪REGISTER_SYSTEM_EX( "zm_attackables", &‪__init__, &‪__main__, undefined )
27 
28 function ‪__init__()
29 {
30  level.attackableCallback = &‪attackable_callback;
31 
32  level.attackables = ‪struct::get_array( "scriptbundle_attackables", "classname" );
33 
34  foreach( attackable in level.attackables )
35  {
36  attackable.bundle = ‪struct::get_script_bundle( "attackables", attackable.scriptbundlename );
37 
38  if ( isdefined( attackable.target ) )
39  {
40  attackable.slot = ‪struct::get_array( attackable.target, "targetname" );
41  }
42 
43  attackable.is_active = false;
44  attackable.health = attackable.bundle.max_health;
45 
46  if ( GetDvarInt( "zm_attackables" ) > 0 )
47  {
48  attackable.is_active = true;
49  attackable.health = 1000;
50  }
51 
52  }
53 }
54 
55 function ‪__main__()
56 {
57 }
58 
59 function ‪get_attackable() // self = zombie AI
60 {
61  foreach( attackable in level.attackables )
62  {
63  if ( !‪IS_TRUE( attackable.is_active ) )
64  {
65  continue;
66  }
67 
68  dist = Distance( self.origin, attackable.origin );
69  if ( dist < attackable.bundle.aggro_distance )
70  {
71  if ( attackable ‪get_attackable_slot( self ) )
72  {
73  return attackable;
74  }
75  }
76  }
77 
78  return undefined;
79 }
80 
81 function ‪get_attackable_slot( entity ) // self = attackble scriptbundle (struct)
82 {
83  //self.slot = array::remove_dead( self.slot );
84 
85  //if ( self.slot.size < self.bundle.max_attackers )
86  //{
87  // ARRAY_ADD( self.slot, entity );
88  // return true;
89  //}
90 
91  self ‪clear_slots();
92 
93  foreach( slot in self.slot )
94  {
95  if ( !isdefined( slot.entity ) )
96  {
97  slot.entity = entity;
98  entity.attackable_slot = slot;
99  return true;
100  }
101  }
102 
103  return false;
104 }
105 
106 function private ‪clear_slots() // self = attackble scriptbundle (struct)
107 {
108  foreach( slot in self.slot )
109  {
110  if ( !IsAlive( slot.entity ) )
111  {
112  slot.entity = undefined;
113  }
114  else
115  {
116  if ( ‪IS_TRUE( slot.entity.missingLegs ) )
117  {
118  slot.entity = undefined;
119  }
120  }
121  }
122 }
123 
124 function ‪activate() // self = attackble scriptbundle (struct)
125 {
126  self.is_active = true;
127 
128  // Re-set the attackable's health if it's 0
129  // Allows the attackable to be re-used
130  if( self.health <= 0 )
131  {
132  self.health = self.bundle.max_health;
133  }
134 }
135 
136 function ‪deactivate() // self = attackble scriptbundle (struct)
137 {
138  self.is_active = false;
139 }
140 
141 function ‪do_damage( ‪damage ) // self = attackble scriptbundle (struct)
142 {
143  self.health -= ‪damage;
144  self notify( "attackable_damaged" );
145 
146  if ( self.health <= 0 )
147  {
148  self notify( "attackable_deactivated" );
149 
150  if( !‪IS_TRUE( self.b_deferred_deactivation ) )
151  {
152  self ‪deactivate();
153  }
154  }
155 }
156 
157 function ‪attackable_callback( entity )
158 {
159  self ‪do_damage( entity.meleeWeapon.meleeDamage );
160 }
‪__init__
‪function __init__()
Definition: _zm_attackables.gsc:28
‪get_array
‪function get_array(kvp_value, kvp_key="targetname")
Definition: struct.csc:34
‪clear_slots
‪function private clear_slots()
Definition: _zm_attackables.gsc:106
‪IS_TRUE
‪#define IS_TRUE(__a)
Definition: shared.gsh:251
‪activate
‪function activate()
Definition: _zm_attackables.gsc:124
‪damage
‪function damage(trap)
Definition: _zm_trap_electric.gsc:116
‪get_attackable_slot
‪function get_attackable_slot(entity)
Definition: _zm_attackables.gsc:81
‪attackable_callback
‪function attackable_callback(entity)
Definition: _zm_attackables.gsc:157
‪REGISTER_SYSTEM_EX
‪#define REGISTER_SYSTEM_EX(__sys, __func_init_preload, __func_init_postload, __reqs)
Definition: shared.gsh:209
‪do_damage
‪function do_damage(damage)
Definition: _zm_attackables.gsc:141
‪deactivate
‪function deactivate()
Definition: _zm_attackables.gsc:136
‪get_attackable
‪function get_attackable()
Definition: _zm_attackables.gsc:59
‪get_script_bundle
‪function get_script_bundle(str_type, str_name)
Definition: struct.csc:45
‪__main__
‪function __main__()
Definition: _zm_attackables.gsc:55