‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
_elevator.gsc
Go to the documentation of this file.
1 #using scripts\codescripts\struct;
2 
3 #using scripts\shared\array_shared;
4 #using scripts\shared\sound_shared;
5 #using scripts\shared\system_shared;
6 
7 #insert scripts\shared\shared.gsh;
8 
9 /*
10 Elevators and You: A Consice Guide.
11 Bloodlust
12 
13 First place a script_model or create a script_brushmodel to be used for the elevator platform.
14 
15 Make a trigger_use if you want a switch operated elevator.
16 Make a trigger_multiple if you want a Quake style elevator.
17 
18 Give this trigger a targetname of elevator_trigger.
19 
20 If making a switch operated elevator, place a script_model or script_brushmodel in the map where you want the switch.
21 Make the trigger target the newly created switch entity.
22 
23 If making a Quake style elevator, make the trigger target the elevator platform entity.
24 
25 Place a script_struct dead center of the platform entity at the bottom point in the platform's route.
26 Place a script_struct dead center of the platform entity at the next point in the platform's route.
27 Continue placing script_structs dead center of the platform entity at the next point in the platform's route.
28 These can be placed in any direction, not just straight up and down. Just ensure the platform will center on them.
29 
30 Give the bottom script_struct a script_noteworthy of platform_start.
31 Make the platform entity target this script_struct.
32 Make this script_struct target the next script_struct in the elevator's path.
33 Continue making the elevator's path by targeting the path script_structs to eachother.
34 
35 
36 Optional:
37 
38 If you want to play hydraulic or machinery sounds for the elevator, place a script_struct where you want the sound to play.
39 Make the platform target this script_struct.
40 Give this script_struct a script_noteworthy of audio_point.
41 Define a variable in your level script of level.scr_sound["description"] = "actual_sound_alias".
42 The "description" can be any description you want to use, such as "hydraulics".
43 the "actual_sound_alias" must be an actual sound alias defined in your level's csv or a common csv.
44 Give this script_struct a script_sound of whatever you defined as "description".
45 You can place as many script_structs this way as you want.
46 
47 
48 Optional:
49 
50 If you want an alarm sound to play when the elevator is activated, place a script_model or script_brushmodel where you want the sound to play.
51 Make the platform target this entity.
52 Give this entity a script_noteworthy of elevator_klaxon_speaker.
53 Define a variable in your level script of level.scr_sound["description"] = "actual_sound_alias".
54 The "description" can be any description you want to use, such as "alarm_sound".
55 the "actual_sound_alias" must be an actual sound alias defined in your level's csv or a common csv.
56 Give this entity a script_sound of whatever you defined as "description".
57 You can place as many entities this way as you want.
58 
59 
60 Optional:
61 
62 If you want a gate or gates to animate when the elevator is activated, place a script_model or script_brushmodel to use as the gate.
63 Do NOT rotate the gate or place it where you want the gate to be. This will be handled by the _elevator.gsc utility script.
64 Make the platform target this gate.
65 Give this gate a script_noteworthy of elevator_gate.
66 Give this gate a script_int equal to the amount of degrees you want it to rotate, ie: 90
67 Place a script_struct where you want the gate to be centered and have the gate target this script_struct.
68 Rotate this script_struct in the direction you want the gate to move.
69 You can place as many gates per elevator this way as you want.
70 
71 Define a variable in your level script of level.scr_sound["description"] = "actual_sound_alias".
72 The "description" can be any description you want to use, such as "gate_rotate".
73 the "actual_sound_alias" must be an actual sound alias defined in your level's csv or a common csv.
74 Give this gate a script_sound of whatever you defined as "description".
75 
76 
77 Optional:
78 
79 If you dont specify a speed for your elevator platform in Radiant, it will default to 100.
80 function To set the speed, make a K/V pair of speed / 100 (or whatever speed you want).
81 Each individual platform can have a different speed set to it if you want.
82 This is the speed of the platform in MPH.
83 Do not set a speed K/V pair on the script_struct that the platform targets;
84 set it on THAT script_struct's target instead.
85 You can then set any positive whole number value for speed on the rest of the script_structs that make up the elevator's path if you want to.
86 
87 If you dont specify a speed for your elevator platform gates in Radiant, it will default to 1.
88 This is how many seconds the platform gates, if you included any in your level, will take to rotate when they are raised or lowered.
89 function To set the speed, make a K/V pair of speed / 1 (or whatever speed you want).
90 This speed should be defined in seconds, not actual speed in MPH like the platforms.
91 This speed must also be a whole number, no fractions!
92 
93 If you dont specify an amount of degrees for your elevator platform gates to rotate in Radiant, it will default to 90.
94 function To set the desired amount of angles, make a K/V pair of script_int / 90 (or whatever angle you want).
95 Each individual platform can have a different angle set to it if you want.
96 
97 
98 Notes of Interest:
99 
100 Platforms and platform switches must be either a script_model or a script_brushmodel.
101 You can use a prefab for the platform that actually moves, but you must stamp it into your level.
102 You cannot have a trigger or switch target a prefab.
103 
104 You can setup the elevator and all its parts, then save this as a prefab, and copy and paste
105 this prefab into the level where ever you want to. Be certain that your platform triggers inside the prefab retain their
106 targetname of elevator_trigger though, as it may change when you make the prefab and paste it around the level.
107 */
108 
109 #namespace elevator;
110 
111 ‪REGISTER_SYSTEM( "elevator", &‪__init__, undefined )
112 
113 function ‪__init__()
114 {
115  platform_triggers = getEntArray("elevator_trigger", "targetname");
116  if(platform_triggers.size <= 0)
117  {
118  return;
119  }
120 
121  platform_switches = [];
122  platforms_non_switched = [];
123  platforms_total = [];
124  trigger_target_targets = [];
125 
126  for(i = 0; i < platform_triggers.size; i++)
127  {
128  trigger_target = getEnt(platform_triggers[i].target, "targetname");
129 
130  if(!isdefined(trigger_target))
131  {
132  AssertMsg("This trigger does not have a target: " + platform_triggers[i].origin);
133  }
134 
135  // does the trigger target a switch model or just a platform?
136  if(isdefined(trigger_target))
137  {
138  trigger_target_targets = getEntArray(trigger_target.target, "targetname");
139 
140  // if the trigger's target has only 1 target, then the trigger is targeting a switch model, not a platform
141  if(isdefined(trigger_target_targets) && (trigger_target_targets.size == 1))
142  {
143  platform_switches[platform_switches.size] = trigger_target;
144  }
145  else
146  {
147  platforms_non_switched[platforms_non_switched.size] = trigger_target;
148  }
149  }
150  }
151 
152  for(i = 0; i < platform_switches.size; i++)
153  {
154  platform = getEnt(platform_switches[i].target, "targetname");
155 
156  if(!isdefined(platform))
157  {
158  AssertMsg("This switch does not target a platform: " + platform_switches[i].origin);
159  }
160  else
161  {
162  counter = 0;
163 
164  for(x = 0; x < platforms_total.size; x++)
165  {
166  if(platform == platforms_total[x])
167  {
168  counter++;
169  }
170  }
171 
172  if(counter > 0)
173  {
174  continue;
175  }
176  else
177  {
178  platforms_total[platforms_total.size] = platform;
179  }
180  }
181  }
182 
183  for(i = 0; i < platforms_non_switched.size; i++)
184  {
185  counter = 0;
186 
187  for(x = 0; x < platforms_total.size; x++)
188  {
189  if(platforms_non_switched[i] == platforms_total[x])
190  {
191  counter++;
192  }
193  }
194 
195  if(counter > 0)
196  {
197  continue;
198  }
199  else
200  {
201  platforms_total[platforms_total.size] = platforms_non_switched[i];
202  }
203  }
204 
205  array::thread_all(platforms_total,&‪define_elevator_parts);
206 }
207 
208 // self = the platform
210 {
211  audio_points = [];
212  klaxon_speakers = [];
213  elevator_gates = [];
214  platform_start = undefined;
215 
216  platform = self;
217  platform_name = platform.targetname;
218  platform.at_start = true;
219 
220  platform_triggers = [];
221  targets_platform = getEntArray(platform_name, "target");
222 
223 
224  for(i = 0; i < targets_platform.size; i++)
225  {
226  if(targets_platform[i].classname == "script_model" || targets_platform[i].classname == "script_brushmodel")
227  {
228  switch_trigger = getEnt(targets_platform[i].targetname, "target");
229  platform_triggers[platform_triggers.size] = switch_trigger;
230  }
231  else
232  {
233  platform_triggers[platform_triggers.size] = targets_platform[i];
234  }
235  }
236 
237  platform_targets_Ents = getEntArray(platform.target, "targetname");
238  platform_targets_Structs = ‪struct::get_array(platform.target, "targetname");
239  platform_targets = ArrayCombine(platform_targets_Ents, platform_targets_Structs, true, false);
240 
241  if(platform_targets.size <= 0)
242  {
243  AssertMsg("This platform does not have any targets: " + platform.origin);
244  }
245 
246  if(isdefined(platform_targets))
247  {
248  for(i = 0; i < platform_targets.size; i++)
249  {
250  if(isdefined(platform_targets[i].script_noteworthy))
251  {
252  if(platform_targets[i].script_noteworthy == "audio_point")
253  {
254  audio_points[audio_points.size] = platform_targets[i];
255  }
256 
257  if(platform_targets[i].script_noteworthy == "elevator_gate")
258  {
259  elevator_gates[elevator_gates.size] = platform_targets[i];
260  }
261 
262  if(platform_targets[i].script_noteworthy == "elevator_klaxon_speaker")
263  {
264  klaxon_speakers[klaxon_speakers.size] = platform_targets[i];
265  }
266 
267  if(platform_targets[i].script_noteworthy == "platform_start")
268  {
269  platform_start = platform_targets[i];
270  }
271  }
272  }
273  }
274 
275  if(!isdefined(platform_start))
276  {
277  AssertMsg("This platform does not target a script_struct with a script_noteworthy of platform_start: " + platform.origin);
278  }
279 
280  if(isdefined(elevator_gates) && (elevator_gates.size >0))
281  {
282  array::thread_all(elevator_gates,&‪setup_elevator_gates, platform_name);
283  }
284 
285  if(isdefined(klaxon_speakers) && (klaxon_speakers.size >0))
286  {
287  array::thread_all(klaxon_speakers,&‪elevator_looping_sounds, "elevator_" + platform_name + "_move", "stop_" + platform_name + "_movement_sound");
288  }
289 
290  if(isdefined(audio_points) && (audio_points.size >0))
291  {
292  array::thread_all(audio_points,&‪elevator_looping_sounds, "start_" + platform_name + "_klaxon", "stop_" + platform_name + "_klaxon");
293  }
294 
295  array::thread_all(platform_triggers,&‪trigger_think, platform_name);
296 
297  platform thread ‪move_platform(platform_start, platform_name);
298 }
299 
300 // each seperate platform trigger in the level is run through this function
301 // self = the trigger
302 function ‪trigger_think(platform_name)
303 {
304  while(1)
305  {
306  self waittill("trigger");
307 
308  // start the platform motion klaxon alarm
309  level notify("start_" + platform_name + "_klaxon");
310 
311  wait 2;
312 
313  // start the platform moving
314  level notify("elevator_" + platform_name + "_move");
315 
316  level waittill("elevator_" + platform_name + "_stop");
317 
318  // stop the platform motion klaxon alarm
319  level notify("stop_" + platform_name + "_klaxon");
320  }
321 }
322 
323 // play any looping sounds if its defined by self.script_sound
324 // self = the entity to play the sound at its origin
325 function ‪elevator_looping_sounds(notify_play, notify_stop)
326 {
327  level waittill(notify_play);
328 
329  if(isdefined(self.script_sound))
330  {
331  self thread ‪sound::loop_in_space(level.scr_sound[self.script_sound], self.origin, notify_stop);
332  }
333 }
334 
335 // self = the gate
336 function ‪setup_elevator_gates(platform_name)
337 {
338  struct = ‪struct::get(self.target, "targetname");
339  if(!isdefined(struct))
340  {
341  AssertMsg("This gate does not target a script_struct: " + self.origin);
342  }
343 
344  self.origin = struct.origin;
345  self.angles = struct.angles;
346 
347  self thread ‪move_elevator_gates(platform_name, "raise_");
348  self thread ‪move_elevator_gates(platform_name, "lower_");
349 }
350 
351 // self = the gate
352 function ‪move_elevator_gates(platform_name, direction)
353 {
354  // amount of degrees to rotate the gate
355  amount = undefined;
356  // speed at which to rotate the gate
357  speed = undefined;
358 
359  if(isdefined(self.script_int))
360  {
361  amount = (self.script_int);
362  }
363  else
364  {
365  amount = (90);
366  }
367 
368  if(direction == "raise_")
369  {
370  amount = (amount * -1);
371  }
372 
373  if(isdefined(self.‪script_delay))
374  {
375  speed = self.script_delay;
376  }
377  else
378  {
379  speed = 1;
380  }
381 
382  while(1)
383  {
384  level waittill(direction + platform_name + "_gates");
385  self rotatePitch(amount, speed);
386  }
387 }
388 
389 // self = the platform
390 function ‪move_platform(platform_start, platform_name)
391 {
392  move_up = [];
393  move_down = [];
394 
395  move_up[move_up.size] = platform_start;
396 
397  platform_start_first_target = ‪struct::get(platform_start.target, "targetname");
398 
399  if(!isdefined(platform_start_first_target))
400  {
401  AssertMsg("This platform start point does not have a script_struct target to move to. There needs to be at least two script_structs to make a path for the elevator to move along: " + platform_start.origin);
402  }
403 
404  path = true;
405  pstruct = platform_start;
406 
407  while(path)
408  {
409  if(isdefined(pstruct.target))
410  {
411  pstruct = ‪struct::get(pstruct.target, "targetname");
412 
413  if(isdefined(pstruct))
414  {
415  move_up[move_up.size] = pstruct;
416  }
417  }
418  else
419  {
420  path = false;
421  }
422  }
423 
424  for(i = move_up.size - 1; i >= 0; i--)
425  {
426  move_down[move_down.size] = move_up[i];
427  }
428 
429  while(1)
430  {
431  level waittill("elevator_" + platform_name + "_move");
432 
433  wait 2;
434 
435  if(isdefined(level.scr_sound["elevator_start"]))
436  {
437  self playSound(level.scr_sound["elevator_start"]);
438  }
439 
440  if(self.at_start)
441  {
442  speed = -1;
443 
444  for(i = 0; i < move_up.size; i++)
445  {
446  org = move_up[i + 1];
447 
448  if(isdefined(org))
449  {
450  speed = ‪get_speed(org, speed);
451 
452  // convert speed to a time
453  time = distance(self.origin, org.origin) / speed;
454  self moveto(org.origin, time);
455  wait time;
456  }
457  }
458 
459  // play any metal screeching / groaning sounds if assigned
460  if(isdefined(self.script_sound))
461  {
462  self playSound(level.scr_sound[self.script_sound]);
463  }
464 
465  level notify("elevator_" + platform_name + "_stop");
466  level notify("stop_" + platform_name + "_movement_sound");
467  level notify("stop_" + platform_name + "_klaxon");
468  level notify("lower_" + platform_name + "_gates");
469 
470  if(isdefined(level.scr_sound["elevator_end"]))
471  {
472  self playSound(level.scr_sound["elevator_end"]);
473  }
474 
475  self.at_start = false;
476  }
477  else
478  {
479  level notify("raise_" + platform_name + "_gates");
480 
481  wait 2;
482 
483  level notify("elevator_" + platform_name + "_move");
484 
485  if(isdefined(level.scr_sound["elevator_start"]))
486  {
487  self playSound(level.scr_sound["elevator_start"]);
488  }
489 
490  speed = -1;
491 
492  for(i = 0; i < move_down.size; i++)
493  {
494  org = move_down[i + 1];
495 
496  if(isdefined(org))
497  {
498  speed = ‪get_speed(org, speed);
499 
500  // convert speed to a time
501  time = distance(self.origin, org.origin) / speed;
502  self moveto(org.origin, time);
503  wait time;
504  }
505  }
506 
507  // play any metal screeching / groaning sounds if assigned
508  if(isdefined(self.script_sound))
509  {
510  self playSound(level.scr_sound[self.script_sound]);
511  }
512 
513  level notify("elevator_" + platform_name + "_stop");
514  level notify("stop_" + platform_name + "_movement_sound");
515  level notify("stop_" + platform_name + "_klaxon");
516 
517  if(isdefined(level.scr_sound["elevator_end"]))
518  {
519  self playSound(level.scr_sound["elevator_end"]);
520  }
521 
522  self.at_start = true;
523  }
524  }
525 }
526 
527 // check if a speed is defined on the current path point script_struct
528 function ‪get_speed(path_point, speed)
529 {
530  if(speed <= 0)
531  {
532  speed = 100;
533  }
534 
535  if(isdefined(path_point.speed))
536  {
537  speed = path_point.speed;
538  }
539 
540  return speed;
541 }
‪script_delay
‪function script_delay()
Definition: util_shared.gsc:970
‪elevator_looping_sounds
‪function elevator_looping_sounds(notify_play, notify_stop)
Definition: _elevator.gsc:325
‪get_speed
‪function get_speed(path_point, speed)
Definition: _elevator.gsc:528
‪define_elevator_parts
‪function define_elevator_parts()
Definition: _elevator.gsc:209
‪trigger_think
‪function trigger_think(platform_name)
Definition: _elevator.gsc:302
‪get_array
‪function get_array(kvp_value, kvp_key="targetname")
Definition: struct.csc:34
‪get
‪function get(kvp_value, kvp_key="targetname")
Definition: struct.csc:13
‪__init__
‪function __init__()
Definition: _elevator.gsc:113
‪move_elevator_gates
‪function move_elevator_gates(platform_name, direction)
Definition: _elevator.gsc:352
‪REGISTER_SYSTEM
‪#define REGISTER_SYSTEM(__sys, __func_init_preload, __reqs)
Definition: shared.gsh:204
‪loop_in_space
‪function loop_in_space(alias, origin, ender)
Definition: sound_shared.gsc:223
‪move_platform
‪function move_platform(platform_start, platform_name)
Definition: _elevator.gsc:390
‪setup_elevator_gates
‪function setup_elevator_gates(platform_name)
Definition: _elevator.gsc:336