‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
_flashgrenades.gsc
Go to the documentation of this file.
1 #using scripts\codescripts\struct;
2 
3 #using scripts\shared\callbacks_shared;
4 #using scripts\shared\clientfield_shared;
5 #using scripts\shared\util_shared;
6 #using scripts\shared\system_shared;
7 
8 #insert scripts\shared\shared.gsh;
9 #insert scripts\shared\version.gsh;
10 
11 #namespace flashgrenades;
12 
13 function ‪init_shared()
14 {
15  level.sound_flash_start = "";
16  level.sound_flash_loop = "";
17  level.sound_flash_stop = "";
18 
20 }
21 
22 function ‪flashRumbleLoop( duration )
23 {
24  self endon("stop_monitoring_flash");
25 
26  self endon("flash_rumble_loop");
27  self notify("flash_rumble_loop");
28 
29  goalTime = getTime() + duration * 1000;
30 
31  while ( getTime() < goalTime )
32  {
33  self PlayRumbleOnEntity( "damage_heavy" );
35  }
36 }
37 
38 
39 function ‪monitorFlash_Internal(amount_distance, amount_angle, attacker, direct_on_player)
40 {
41  hurtattacker = false;
42  hurtvictim = true;
43 
44  /*
45  if ( amount_angle < 0.5 )
46  {
47  amount_angle = 0.5;
48  }
49  else if ( amount_angle > 0.8 )
50  {
51  amount_angle = 1;
52  }
53  */
54 
55  //duration = amount_distance * amount_angle * 6; // TFLAME - 2/7/15 - The angle input is making it unreadable and inconsistent how enemies are being affected based on hitmarker. Removing for now.
56 
57  duration = amount_distance * 3.5;
58 
59 
60  min_duration = 2.5; // TFLAME - 2/10/15 - The old calculation here is hard to read and very inconsistent. Lets have a min/max and be done with it.
61  max_self_duration = 2.5;
62 
63  if ( duration < min_duration )
64  {
65  duration = min_duration;
66  }
67 
68  if ( isdefined( attacker ) && (attacker == self) ) // TFLAME - 8/1/12 - Don't want tacticals to be too frustrating to use, reducing amount they affect player using them
69  {
70  duration = duration/3;
71  }
72 
73  if ( duration < 0.25 )
74  {
75  return;
76  }
77 
78  rumbleduration = undefined;
79 
80  if ( duration > 2 )
81  {
82  rumbleduration = 0.75;
83  }
84  else
85  {
86  rumbleduration = 0.25;
87  }
88 
89  assert(isdefined(self.team));
90 
91  if (level.teamBased && isdefined(attacker) && isdefined(attacker.team) && attacker.team == self.team && attacker != self)
92  {
93  friendlyfire = [[ level.figure_out_friendly_fire]]( self );
94 
95  if ( friendlyfire == 0 ) // no FF
96  {
97  return;
98  }
99  else if ( friendlyfire == 1 ) // FF
100  {
101  }
102  else if ( friendlyfire == 2) // reflect
103  {
104  duration = duration * .5;
105  rumbleduration = rumbleduration * .5;
106  hurtvictim = false;
107  hurtattacker = true;
108  }
109  else if ( friendlyfire == 3 ) // share
110  {
111  duration = duration * .5;
112  rumbleduration = rumbleduration * .5;
113  hurtattacker = true;
114  }
115  }
116 
117  if ( self hasPerk ("specialty_flashprotection") )
118  {
119  // do a little bit, not a complete negation
120  duration *= 0.1;
121  rumbleduration *= 0.1;
122  }
123 
124  if (hurtvictim)
125  {
126  // No flashbang effect if in vehicle
127  if ( self ‪util::mayApplyScreenEffect() || (!direct_on_player && (self IsRemoteControlling()) ) )
128  {
129  if( isDefined(attacker) && self != attacker &&isPlayer(attacker) )
130  {
131  attacker AddWeaponStat( GetWeapon( "flash_grenade" ), "hits", 1 );
132  attacker AddWeaponStat( GetWeapon( "flash_grenade" ), "used", 1 );
133  }
134  self thread ‪applyFlash(duration, rumbleduration, attacker);
135  }
136  }
137 
138  if (hurtattacker)
139  {
140  // No flashbang effect if in vehicle
141  if ( attacker ‪util::mayApplyScreenEffect() )
142  attacker thread ‪applyFlash(duration, rumbleduration, attacker);
143  }
144 }
145 
146 function ‪monitorFlash()
147 {
148  self endon("disconnect");
149  self endon ("killFlashMonitor");
150 
151  self.flashEndTime = 0;
152  while(1)
153  {
154  self waittill( "flashbang", amount_distance, amount_angle, attacker );
155 
156  if ( !isalive( self ) )
157  {
158  continue;
159  }
160 
161  self ‪monitorFlash_Internal(amount_distance, amount_angle, attacker, true);
162  }
163 }
164 
166 {
167  self endon("death");
168  self.flashEndTime = 0;
169  while(1)
170  {
171  self waittill( "flashbang", amount_distance, amount_angle, attacker );
172 
173  driver = self getseatoccupant(0);
174 
175  if ( !isdefined(driver) || !isalive( driver ) )
176  {
177  continue;
178  }
179 
180  driver ‪monitorFlash_Internal(amount_distance, amount_angle, attacker, false);
181  }
182 }
183 
184 function ‪applyFlash(duration, rumbleduration, attacker)
185 {
186  // wait for the highest flash duration this frame,
187  // and apply it in the following frame
188 
189  if (!isdefined(self.flashDuration) || duration > self.flashDuration)
190  {
191  self.flashDuration = duration;
192  }
193 
194  if (!isdefined(self.flashRumbleDuration) || rumbleduration > self.flashRumbleDuration)
195  {
196  self.flashRumbleDuration = rumbleduration;
197  }
198 
199  self thread ‪playFlashSound( duration );
200 
201  wait .05;
202 
203  if (isdefined(self.flashDuration))
204  {
205  if ( self hasPerk ("specialty_flashprotection") == false )
206  {
207  self shellshock( "flashbang", self.flashDuration, false );
208  }
209  self.flashEndTime = getTime() + (self.flashDuration * 1000);
210  self.lastFlashedBy = attacker;
211  }
212 
213  if (isdefined(self.flashRumbleDuration)) {
214  self thread ‪flashRumbleLoop( self.flashRumbleDuration ); //TODO: Non-hacky rumble.
215  }
216 
217  self.flashDuration = undefined;
218  self.flashRumbleDuration = undefined;
219 }
220 
221 function ‪playFlashSound( duration )
222 {
223  self endon( "death" );
224  self endon( "disconnect" );
225 
226  flashSound = ‪spawn ("script_origin",(0,0,1));
227  flashSound.origin = self.origin;
228  flashSound linkTo( self );
229  flashSound thread ‪deleteEntOnOwnerDeath( self );
230 
231  flashSound playsound( level.sound_flash_start );
232  flashSound playLoopSound ( level.sound_flash_loop );
233  if ( duration > 0.5 )
234  wait( duration - 0.5 );
235  flashSound playsound( level.sound_flash_start );
236  flashSound StopLoopSound( .5);
237  wait(0.5);
238 
239  flashSound notify ( "delete" );
240  flashSound delete();
241 }
242 
243 function ‪deleteEntOnOwnerDeath( owner )
244 {
245  self endon( "delete" );
246  owner waittill( "death" );
247  self delete();
248 }
249 
250 /*util::isFlashbanged()
251 {
252  return isdefined( self.flashEndTime ) && gettime() < self.flashEndTime;
253 }
254 */
‪spawn
‪function spawn(v_origin=(0, 0, 0), v_angles=(0, 0, 0))
Definition: struct.csc:23
‪monitorRCBombFlash
‪function monitorRCBombFlash()
Definition: _flashgrenades.gsc:165
‪monitorFlash_Internal
‪function monitorFlash_Internal(amount_distance, amount_angle, attacker, direct_on_player)
Definition: _flashgrenades.gsc:39
‪init_shared
‪function init_shared()
Definition: _flashgrenades.gsc:13
‪flashRumbleLoop
‪function flashRumbleLoop(duration)
Definition: _flashgrenades.gsc:22
‪applyFlash
‪function applyFlash(duration, rumbleduration, attacker)
Definition: _flashgrenades.gsc:184
‪playFlashSound
‪function playFlashSound(duration)
Definition: _flashgrenades.gsc:221
‪deleteEntOnOwnerDeath
‪function deleteEntOnOwnerDeath(owner)
Definition: _flashgrenades.gsc:243
‪monitorFlash
‪function monitorFlash()
Definition: _flashgrenades.gsc:146
‪on_connect
‪function on_connect()
Definition: _arena.gsc:20
‪mayApplyScreenEffect
‪function mayApplyScreenEffect()
Definition: util_shared.gsc:2613
‪WAIT_SERVER_FRAME
‪#define WAIT_SERVER_FRAME
Definition: shared.gsh:265