‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
_empgrenade.csc
Go to the documentation of this file.
1 #using scripts\codescripts\struct;
2 
3 #using scripts\shared\audio_shared;
4 #using scripts\shared\callbacks_shared;
5 #using scripts\shared\clientfield_shared;
6 #using scripts\shared\system_shared;
7 #using scripts\shared\util_shared;
8 #using scripts\shared\visionset_mgr_shared;
9 #using scripts\shared\weapons\_flashgrenades;
10 #using scripts\shared\filter_shared;
11 #using scripts\shared\math_shared;
12 
13 #insert scripts\shared\shared.gsh;
14 #insert scripts\shared\version.gsh;
15 
16 #namespace empgrenade;
17 ‪REGISTER_SYSTEM( "empgrenade", &‪__init__, undefined )
18 
19 
20 function ‪__init__()
21 {
24 
25  ‪callback::on_spawned( &‪on_player_spawned ); // TODO: utilize on_local_player_spawned when it becomes available
26 }
27 
28 function ‪onEmpChanged( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump )
29 {
30  localPlayer = GetLocalPlayer( localClientNum );
31 
32  if( newVal == 1 )
33  {
34  self ‪StartEmpEffects( localPlayer );
35  }
36  else
37  {
38  already_distance_monitored = ( localPlayer ‪clientfield::get_to_player( "empd_monitor_distance" ) == 1 );
39  if ( !already_distance_monitored )
40  {
41  self ‪StopEmpEffects( localPlayer, oldVal );
42  }
43  }
44 }
45 
46 function ‪StartEmpEffects( localPlayer, bWasTimeJump = false )
47 {
48  ‪filter::init_filter_tactical( localPlayer );
49 
52 
53  if ( !bWasTimeJump )
54  playsound( 0, "mpl_plr_emp_activate", (0,0,0) );
55 
56  ‪audio::playloopat( "mpl_plr_emp_looper", (0,0,0) );
57 }
58 
59 function ‪StopEmpEffects( localPlayer, oldVal, bWasTimeJump = false )
60 {
61  ‪filter::init_filter_tactical( localPlayer );
62 
64 
65  if( oldVal != 0 && !bWasTimeJump )
66  playsound( 0, "mpl_plr_emp_deactivate", (0,0,0) );
67 
68  ‪audio::stoploopat( "mpl_plr_emp_looper", (0,0,0) );
69 }
70 
71 
72 function ‪on_player_spawned( localClientNum )
73 {
74  self endon( "disconnect" );
75 
76  localPlayer = GetLocalPlayer( localClientNum );
77 
78  if ( localPlayer != self )
79  return;
80 
81  curVal = localPlayer ‪clientfield::get_to_player( "empd_monitor_distance" );
82  inKillCam = GetInKillcam( localClientNum );
83 
84  if ( curVal > 0 && localPlayer IsEMPJammed() )
85  {
86  ‪StartEmpEffects( localPlayer, inKillCam ); // only start sound if we are not in killcam
87  localPlayer ‪MonitorDistance( localClientNum );
88  }
89  else
90  {
91  ‪StopEmpEffects( localPlayer, 0, true ); // never play the turn off sound when spawning in
92  localPlayer notify( "end_emp_monitor_distance" );
93  }
94 }
95 
96 function ‪onEmpMonitorDistanceChanged( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump )
97 {
98  localPlayer = GetLocalPlayer( localClientNum );
99 
100  if ( newVal == 1 )
101  {
102  ‪StartEmpEffects( localPlayer, bWasTimeJump );
103  localPlayer ‪MonitorDistance( localClientNum );
104  }
105  else
106  {
107  ‪StopEmpEffects( localPlayer, oldVal, bWasTimeJump );
108  localPlayer notify( "end_emp_monitor_distance" );
109  }
110 }
111 
112 function ‪MonitorDistance( localClientNum )
113 {
114  localPlayer = self;
115 
116  localPlayer endon( "entityshutdown" );
117  localPlayer endon( "end_emp_monitor_distance" );
118  localPlayer endon( "team_changed" );
119 
120  if ( localPlayer IsEMPJammed() == false )
121  return;
122 
123  distance_to_closest_enemy_emp_ui_model = GetUIModel( GetUIModelForController( localClientNum ), "distanceToClosestEnemyEmpKillstreak" );
124 
125  new_distance = 0.0;
126 
127  max_static_value = GetDvarFloat( "ks_emp_fullscreen_maxStaticValue" );
128  min_static_value = GetDvarFloat( "ks_emp_fullscreen_minStaticValue" );
129  min_radius_max_static = GetDvarFloat( "ks_emp_fullscreen_minRadiusMaxStatic" );
130  max_radius_min_static = GetDvarFloat( "ks_emp_fullscreen_maxRadiusMinStatic" );
131 
132  if ( isdefined( distance_to_closest_enemy_emp_ui_model ) )
133  {
134  while( true )
135  {
136 
137  // calculate effect factor based on distance
138  new_distance = GetUIModelValue( distance_to_closest_enemy_emp_ui_model );
139  range = max_radius_min_static - min_radius_max_static;
140  current_static_value = max_static_value - ( ( range <= 0.0 ) ? max_static_value : ( ( new_distance - min_radius_max_static ) / range ) );
141  current_static_value = ‪math::clamp( current_static_value, min_static_value, max_static_value );
142 
143  // emp grenaded has full screen effect
144  emp_grenaded = ( localPlayer ‪clientfield::get_to_player( "empd" ) == 1 );
145  if ( emp_grenaded && current_static_value < 1.0 )
146  {
147  current_static_value = 1.0;
148  }
149 
150  // update filter effects
151  ‪filter::set_filter_tactical_amount( localPlayer, ‪FILTER_INDEX_EMP, current_static_value );
152 
153  wait 0.1;
154  }
155  }
156 }
‪onEmpMonitorDistanceChanged
‪function onEmpMonitorDistanceChanged(localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump)
Definition: _empgrenade.csc:96
‪StopEmpEffects
‪function StopEmpEffects(localPlayer, oldVal, bWasTimeJump=false)
Definition: _empgrenade.csc:59
‪get_to_player
‪function get_to_player(field_name)
Definition: clientfield_shared.csc:38
‪set_filter_tactical_amount
‪function set_filter_tactical_amount(player, filterid, amount)
Definition: filter_shared.csc:442
‪stoploopat
‪function stoploopat(aliasname, origin)
Definition: audio_shared.csc:914
‪CF_CALLBACK_ZERO_ON_NEW_ENT
‪#define CF_CALLBACK_ZERO_ON_NEW_ENT
Definition: version.gsh:103
‪VERSION_SHIP
‪#define VERSION_SHIP
Definition: version.gsh:36
‪MonitorDistance
‪function MonitorDistance(localClientNum)
Definition: _empgrenade.csc:112
‪disable_filter_tactical
‪function disable_filter_tactical(player, filterid)
Definition: filter_shared.csc:447
‪on_spawned
‪function on_spawned(func, obj)
Definition: callbacks_shared.csc:245
‪__init__
‪function __init__()
Definition: _empgrenade.csc:20
‪CF_HOST_ONLY
‪#define CF_HOST_ONLY
Definition: version.gsh:102
‪REGISTER_SYSTEM
‪#define REGISTER_SYSTEM(__sys, __func_init_preload, __reqs)
Definition: shared.gsh:204
‪FILTER_INDEX_EMP
‪#define FILTER_INDEX_EMP
Definition: shared.gsh:484
‪on_player_spawned
‪function on_player_spawned(localClientNum)
Definition: _empgrenade.csc:72
‪register
‪function register()
Definition: _ai_tank.gsc:126
‪clamp
‪function clamp(val, val_min, val_max)
Definition: math_shared.csc:16
‪StartEmpEffects
‪function StartEmpEffects(localPlayer, bWasTimeJump=false)
Definition: _empgrenade.csc:46
‪enable_filter_tactical
‪function enable_filter_tactical(player, filterid)
Definition: filter_shared.csc:436
‪init_filter_tactical
‪function init_filter_tactical(player)
Definition: filter_shared.csc:429
‪playloopat
‪function playloopat(aliasname, origin)
Definition: audio_shared.csc:909
‪onEmpChanged
‪function onEmpChanged(localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump)
Definition: _empgrenade.csc:28