‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
_dogs.csc
Go to the documentation of this file.
1 #using scripts\codescripts\struct;
2 
3 #using scripts\shared\system_shared;
4 
5 #insert scripts\shared\shared.gsh;
6 
7 #namespace dogs;
8 
9 //REGISTER_SYSTEM( "dogs", &__init__, undefined )
10 
11 function ‪init()
12 {
13  level.movementStateSound = [];
14 
15  level.maxStateSoundDistance = 99999999;
16 
17  level.movementStateSound["normal"] = spawnStruct();
18  level.movementStateSound["normal"].sound = "aml_dog_bark";
19  level.movementStateSound["normal"].waitMax = 4;
20  level.movementStateSound["normal"].waitMin = 1;
21  level.movementStateSound["normal"].enemyrange = level.maxStateSoundDistance; // this has no range
22  level.movementStateSound["normal"].localenemyonly = false;
23 
24  // this is for everyone other then the enemy
25  level.movementStateSound["attack_mid_everyone"] = spawnStruct();
26  level.movementStateSound["attack_mid_everyone"].sound = "aml_dog_bark_mid";
27  level.movementStateSound["attack_mid_everyone"].waitMax = 2;
28  level.movementStateSound["attack_mid_everyone"].waitMin = 0.5;
29  level.movementStateSound["attack_mid_everyone"].enemyrange = 1500;
30  level.movementStateSound["attack_mid_everyone"].localenemyonly = false;
31 
32  // this is only for the enemy to hear
33  level.movementStateSound["attack_mid_enemy"] = spawnStruct();
34  level.movementStateSound["attack_mid_enemy"].sound = "aml_dog_bark_mid";
35  level.movementStateSound["attack_mid_enemy"].waitMax = 0.5;
36  level.movementStateSound["attack_mid_enemy"].waitMin = 0.01;
37  level.movementStateSound["attack_mid_enemy"].enemyrange = 1500;
38  level.movementStateSound["attack_mid_enemy"].localenemyonly = true;
39 
40  // this is only for the enemy to hear
41  level.movementStateSound["attack_close_enemy"] = spawnStruct();
42  level.movementStateSound["attack_close_enemy"].sound = "aml_dog_bark_close";
43  level.movementStateSound["attack_close_enemy"].waitMax = 0.1;
44  level.movementStateSound["attack_close_enemy"].waitMin = 0.01;
45  level.movementStateSound["attack_close_enemy"].enemyrange = 1000;
46  level.movementStateSound["attack_close_enemy"].localenemyonly = true;
47 }
48 
49 function ‪spawned( localClientNum )
50 {
51  self endon( "entityshutdown" );
52 
53  self thread ‪animCategoryWatcher( localClientNum );
54  self thread ‪enemyWatcher( localClientNum );
55 }
56 
57 function ‪animCategoryChanged( localClientNum, animCategory )
58 {
59  self.animCategory = animCategory;
60  self notify("killanimscripts");
61 
62  ‪dog_print( "anim category changed " + animCategory);
63 
64  switch (animCategory )
65  {
66  case "move":
67  self thread ‪playMovementSounds( localClientNum );
68  break;
69  case "pain":
70  self thread ‪playPainSounds( localClientNum );
71  break;
72  case "death":
73  self thread ‪playDeathSounds( localClientNum );
74  break;
75  };
76 
77 
78 }
79 
80 function ‪animCategoryWatcher( localClientNum )
81 {
82  self endon("entityshutdown");
83 
84  if ( !isdefined(self.animCategory) )
85  {
86  ‪animCategoryChanged( localClientNum, self GetAnimStateCategory() );
87  }
88 
89  while(1)
90  {
91  animCategory = self GetAnimStateCategory();
92 
93  if ( isdefined( animCategory) && self.animCategory != animCategory && animCategory != "traverse" )
94  {
95  ‪animCategoryChanged( localClientNum, animCategory );
96  }
97  wait(0.05);
98  }
99 }
100 
101 function ‪enemyWatcher(localClientNum)
102 {
103  self endon("entityshutdown");
104 
105  while(1)
106  {
107  self waittill("enemy");
108  }
109 }
110 
111 function ‪isLocalPlayerEnemy( enemy )
112 {
113  if ( !isdefined(enemy) )
114  {
115  return false;
116  }
117 
118  players = level.localPlayers;
119 
120  if ( isdefined( players ) )
121  {
122  for ( i = 0; i < players.size; i++ )
123  {
124  if ( players[i] == enemy )
125  return true;
126  }
127  }
128  return false;
129 }
130 
131 function ‪hasEnemyChanged( last_enemy )
132 {
133  if ( !isdefined(last_enemy) && isdefined(self.enemy) )
134  return true;
135 
136  if ( isdefined(last_enemy) && !isdefined(self.enemy) )
137  return true;
138 
139  if ( last_enemy != self.enemy )
140  return true;
141 
142  return false;
143 }
144 
146 {
147  localPlayer = ‪isLocalPlayerEnemy( self.enemy );
148  closest_dist = level.maxStateSoundDistance * level.maxStateSoundDistance;
149  closest_key = "normal";
150  has_enemy = isdefined(self.enemy);
151  if ( has_enemy )
152  {
153  enemy_distance = distancesquared( self.origin, self.enemy.origin );
154  }
155  else
156  {
157  return "normal";
158  }
159 
160  stateArray = getArrayKeys( level.movementStateSound );
161  for ( i = 0; i < stateArray.size; i++ )
162  {
163 // dog_sound_print("checking " + stateArray[i]);
164  if ( level.movementStateSound[stateArray[i]].localenemyonly && !localPlayer )
165  continue;
166 
167  state_dist = level.movementStateSound[stateArray[i]].enemyrange;
168  state_dist *= state_dist;
169 
170  if ( state_dist < enemy_distance )
171  continue;
172 
173  if ( state_dist < closest_dist )
174  {
175  closest_dist = state_dist;
176  closest_key = stateArray[i];
177  }
178  }
179 
180 // dog_sound_print("returning " + closest_key);
181  return closest_key;
182 }
183 
184 function ‪playMovementSounds( localClientNum )
185 {
186  self endon( "entityshutdown" );
187  self endon( "killanimscripts" );
188 
189  last_state = "normal";
190  last_time = 0;
191  wait_time = 0;
192  // getting t5 running
193 
194 
195  while (1)
196  {
197  state = ‪getMovementSoundState();
198 // dog_sound_print( "Sound State: " + state);
199 
200  next_sound = false;
201  if ( state != last_state && level.movementStateSound[state].waitMax < wait_time )
202  {
203  ‪dog_sound_print( "New State forcing next sound");
204  next_sound = true;
205  }
206 
207  if ( next_sound || ((last_time + wait_time) < GetRealTime()) )
208  {
209  if (isdefined(self.enemy) )
210  {
211  ‪dog_sound_print( "enemy distance: " + distance( self.origin, self.enemy.origin ));
212  }
213 
214  soundId = self ‪play_dog_sound( localClientNum, level.movementStateSound[state].sound );
215  last_state = state;
216 
217  if ( soundId >= 0 )
218  {
219  while( soundplaying( soundId ) )
220  {
221  wait( 0.05 );
222  }
223 
224  last_time = GetRealTime();
225  wait_time = 1000 * randomfloatrange( level.movementStateSound[state].waitMin, level.movementStateSound[state].waitMax );
226  ‪dog_sound_print( "wait_time: " + wait_time);
227  }
228  else
229  {
230  // could not play for some reason so dont bother trying again real quick
231  wait(0.5);
232  }
233  }
234 
235  wait( 0.05 );
236  }
237 
238 }
239 
240 function ‪playPainSounds( localClientNum )
241 {
242  self endon( "entityshutdown" );
243  self endon( "killanimscripts" );
244 
245  soundId = self ‪play_dog_sound( localClientNum, "aml_dog_pain" );
246 }
247 
248 function ‪playDeathSounds( localClientNum )
249 {
250  self endon( "entityshutdown" );
251  self endon( "killanimscripts" );
252 
253  soundId = self ‪play_dog_sound( localClientNum, "aml_dog_death" );
254 }
255 
256 function ‪playLockOnSounds( localClientNum )
257 {
258  self endon( "entityshutdown" );
259 
260  soundId = self ‪play_dog_sound( localClientNum, "aml_dog_lock" );
261 }
262 
263 function ‪soundNotify(client_num, entity, note )
264 {
265  if ( note == "sound_dogstep_run_default" )
266  {
267  entity playsound( client_num, "fly_dog_step_run_default" );
268  return true;
269  }
270 
271  alias = "aml" + getsubstr( note, 5 );
272  entity ‪play_dog_sound( client_num, alias);
273 }
274 
275 function ‪dog_get_dvar_int( dvar, def )
276 {
277  return int( ‪dog_get_dvar( dvar, def ) );
278 }
279 
280 // dvar set/fetch/check
281 function ‪dog_get_dvar( dvar, def )
282 {
283  if ( GetDvarString( dvar ) != "" )
284  return getdvarfloat( dvar );
285  else
286  {
287  return def;
288  }
289 }
290 
291 function ‪dog_sound_print( message )
292 {
293 }
294 
295 function ‪dog_print( message )
296 {
297 }
298 
299 function ‪play_dog_sound( localClientNum, sound, position )
300 {
301  ‪dog_sound_print( "SOUND " + sound);
302 
303  if ( isdefined( position ) )
304  {
305  return self playsound( localClientNum, sound, position );
306  }
307 
308  return self playsound( localClientNum, sound );
309 }
‪animCategoryChanged
‪function animCategoryChanged(localClientNum, animCategory)
Definition: _dogs.csc:57
‪spawned
‪function spawned(localClientNum)
Definition: _dogs.csc:49
‪playPainSounds
‪function playPainSounds(localClientNum)
Definition: _dogs.csc:240
‪getMovementSoundState
‪function getMovementSoundState()
Definition: _dogs.csc:145
‪dog_print
‪function dog_print(message)
Definition: _dogs.csc:295
‪animCategoryWatcher
‪function animCategoryWatcher(localClientNum)
Definition: _dogs.csc:80
‪soundNotify
‪function soundNotify(client_num, entity, note)
Definition: _dogs.csc:263
‪hasEnemyChanged
‪function hasEnemyChanged(last_enemy)
Definition: _dogs.csc:131
‪dog_get_dvar
‪function dog_get_dvar(dvar, def)
Definition: _dogs.csc:281
‪playLockOnSounds
‪function playLockOnSounds(localClientNum)
Definition: _dogs.csc:256
‪enemyWatcher
‪function enemyWatcher(localClientNum)
Definition: _dogs.csc:101
‪playDeathSounds
‪function playDeathSounds(localClientNum)
Definition: _dogs.csc:248
‪init
‪function init()
Definition: _dogs.csc:11
‪isLocalPlayerEnemy
‪function isLocalPlayerEnemy(enemy)
Definition: _dogs.csc:111
‪play_dog_sound
‪function play_dog_sound(localClientNum, sound, position)
Definition: _dogs.csc:299
‪playMovementSounds
‪function playMovementSounds(localClientNum)
Definition: _dogs.csc:184
‪dog_get_dvar_int
‪function dog_get_dvar_int(dvar, def)
Definition: _dogs.csc:275
‪dog_sound_print
‪function dog_sound_print(message)
Definition: _dogs.csc:291