‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
_ballistic_knife.gsc
Go to the documentation of this file.
1 #using scripts\codescripts\struct;
2 
3 #using scripts\shared\callbacks_shared;
4 #using scripts\shared\challenges_shared;
5 #using scripts\shared\clientfield_shared;
6 #using scripts\shared\system_shared;
7 #using scripts\shared\weapons\_weaponobjects;
8 
9 #insert scripts\shared\shared.gsh;
10 
11 #define RETRIEVE_TRIGGER_HEIGHT 100
12 #define RETRIEVE_TRIGGER_RADIUS 50
13 
14 #namespace ballistic_knife;
15 
16 function ‪init_shared()
17 {
19 }
20 
21 function ‪onSpawn( watcher, player )
22 {
23  player endon( "death" );
24  player endon( "disconnect" );
25  level endon( "game_ended" );
26 
27  self waittill( "stationary", endpos, normal, angles, attacker, prey, bone );
28 
29  isFriendly = false;
30 
31  if( isdefined(endpos) )
32  {
33  // once the missile dies, spawn a model there to be retrieved
34  retrievable_model = ‪spawn( "script_model", endpos );
35  retrievable_model SetModel( "wpn_t7_loot_ballistic_knife_projectile" );
36  retrievable_model SetTeam( player.team );
37  retrievable_model SetOwner( player );
38  retrievable_model.owner = player;
39  retrievable_model.angles = angles;
40  retrievable_model.name = watcher.weapon;
41  retrievable_model.targetname = "sticky_weapon";
42 
43  if( isdefined( prey ) )
44  {
45  //Don't stick to teammates and friendly dogs
46  if( level.teamBased && player.team == prey.team )
47  isFriendly = true;
48 
49  if( !isFriendly )
50  {
51  if( IsAlive( prey ) )
52  {
53  retrievable_model ‪dropToGround( retrievable_model.origin, 80 );
54  }
55  else
56  {
57  retrievable_model LinkTo( prey, bone );
58  }
59  }
60  else if( isFriendly )
61  {
62  //launchVec = normal * -1;
63  retrievable_model physicslaunch( normal, (randomint(10),randomint(10),randomint(10)) );
64 
65  //Since the impact normal is not what we want anymore, and the knife will fall to the ground, send the world up normal.
66  normal = (0,0,1);
67  }
68 
69  }
70 
71  watcher.objectArray[watcher.objectArray.size] = retrievable_model;
72 
73  //Wait until the model is stationary again
74  if( isFriendly )
75  retrievable_model waittill( "stationary");
76 
77  retrievable_model thread ‪dropKnivesToGround();
78 
79  if ( isFriendly )
80  player notify( "ballistic_knife_stationary", retrievable_model, normal );
81  else
82  player notify( "ballistic_knife_stationary", retrievable_model, normal, prey );
83  }
84 }
85 
86 function ‪watch_shutdown() // self == retrievable_model
87 {
88  pickUpTrigger = self.pickUpTrigger;
89 
90  self waittill( "death" );
91 
92  if( isdefined( pickUpTrigger ) )
93  pickUpTrigger delete();
94 }
95 
96 function ‪onSpawnRetrieveTrigger( watcher, player )
97 {
98  player endon( "death" );
99  player endon( "disconnect" );
100  level endon( "game_ended" );
101 
102  player waittill( "ballistic_knife_stationary", retrievable_model, normal, prey );
103 
104  if( !isdefined( retrievable_model ) )
105  return;
106 
107  vec_scale = 10;
108  trigger_pos = [];
109  if ( isdefined( prey ) && ( isPlayer( prey ) || isAI( prey ) ) )
110  {
111  trigger_pos[0] = prey.origin[0];
112  trigger_pos[1] = prey.origin[1];
113  trigger_pos[2] = prey.origin[2] + vec_scale;
114  }
115  else
116  {
117  trigger_pos[0] = retrievable_model.origin[0] + (vec_scale * normal[0]);
118  trigger_pos[1] = retrievable_model.origin[1] + (vec_scale * normal[1]);
119  trigger_pos[2] = retrievable_model.origin[2] + (vec_scale * normal[2]);
120  }
121 
122  // center the retrieve trigger so that triggers above the players head are reachable
123  // trigger_radius spawn types set the base at the origin and extend to the height param
124  trigger_pos[2] -= ‪RETRIEVE_TRIGGER_HEIGHT / 2;
125 
126  retrievable_model ‪clientfield::set( "retrievable", 1 );
127 
128  pickup_trigger = ‪spawn( "trigger_radius", (trigger_pos[0], trigger_pos[1], trigger_pos[2]), 0, ‪RETRIEVE_TRIGGER_RADIUS, ‪RETRIEVE_TRIGGER_HEIGHT );
129  pickup_trigger.owner = player;
130 
131  retrievable_model.pickUpTrigger = pickup_trigger;
132 
133  // link the model and trigger, then link them to the ragdoll if needed
134  pickup_trigger EnableLinkTo();
135 
136  if ( isdefined( prey ) )
137  pickup_trigger LinkTo( prey );
138  else
139  pickup_trigger LinkTo( retrievable_model );
140 
141  retrievable_model thread ‪watch_use_trigger( pickup_trigger, retrievable_model,&‪pick_up, watcher.pickUpSoundPlayer, watcher.pickUpSound );
142  retrievable_model thread ‪watch_shutdown();
143 }
144 
145 function ‪watch_use_trigger( trigger, model, ‪callback, playerSoundOnUse, npcSoundOnUse ) // self == retrievable_model
146 {
147  self endon( "death" );
148  self endon( "delete" );
149  level endon ( "game_ended" );
150 
151  // need to add 1 to max ammo because the ballistic knife has a max ammo of 1 but can hold 1 in the clip and 1 in the stock
152  // there's something janky in the code so if we do 2 max ammo then players could pick up 3 and we only want them to have 2
153  max_ammo = level.weaponBallisticKnife.maxAmmo + 1;
154 
155  while ( true )
156  {
157  trigger waittill( "trigger", player );
158 
159  if ( !IsAlive( player ) )
160  continue;
161 
162  if ( !player IsOnGround() && !SessionModeIsMultiplayerGame() )
163  continue;
164 
165  if ( isdefined( trigger.triggerTeam ) && ( player.team != trigger.triggerTeam ) )
166  continue;
167 
168  if ( isdefined( trigger.claimedBy ) && ( player != trigger.claimedBy ) )
169  continue;
170 
171  if ( !player HasWeapon( level.weaponBallisticKnife, true ) )
172  continue;
173 
174  heldBallisticKnife = player GetWeaponForWeaponRoot( level.weaponBallisticKnife );
175  if ( !isdefined( heldBallisticKnife ) )
176  continue;
177 
178  ammo_stock = player GetWeaponAmmoStock( heldBallisticKnife );
179  ammo_clip = player GetWeaponAmmoClip( heldBallisticKnife );
180 
181  total_ammo = ammo_stock + ammo_clip;
182 
183  // see if this player hasn't reloaded yet, we make this check so you can't pick it up before your stock ammo has updated
184  // if your stock ammo hasn't updated then you'll take it but you won't get it in your reserves, it just goes away
185  hasReloaded = true;
186  if ( total_ammo > 0 && ammo_stock == total_ammo )
187  hasReloaded = false;
188 
189  if ( total_ammo >= max_ammo || !hasReloaded )
190  continue;
191 
192  if ( isdefined( playerSoundOnUse ) )
193  player playLocalSound( playerSoundOnUse );
194  if ( isdefined( npcSoundOnUse ) )
195  player playSound( npcSoundOnUse );
196 
197  self thread [[‪callback]]( player );
198  break;
199  }
200 }
201 
202 function ‪pick_up( player ) // self == retrievable_model
203 {
204  self ‪destroy_ent();
205 
206  // if we're not currently on the ballistic knife and the clip is empty then put the ammo in the clip
207  current_weapon = player GetCurrentWeapon();
209  if( current_weapon.rootWeapon != level.weaponBallisticKnife )
210  {
211  heldBallisticKnife = player GetWeaponForWeaponRoot( level.weaponBallisticKnife );
212  if ( !isdefined( heldBallisticKnife ) )
213  return;
214 
215  // if the clip is empty, fill it
216  clip_ammo = player GetWeaponAmmoClip( heldBallisticKnife );
217  if( !clip_ammo )
218  {
219  player SetWeaponAmmoClip( heldBallisticKnife, 1 );
220  }
221  else
222  {
223  new_ammo_stock = player GetWeaponAmmoStock( heldBallisticKnife ) + 1;
224  player SetWeaponAmmoStock( heldBallisticKnife, new_ammo_stock );
225  }
226  }
227  else
228  {
229  new_ammo_stock = player GetWeaponAmmoStock( current_weapon ) + 1;
230  player SetWeaponAmmoStock( current_weapon, new_ammo_stock );
231  }
232 }
233 
234 function ‪destroy_ent()
235 {
236  if( isdefined(self) )
237  {
238  pickUpTrigger = self.pickUpTrigger;
239 
240  if( isdefined( pickUpTrigger ) )
241  pickUpTrigger delete();
242 
243  self delete();
244  }
245 }
246 
248 {
249  self endon("death");
250 
251  for( ;; )
252  {
253  level waittill( "drop_objects_to_ground", origin, radius );
254  self ‪dropToGround( origin, radius );
255  }
256 }
257 
258 function ‪dropToGround( origin, radius )
259 {
260  if( DistanceSquared( origin, self.origin )< radius * radius )
261  {
262  self physicslaunch( (0,0,1), (5,5,5));
263  self thread ‪updateRetrieveTrigger();
264  }
265 }
266 
268 {
269  self endon("death");
270 
271  self waittill( "stationary");
272 
273  trigger = self.pickUpTrigger;
274 
275  trigger.origin = ( self.origin[0], self.origin[1], self.origin[2] + 10 );
276  trigger LinkTo( self );
277 }
278 
279 function ‪createBallisticKnifeWatcher() // self == player
280 {
281  watcher = self ‪weaponobjects::createUseWeaponObjectWatcher( "knife_ballistic", self.team );
282  watcher.onSpawn = &‪onSpawn;
283  watcher.onDetonateCallback =&‪weaponobjects::deleteEnt;
284  watcher.onSpawnRetrieveTriggers = &‪onSpawnRetrieveTrigger;
285  watcher.storeDifferentObject = true;
286 }
‪callback
‪function callback(event, localclientnum, params)
Definition: callbacks_shared.csc:13
‪onSpawnRetrieveTrigger
‪function onSpawnRetrieveTrigger(watcher, player)
Definition: _ballistic_knife.gsc:96
‪deleteEnt
‪function deleteEnt(attacker, emp, target)
Definition: _weaponobjects.gsc:461
‪dropKnivesToGround
‪function dropKnivesToGround()
Definition: _ballistic_knife.gsc:247
‪onSpawn
‪function onSpawn(watcher, player)
Definition: _ballistic_knife.gsc:21
‪spawn
‪function spawn(v_origin=(0, 0, 0), v_angles=(0, 0, 0))
Definition: struct.csc:23
‪watch_shutdown
‪function watch_shutdown()
Definition: _ballistic_knife.gsc:86
‪pickedUpBallisticKnife
‪function pickedUpBallisticKnife()
Definition: challenges_shared.gsc:20
‪createBallisticKnifeWatcher
‪function createBallisticKnifeWatcher()
Definition: _ballistic_knife.gsc:279
‪pick_up
‪function pick_up(player)
Definition: _ballistic_knife.gsc:202
‪watch_use_trigger
‪function watch_use_trigger(trigger, model, callback, playerSoundOnUse, npcSoundOnUse)
Definition: _ballistic_knife.gsc:145
‪dropToGround
‪function dropToGround(origin, radius)
Definition: _ballistic_knife.gsc:258
‪init_shared
‪function init_shared()
Definition: _ballistic_knife.gsc:16
‪add_weapon_watcher
‪function add_weapon_watcher(callback)
Definition: callbacks_shared.gsc:609
‪RETRIEVE_TRIGGER_RADIUS
‪#define RETRIEVE_TRIGGER_RADIUS
Definition: _ballistic_knife.gsc:12
‪destroy_ent
‪function destroy_ent()
Definition: _ballistic_knife.gsc:234
‪updateRetrieveTrigger
‪function updateRetrieveTrigger()
Definition: _ballistic_knife.gsc:267
‪set
‪function set(str_field_name, n_value)
Definition: clientfield_shared.gsc:34
‪createUseWeaponObjectWatcher
‪function createUseWeaponObjectWatcher(weaponname, ownerTeam)
Definition: _weaponobjects.gsc:1297
‪RETRIEVE_TRIGGER_HEIGHT
‪#define RETRIEVE_TRIGGER_HEIGHT
Definition: _ballistic_knife.gsc:11