‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
_lightninggun.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\flagsys_shared;
7 #using scripts\shared\killcam_shared;
8 #using scripts\shared\player_shared;
9 #using scripts\shared\scoreevents_shared;
10 #using scripts\shared\system_shared;
11 #using scripts\shared\util_shared;
12 #using scripts\shared\visionset_mgr_shared;
13 
14 #using scripts\shared\weapons\_weaponobjects;
15 
16 #insert scripts\shared\shared.gsh;
17 #insert scripts\shared\version.gsh;
18 
19 #insert scripts\shared\weapons\_lightninggun.gsh;
20 
21 #precache( "fx", "weapon/fx_lightninggun_arc" );
22 
23 #define LIGHTNINGGUN_VICTIM_RUMBLE "lightninggun_victim"
24 
25 #namespace lightninggun;
26 
27 function ‪init_shared()
28 {
29  level.weaponLightningGun = GetWeapon( "hero_lightninggun" );
30  level.weaponLightningGunArc = GetWeapon( "hero_lightninggun_arc" );
31  level.weaponLightningGunKillcamTime = GetDvarFloat( "scr_lightningGunKillcamTime", 0.35 );
32  level.weaponLightningGunKillcamDecelPercent = GetDvarFloat( "scr_lightningGunKillcamDecelPercent", 0.25 );
33  level.weaponLightningGunKillcamOffset = GetDvarFloat( "scr_lightningGunKillcamOffset", 150.0 );
34 
35  level.lightninggun_arc_range = ‪LIGHTNINGGUN_ARC_RANGE;
36  level.lightninggun_arc_range_sq = level.lightninggun_arc_range * level.lightninggun_arc_range;
37  level.lightninggun_arc_speed = ‪LIGHTNINGGUN_ARC_SPEED;
38  level.lightninggun_arc_speed_sq = level.lightninggun_arc_speed * level.lightninggun_arc_speed;
39  level.lightninggun_arc_fx_min_range = ‪LIGHTNINGGUN_ARC_FX_MIN_RANGE;
40  level.lightninggun_arc_fx_min_range_sq = level.lightninggun_arc_fx_min_range * level.lightninggun_arc_fx_min_range;
41 
42  level._effect["lightninggun_arc"] = "weapon/fx_lightninggun_arc";
43 
44  ‪callback::add_weapon_damage( level.weaponLightningGun, &‪on_damage_lightninggun );
45 
46 /#
47  level thread ‪update_dvars();
48 #/
49 }
50 
51 /#
52 function ‪update_dvars()
53 {
54  while(1)
55  {
56  wait(1);
57  level.weaponLightningGunKillcamTime = GetDvarFloat( "scr_lightningGunKillcamTime", 0.35 );
58  level.weaponLightningGunKillcamDecelPercent = GetDvarFloat( "scr_lightningGunKillcamDecelPercent", 0.25 );
59  level.weaponLightningGunKillcamOffset = GetDvarFloat( "scr_lightningGunKillcamOffset", 150.0 );
60  }
61 }
62 #/
63 
65 {
66  self endon( "disconnect" );
67 
68 /#
69  If ( IsGodMode( self ) )
70  {
71  return;
72  }
73 #/
74 
75  self SetElectrifiedState( true );
76  self.electrifiedBy = eAttacker;
77  self PlayRumbleOnEntity( ‪LIGHTNINGGUN_VICTIM_RUMBLE );
78 
80 
81  self.electrifiedBy = undefined;
82  self SetElectrifiedState( false );
83 }
84 
85 function ‪lightninggun_arc_killcam( arc_source_pos, arc_target, arc_target_pos, original_killcam_ent, waitTime )
86 {
87  arc_target.killcamKilledByEnt = ‪create_killcam_entity( original_killcam_ent.origin, original_killcam_ent.angles, level.weaponLightningGunArc );
88  arc_target.killcamKilledByEnt ‪killcam::store_killcam_entity_on_entity(original_killcam_ent);
89 
90  arc_target.killcamKilledByEnt ‪killcam_move( arc_source_pos, arc_target_pos, waitTime );
91 }
92 
93 function ‪lightninggun_arc_fx( arc_source_pos, arc_target, arc_target_pos, distanceSq, original_killcam_ent )
94 {
95  if ( !isdefined( arc_target ) || !isdefined( original_killcam_ent ) )
96  return;
97 
98  waitTime = 0.25;
99  if ( level.lightninggun_arc_speed_sq > 100 && distanceSq > 1 )
100  {
101  waitTime = distanceSq / level.lightninggun_arc_speed_sq;
102  }
103 
104  ‪lightninggun_arc_killcam( arc_source_pos, arc_target, arc_target_pos, original_killcam_ent, waitTime );
105  killcamEntity = arc_target.killcamKilledByEnt;
106 
107  if ( !isdefined( arc_target ) || !isdefined( original_killcam_ent ) )
108  return;
109 
110  if ( distanceSq < level.lightninggun_arc_fx_min_range_sq )
111  {
112  wait( waitTime );
113 
114  killcamEntity delete();
115 
116  if ( isdefined( arc_target ) )
117  {
118  arc_target.killcamKilledByEnt = undefined;
119  }
120  //Not playing arcing FX. Enemies too close
121  return;
122  }
123 
124  // this needs to be clientsided.
125  fxOrg = ‪spawn( "script_model", arc_source_pos );
126  fxOrg SetModel( "tag_origin" );
127 
128  fx = PlayFxOnTag( level._effect["lightninggun_arc"], fxOrg, "tag_origin" );
129  playsoundatposition( "wpn_lightning_gun_bounce", fxOrg.origin );
130 
131  fxOrg MoveTo( arc_target_pos, waitTime );
132  fxOrg waittill( "movedone" );
136  fxOrg delete();
137 
138  killcamEntity delete();
139 
140  if ( isdefined( arc_target ) )
141  {
142  arc_target.killcamKilledByEnt = undefined;
143  }
144 }
145 
146 function ‪lightninggun_arc( ‪delay, eAttacker, arc_source, arc_source_origin, arc_source_pos, arc_target, arc_target_pos, distanceSq )
147 {
148  if ( ‪delay )
149  {
150  wait( ‪delay );
151 
152  if ( !IsDefined( arc_target ) || !IsAlive( arc_target ) )
153  {
154  return;
155  }
156 
157  // make sure we're still in range after the delay
158  distanceSq = DistanceSquared( arc_target.origin, arc_source_origin );
159  if ( distanceSq > level.lightninggun_arc_range_sq )
160  {
161  return;
162  }
163  }
164 
165  if ( !isdefined( arc_source ) )
166  {
167  return;
168  }
169 
170  if ( !isdefined( arc_source.killcamKilledByEnt ) )
171  {
172  return;
173  }
174 
175  level thread ‪lightninggun_arc_fx( arc_source_pos, arc_target, arc_target_pos, distanceSq, arc_source.killcamKilledByEnt );
176  arc_target thread ‪lightninggun_start_damage_effects( eAttacker );
177  arc_target DoDamage( arc_target.health, arc_source_pos, eAttacker, arc_source, "none", "MOD_PISTOL_BULLET", 0, level.weaponLightningGunArc );
178 }
179 
180 // arc_source_origin is the origin of the player initially hit, arc_source_pos is the pos of the tag the arc will be emanating from
181 function ‪lightninggun_find_arc_targets( eAttacker, arc_source, arc_source_origin, arc_source_pos )
182 {
184 
185  allEnemyAlivePlayers = ‪util::get_other_teams_alive_players_s( eAttacker.team );
186 
187  closestPlayers = ArraySort( allEnemyAlivePlayers.a, arc_source_origin, true );
188 
189  foreach( player in closestPlayers )
190  {
191  if ( IsDefined( arc_source ) && player == arc_source )
192  {
193  continue;
194  }
195 
196  if ( player ‪player::is_spawn_protected() )
197  {
198  continue;
199  }
200 
201  distanceSq = DistanceSquared( player.origin, arc_source_origin );
202  if ( distanceSq > level.lightninggun_arc_range_sq )
203  {
204  break;
205  }
206 
207  if ( eAttacker != player && ‪weaponobjects::friendlyFireCheck( eAttacker, player ) )
208  {
209  if ( isdefined( self ) && !player DamageConeTrace( arc_source_pos, self ) )
210  {
211  continue;
212  }
213 
214  level thread ‪lightninggun_arc( ‪delay, eAttacker, arc_source, arc_source_origin, arc_source_pos, player, player GetTagOrigin( ‪LIGHTNINGGUN_FX_TAG ), distanceSq );
216  }
217  }
218 }
219 
220 function ‪create_killcam_entity( origin, angles, weapon )
221 {
222  killcamKilledByEnt = ‪spawn( "script_model", origin );
223  killcamKilledByEnt SetModel( "tag_origin" );
224  killcamKilledByEnt.angles = angles;
225  killcamKilledByEnt SetWeapon( weapon );
226  return killcamKilledByEnt;
227 }
228 
229 function ‪killcam_move( start_origin, end_origin, time )
230 {
231  delta = end_origin - start_origin;
232  dist = Length( delta );
233  delta = VectorNormalize( delta );
234  move_to_dist = dist - level.weaponLightningGunKillcamOffset;
235 
236  end_angles = (0,0,0);
237 
238  if ( move_to_dist > 0 )
239  {
240  move_to_pos = start_origin + (delta * move_to_dist);
241  self MoveTo( move_to_pos, time, 0, time * level.weaponLightningGunKillcamDecelPercent );
242  end_angles = VectorToAngles( delta );
243  }
244  else
245  {
246  delta = end_origin - self.origin;
247  end_angles = VectorToAngles( delta );
248  }
249 
250  //self RotateTo( end_angles, time, 0, time * level.weaponLightningGunKillcamDecelPercent );
251 }
252 
253 function ‪lightninggun_damage_response( eAttacker, eInflictor, weapon, meansOfDeath, ‪damage )
254 {
255  source_pos = eAttacker.origin;
256  bolt_source_pos = eAttacker GetTagOrigin( "tag_flash" );
257 
258  arc_source = self;
259  arc_source_origin = self.origin;
260  arc_source_pos = self GetTagOrigin( ‪LIGHTNINGGUN_FX_TAG );
261 
262  delta = arc_source_pos - bolt_source_pos;
263  angles = (0,0,0); //VectorToAngles( delta );
264 
265  arc_source.killcamKilledByEnt = ‪create_killcam_entity( bolt_source_pos, angles, weapon );
266  arc_source.killcamKilledByEnt ‪killcam_move( bolt_source_pos, arc_source_pos, level.weaponLightningGunKillcamTime );
267  killcamEntity = arc_source.killcamKilledByEnt;
268 
269  self thread ‪lightninggun_start_damage_effects( eAttacker );
270 // self DoDamage( self.health, source_pos, eAttacker, eAttacker, "none", "MOD_PISTOL_BULLET", 0, level.weaponLightningGunArc );
271 
273 
274  if ( !IsDefined( self ) )
275  {
276  self thread ‪lightninggun_find_arc_targets( eAttacker, undefined, arc_source_origin, arc_source_pos );
277  return;
278  }
279 
280  // get latest positioning
281  if ( IsDefined( self.body ) )
282  {
283  arc_source_origin = self.body.origin;
284  arc_source_pos = self.body GetTagOrigin( ‪LIGHTNINGGUN_FX_TAG );
285  }
286 
287  self thread ‪lightninggun_find_arc_targets( eAttacker, arc_source, arc_source_origin, arc_source_pos );
288 
289  // wait the maximum amount of time that we could still be arcing. The other players
290  // will use this killcamEntity
291  wait( ‪LIGHTNINGGUN_ARC_DELAY * 9 );
292  killcamEntity delete();
293 
294  if ( IsDefined( arc_source ) )
295  {
296  arc_source.killcamKilledByEnt = undefined;
297  }
298 }
299 
300 function ‪on_damage_lightninggun( eAttacker, eInflictor, weapon, meansOfDeath, ‪damage )
301 {
302  if ( "MOD_PISTOL_BULLET" != meansOfDeath && "MOD_HEAD_SHOT" != meansOfDeath )
303  return;
304 
305  // no additional lightning gun damage response if the player has armor on for now.
306 // if ( self flagsys::get( "gadget_armor_on" ) )
307 // return;
308 
309  self thread ‪lightninggun_damage_response( eAttacker, eInflictor, weapon, meansOfDeath, ‪damage );
310 }
‪lightninggun_arc
‪function lightninggun_arc(delay, eAttacker, arc_source, arc_source_origin, arc_source_pos, arc_target, arc_target_pos, distanceSq)
Definition: _lightninggun.gsc:146
‪lightninggun_find_arc_targets
‪function lightninggun_find_arc_targets(eAttacker, arc_source, arc_source_origin, arc_source_pos)
Definition: _lightninggun.gsc:181
‪update_dvars
‪function update_dvars()
Definition: _lightninggun.gsc:52
‪lightninggun_arc_killcam
‪function lightninggun_arc_killcam(arc_source_pos, arc_target, arc_target_pos, original_killcam_ent, waitTime)
Definition: _lightninggun.gsc:85
‪LIGHTNINGGUN_FX_TAG
‪#define LIGHTNINGGUN_FX_TAG
Definition: _lightninggun.gsh:7
‪spawn
‪function spawn(v_origin=(0, 0, 0), v_angles=(0, 0, 0))
Definition: struct.csc:23
‪LIGHTNINGGUN_ARC_FX_MIN_RANGE
‪#define LIGHTNINGGUN_ARC_FX_MIN_RANGE
Definition: _lightninggun.gsh:6
‪delay
‪function delay(time_or_notify, str_endon, func, arg1, arg2, arg3, arg4, arg5, arg6)
Definition: util_shared.csc:784
‪on_damage_lightninggun
‪function on_damage_lightninggun(eAttacker, eInflictor, weapon, meansOfDeath, damage)
Definition: _lightninggun.gsc:300
‪damage
‪function damage(trap)
Definition: _zm_trap_electric.gsc:116
‪lightninggun_arc_fx
‪function lightninggun_arc_fx(arc_source_pos, arc_target, arc_target_pos, distanceSq, original_killcam_ent)
Definition: _lightninggun.gsc:93
‪wait_network_frame
‪function wait_network_frame(n_count=1)
Definition: util_shared.gsc:64
‪create_killcam_entity
‪function create_killcam_entity(origin, angles, weapon)
Definition: _lightninggun.gsc:220
‪LIGHTNINGGUN_ARC_RANGE
‪#define LIGHTNINGGUN_ARC_RANGE
Definition: _lightninggun.gsh:3
‪init_shared
‪function init_shared()
Definition: _lightninggun.gsc:27
‪lightninggun_damage_response
‪function lightninggun_damage_response(eAttacker, eInflictor, weapon, meansOfDeath, damage)
Definition: _lightninggun.gsc:253
‪is_spawn_protected
‪function is_spawn_protected()
Definition: player_shared.gsc:364
‪killcam_move
‪function killcam_move(start_origin, end_origin, time)
Definition: _lightninggun.gsc:229
‪get_other_teams_alive_players_s
‪function get_other_teams_alive_players_s(teamNameToIgnore)
Definition: util_shared.gsc:2839
‪LIGHTNINGGUN_VICTIM_RUMBLE
‪#define LIGHTNINGGUN_VICTIM_RUMBLE
Definition: _lightninggun.gsc:23
‪add_weapon_damage
‪function add_weapon_damage(weapontype, callback)
Definition: callbacks_shared.gsc:580
‪store_killcam_entity_on_entity
‪function store_killcam_entity_on_entity(killcam_entity)
Definition: killcam_shared.gsc:27
‪LIGHTNINGGUN_ELEC_DURATION_MAX
‪#define LIGHTNINGGUN_ELEC_DURATION_MAX
Definition: _lightninggun.gsh:1
‪LIGHTNINGGUN_ARC_SPEED
‪#define LIGHTNINGGUN_ARC_SPEED
Definition: _lightninggun.gsh:4
‪lightninggun_start_damage_effects
‪function lightninggun_start_damage_effects(eAttacker)
Definition: _lightninggun.gsc:64
‪friendlyFireCheck
‪function friendlyFireCheck(owner, attacker, forcedFriendlyFireRule)
Definition: _weaponobjects.gsc:2733
‪LIGHTNINGGUN_ARC_DELAY
‪#define LIGHTNINGGUN_ARC_DELAY
Definition: _lightninggun.gsh:2