‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
fx_shared.csc
Go to the documentation of this file.
1 #using scripts\shared\callbacks_shared;
2 #using scripts\shared\exploder_shared;
3 #using scripts\shared\sound_shared;
4 #using scripts\shared\system_shared;
5 #using scripts\shared\util_shared;
6 
7 #insert scripts\shared\shared.gsh;
8 
9 #namespace fx;
10 
11 ‪REGISTER_SYSTEM( "fx", &‪__init__, undefined )
12 
13 function ‪__init__()
14 {
16 }
17 
18 function ‪player_init(clientNum)
19 {
20  if(!isdefined(level.createFXent))
21  return;
22 
23  creatingExploderArray = false;
24 
25  if(!isdefined(level.createFXexploders))
26  {
27  creatingExploderArray = true;
28 
29  level.createFXexploders = [];
30  }
31 
32  for ( i=0; i<level.createFXent.size; i++ )
33  {
34  ent = level.createFXent[i];
35 
36  // This code my be executed for multiple local clients - only set the
37  // axis up once.
38  if(!isdefined(level._createfxforwardandupset))
39  {
40  // This code my be executed for multiple local clients - only set the
41  // axis up once.
42  if(!isdefined(level._createfxforwardandupset))
43  {
45  }
46  }
47 
48  if (ent.v["type"] == "loopfx")
49  {
50  ent thread ‪loop_thread(clientNum);
51  }
52  if (ent.v["type"] == "oneshotfx")
53  {
54  ent thread ‪oneshot_thread(clientNum);
55  }
56  if (ent.v["type"] == "soundfx")
57  {
58  ent thread ‪loop_sound(clientNum);
59  }
60 
61  if(creatingExploderArray && ent.v["type"] == "exploder")
62  {
63  if(!isdefined(level.createFXexploders[ent.v["exploder"]]))
64  {
65  level.createFXexploders[ent.v["exploder"]] = [];
66  }
67 
68  ent.v["exploder_id"] = ‪exploder::getExploderId( ent );
69 
70  level.createFXexploders[ent.v["exploder"]][level.createFXexploders[ent.v["exploder"]].size] = ent;
71  }
72  }
73 
74  level._createfxforwardandupset = true;
75 }
76 
77 function ‪validate( fxId, origin )
78 {
79 /#
80  if ( !isdefined( level._effect[fxId] ) )
81  {
82  assertmsg( "FX Not Precached: '" + fxId + "' at: " + origin );
83  }
84 #/
85 }
86 
88 {
89  ent = spawnStruct();
90  if (!isdefined(level.createFXent))
91  level.createFXent = [];
92 
93  level.createFXent[level.createFXent.size] = ent;
94  ent.v = [];
95  ent.v["type"] = "soundfx";
96  ent.v["fxid"] = "No FX";
97  ent.v["soundalias"] = "nil";
98  ent.v["angles"] = (0,0,0);
99  ent.v["origin"] = (0,0,0);
100  ent.drawn = true;
101  return ent;
102 }
103 
104 function ‪create_effect( type, fxid )
105 {
106  ent = spawnStruct();
107  if (!isdefined(level.createFXent))
108  level.createFXent = [];
109 
110  level.createFXent[level.createFXent.size] = ent;
111  ent.v = [];
112  ent.v["type"] = type;
113  ent.v["fxid"] = fxid;
114  ent.v["angles"] = (0,0,0);
115  ent.v["origin"] = (0,0,0);
116  ent.drawn = true;
117  return ent;
118 }
119 
120 function ‪create_oneshot_effect( fxid )
121 {
122  ent = ‪create_effect( "oneshotfx", fxid );
123  ent.v[ "delay" ] = -15;
124  return ent;
125 }
126 
127 function ‪create_loop_effect( fxid )
128 {
129  ent = ‪create_effect( "loopfx", fxid );
130  ent.v[ "delay" ] = 0.5;
131  return ent;
132 }
133 
135 {
136  self.v["up"] = anglestoup(self.v["angles"]);
137  self.v["forward"] = anglestoforward(self.v["angles"]);
138 }
139 
140 function ‪oneshot_thread(clientNum)
141 {
142  // This assumes that client scripts start at beginning of level - will need to take
143  // hot join into account (and possibly restart from checkpoint...)
144 
145  if ( self.v["delay"] > 0 )
146  {
147  waitrealtime(self.v["delay"]);
148  }
149 
150  ‪fx::create_trigger(clientNum);
151 }
152 
154 {
155 }
156 
157 function ‪loop_sound(clientNum)
158 {
159  if(clientNum != 0)
160  return;
161 
162  self notify( "stop_loop" );
163 
164  // Note :
165  // Unlike the server side implementation of this - self.looper will contain an fx id, and not an entity
166  // so no threading things on it.
167 
168  if ( isdefined( self.v["soundalias"] ) && ( self.v["soundalias"] != "nil" ) )
169  {
170  if ( isdefined( self.v[ "stopable" ] ) && self.v[ "stopable" ] )
171  {
172  thread ‪sound::loop_fx_sound( clientNum, self.v["soundalias"], self.v["origin"], "stop_loop" );
173  }
174  else
175  {
176  thread ‪sound::loop_fx_sound( clientNum, self.v["soundalias"], self.v["origin"] );
177  }
178  }
179 
180 }
181 
182 function ‪lightning(normalFunc, flashFunc)
183 {
184  [[flashFunc]]();
185 
186  // SRS 5/28/2008: updated to include a call back to the normal function
187  waitrealtime(RandomFloatRange( 0.05, 0.1 ));
188  [[normalFunc]]();
189 }
190 
191 function ‪loop_thread(clientNum)
192 {
193  if (isdefined (self.fxStart))
194  level waittill ("start fx" + self.fxStart);
195 
196  while (1)
197  {
198  ‪create_looper(clientNum);
199 
200  if (isdefined (self.‪timeout))
201  thread ‪loop_stop(clientNum, self.‪timeout);
202 
203  if (isdefined (self.fxStop))
204  level waittill ("stop fx" + self.fxStop);
205  else
206  return;
207 
208  if (isdefined (self.looperFX))
209  deletefx(clientNum, self.looperFX);
210 
211  if (isdefined (self.fxStart))
212  level waittill ("start fx" + self.fxStart);
213  else
214  return;
215  }
216 }
217 
218 function ‪loop_stop(clientNum, ‪timeout)
219 {
220  self endon("death");
221  wait(‪timeout);
222 
223  if(isdefined(self.looper))
224  {
225  deletefx(clientNum, self.looper);
226  }
227 }
228 
229 //T7 - SP version, check differences to make sure we have the proper checks
230 /*function loop_stop(clientNum, timeout)
231 {
232  self endon("death");
233  waitrealtime(timeout);
234 
235  if(isdefined(self.looper))
236  self.looper delete();
237 
238  if(isdefined(self.looperFX))
239  DeleteFx(clientNum, self.looperFX);
240 }*/
241 
242 function ‪create_looper(clientNum)
243 {
244  self thread ‪fx::loop(clientNum);
245  ‪loop_sound(clientNum);
246 }
247 
248 function ‪loop(clientNum)
249 {
250  ‪validate( self.v["fxid"], self.v["origin"] );
251 
252  self.looperFX = PlayFX( clientNum, level._effect[self.v["fxid"]], self.v["origin"], self.v["forward"], self.v["up"], self.v["delay"], self.v[ "primlightfrac" ], self.v[ "lightoriginoffs" ] );
253 
254  while( 1 )
255  {
256  if( isdefined(self.v["delay"]) )
257  {
258  waitrealtime( self.v["delay"] );//TODO T7 - MP version used serverwait, which is better?
259  // Server wait is linked to the server time, this make it work with demos and killcams when the time gets slowed so does this
260  }
261 
262  while( isfxplaying( clientNum, self.looperFX ) )
263  {
264  wait 0.25;//T7 - was 0.1 in SP
265  }
266 
267  self.looperFX = PlayFX( clientNum, level._effect[self.v["fxid"]], self.v["origin"], self.v["forward"], self.v["up"], 0, self.v[ "primlightfrac" ], self.v[ "lightoriginoffs" ] );
268  }
269 }
270 
271 function ‪create_trigger(clientNum)
272 {
273  ‪validate( self.v["fxid"], self.v["origin"] );
274 
275  self.looperFX = PlayFX( clientNum, level._effect[self.v["fxid"]], self.v["origin"], self.v["forward"], self.v["up"], self.v["delay"], self.v[ "primlightfrac" ], self.v[ "lightoriginoffs" ] );
276 
277  ‪loop_sound(clientNum);
278 }
279 
280 function ‪blinky_light( localClientNum, tagName, friendlyfx, enemyfx ) // self == equipment
281 {
282  self endon( "entityshutdown" );
283  self endon( "stop_blinky_light" );
284 
285  self.lightTagName = tagName;
286 
287  self ‪util::waittill_dobj(localClientNum);
288 
289  self thread ‪blinky_emp_wait(localClientNum);
290 
291  while( true )
292  {
293  if( isdefined( self.stunned ) && self.stunned )
294  {
295  wait( 0.1 );
296  continue;
297  }
298 
299  if ( isdefined( self ) )
300  {
301  if ( ‪util::friend_not_foe(localClientNum) )
302  {
303  self.blinkyLightFx = PlayFXOnTag( localClientNum, friendlyfx, self, self.lightTagName );
304  }
305  else
306  {
307  self.blinkyLightFx = PlayFXOnTag( localClientNum, enemyfx, self, self.lightTagName );
308  }
309  }
310 
311  ‪util::server_wait( localClientNum, 0.5, ‪CLIENT_FRAME );
312  }
313 }
314 
315 function ‪stop_blinky_light(localClientNum)
316 {
317  self notify( "stop_blinky_light" );
318 
319  if ( !isdefined( self.blinkyLightFx ) )
320  {
321  return;
322  }
323 
324  stopfx(localClientNum, self.blinkyLightFx);
325  self.blinkyLightFx = undefined;
326 }
327 
328 function ‪blinky_emp_wait(localClientNum)
329 {
330  self endon( "entityshutdown" );
331  self endon( "stop_blinky_light" );
332 
333  self waittill( "emp" );
334 
335  self ‪stop_blinky_light( localClientNum );
336 }
‪timeout
‪function timeout(n_time, func, arg1, arg2, arg3, arg4, arg5, arg6)
Definition: util_shared.csc:762
‪loop_thread
‪function loop_thread(clientNum)
Definition: fx_shared.csc:191
‪validate
‪function validate(fxId, origin)
Definition: fx_shared.csc:77
‪loop_fx_sound
‪function loop_fx_sound(clientNum, alias, origin, ender)
Definition: sound_shared.csc:5
‪loop_stop
‪function loop_stop(clientNum, timeout)
Definition: fx_shared.csc:218
‪blinky_emp_wait
‪function blinky_emp_wait(localClientNum)
Definition: fx_shared.csc:328
‪stop_blinky_light
‪function stop_blinky_light(localClientNum)
Definition: fx_shared.csc:315
‪friend_not_foe
‪function friend_not_foe(localClientIndex, predicted)
Definition: util_shared.csc:1164
‪__init__
‪function __init__()
Definition: fx_shared.csc:13
‪report_num_effects
‪function report_num_effects()
Definition: fx_shared.csc:153
‪create_loop_effect
‪function create_loop_effect(fxid)
Definition: fx_shared.csc:127
‪loop
‪function loop(clientNum)
Definition: fx_shared.csc:248
‪CLIENT_FRAME
‪#define CLIENT_FRAME
Definition: shared.gsh:263
‪on_localclient_connect
‪function on_localclient_connect(localClientNum)
Definition: ctf.csc:20
‪lightning
‪function lightning(normalFunc, flashFunc)
Definition: fx_shared.csc:182
‪loop_sound
‪function loop_sound(clientNum)
Definition: fx_shared.csc:157
‪create_trigger
‪function create_trigger(clientNum)
Definition: fx_shared.csc:271
‪blinky_light
‪function blinky_light(localClientNum, tagName, friendlyfx, enemyfx)
Definition: fx_shared.csc:280
‪create_effect
‪function create_effect(type, fxid)
Definition: fx_shared.csc:104
‪player_init
‪function player_init(clientNum)
Definition: fx_shared.csc:18
‪oneshot_thread
‪function oneshot_thread(clientNum)
Definition: fx_shared.csc:140
‪getExploderId
‪function getExploderId(ent)
Definition: exploder_shared.csc:265
‪REGISTER_SYSTEM
‪#define REGISTER_SYSTEM(__sys, __func_init_preload, __reqs)
Definition: shared.gsh:204
‪create_oneshot_effect
‪function create_oneshot_effect(fxid)
Definition: fx_shared.csc:120
‪waittill_dobj
‪function waittill_dobj(localClientNum)
Definition: util_shared.csc:1117
‪set_forward_and_up_vectors
‪function set_forward_and_up_vectors()
Definition: fx_shared.csc:134
‪create_loop_sound
‪function create_loop_sound()
Definition: fx_shared.csc:87
‪create_looper
‪function create_looper(clientNum)
Definition: fx_shared.csc:242
‪server_wait
‪function server_wait(localClientNum, seconds, waitBetweenChecks, level_endon)
Definition: util_shared.csc:1125