‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
_teamops.gsc
Go to the documentation of this file.
1 #using scripts\codescripts\struct;
2 #using scripts\shared\system_shared;
3 #using scripts\shared\callbacks_shared;
4 #using scripts\mp\killstreaks\_killstreaks;
5 #using scripts\mp\gametypes\_globallogic_utils;
6 #using scripts\mp\gametypes\_globallogic_audio;
7 #using scripts\shared\util_shared;
8 #using scripts\shared\sound_shared;
9 
10 #insert scripts\shared\shared.gsh;
11 
12 #using scripts\mp\_util;
13 #insert scripts\mp\_teamops.gsh;
14 
15 #namespace teamops;
16 
18 {
19  teamopsInfoTableLoaded = false;
20  teamopsInfoTableID = TableLookupFindCoreAsset( ‪GAMEOPS_EVENT_TABLE_NAME );
21 
22  if ( isdefined( teamopsInfoTableID ) )
23  {
24  teamopsInfoTableLoaded = true;
25  }
26  assert( teamopsInfoTableLoaded, "Team Ops Event Table is not loaded: " + ‪GAMEOPS_EVENT_TABLE_NAME );
27  return teamopsInfoTableID;
28 }
29 
30 function ‪init()
31 {
32  game["teamops"] = SpawnStruct();
33 
34  game["teamops"].data = [];
35  game["teamops"].teamProgress = [];
36  game["teamops"].teamopsName = undefined;
37 
38  foreach( team in level.teams )
39  {
40  game["teamops"].teamProgress[team] = 0;
41  }
42 
43  level.teamopsOnProcessPlayerEvent = &‪teamops::processPlayerEvent;
44 
45  tableID = ‪getTeamopsTableID();
46 
47  assert( isdefined( tableID ) );
48  if( !isdefined( tableID ) )
49  {
50  game["teamops"].teamopsInitialed = false;
51  return;
52  }
53 
54  for( row = 1; row < ‪GAMEOPS_EVENT_MAX_COUNT; row++ )
55  {
56  ‪name = tableLookupColumnForRow( tableID, row, ‪GAMEOPS_NAME );
57  if( ‪name != "" )
58  {
59  game["teamops"].data[‪name] = SpawnStruct();
60  game["teamops"].data[‪name].description = tableLookupColumnForRow( tableID, row, ‪GAMEOPS_DESCRIPTION );
61  game["teamops"].data[‪name].pushevent = tableLookupColumnForRow( tableID, row, ‪GAMEOPS_PUSH_EVENT );
62  game["teamops"].data[‪name].popevent = tableLookupColumnForRow( tableID, row, ‪GAMEOPS_POP_EVENT );
63  game["teamops"].data[‪name].resetevent = tableLookupColumnForRow( tableID, row, ‪GAMEOPS_RESET_EVENT );
64  game["teamops"].data[‪name].count = int( tableLookupColumnForRow( tableID, row, ‪GAMEOPS_COUNT ) );
65  game["teamops"].data[‪name].time = int( tableLookupColumnForRow( tableID, row, ‪GAMEOPS_TIME ) );
66  game["teamops"].data[‪name].modes = StrTok( tableLookupColumnForRow( tableID, row, ‪GAMEOPS_MODE ), "," );
67  game["teamops"].data[‪name].rewards = StrTok( tableLookupColumnForRow( tableID, row, ‪GAMEOPS_REWARD ), "," );
68  }
69  }
70 
71  game["teamops"].teamopsInitialized = true;
72 }
73 
74 function ‪getID( ‪name )
75 {
76  tableID = ‪getTeamopsTableID();
77  for( row = 1; row < ‪GAMEOPS_EVENT_MAX_COUNT; row++ )
78  {
79  _name = tableLookupColumnForRow( tableID, row, ‪GAMEOPS_NAME );
80  if( ‪name == _name )
81  return row;
82  }
83  return 0;
84 }
85 
87 {
88  teamops = game["teamops"].data[‪name];
89 
90  if( teamops.modes.size == 0 )
91  return true;
92 
93  for( mi = 0; mi < teamops.modes.size; mi++ )
94  {
95  if( teamops.modes[mi] == level.gameType )
96  return true;
97  }
98  return false;
99 }
100 
102 {
103  level notify( "teamops_starting" );
104  level.teamopsOnPlayerKilled = undefined;
105  if( !‪teamOpsAllowed( ‪name ) )
106  return;
107 
108  TeamOpsShowHUD( 0 );
109 
110  preAnounceTime = GetDvarInt( "teamOpsPreanounceTime", 5 );
111 
112  foreach( team in level.teams )
113  {
114  ‪globallogic_audio::leader_dialog( "teamops_preannounce", team );
115  }
116 
117  wait ( preAnounceTime );
118 
119  for( i = 0; i < level.players.size; i++ )
120  {
121  player = level.players[i];
122  if( isdefined( player ) )
123  player playlocalsound( "uin_objective_updated" );
124  }
125 
126  teamops = game["teamops"].data[‪name];
127 
128  game["teamops"].teamopsName = ‪name;
129  game["teamops"].teamOpsID = ‪getID( ‪name );
130  game["teamops"].teamopsRewardIndex = RandomIntRange( 0, teamops.rewards.size );
131  game["teamops"].teamopsReward = teamops.rewards[game["teamops"].teamopsRewardIndex];
132  game["teamops"].teamopsStartTime = GetTime();
133 
134  foreach( team in level.teams )
135  {
136  game["teamops"].teamProgress[team] = 0;
137  }
138 
139  wait 0.1;
140 
141  TeamOpsStart( game["teamops"].teamOpsID, game["teamops"].teamopsRewardIndex, game["teamops"].teamopsStartTime, teamops.time );
142 
143  wait 0.1;
144 
145  TeamOpsShowHUD( 1 );
146  TeamOpsUpdateProgress( "axis", 0 );
147  TeamOpsUpdateProgress( "allies", 0 );
148 
149  level thread ‪teamOpsWatcher();
150 }
151 
153 {
154  while( isdefined( game["teamops"].teamopsName ) )
155  {
156  time = game["teamops"].data[game["teamops"].teamopsName].time;
157  if( isdefined( time ) && ( time > 0 ) )
158  {
159  elapsed = GetTime() - game["teamops"].teamopsStartTime;
160  if( elapsed > time * 1000 )
161  {
162  ‪stopTeamops();
163  foreach( team in level.teams )
164  {
165  ‪globallogic_audio::leader_dialog( "teamops_timeout", team );
166  }
167  }
168  }
169  wait 0.5;
170  }
171 }
172 
173 function ‪stopTeamops()
174 {
175  TeamOpsShowHUD( 0 );
176  game["teamops"].teamopsName = undefined;
177  game["teamops"].teamopsReward = undefined;
178  game["teamops"].teamopsStartTime = undefined;
179 
180  foreach( team in level.teams )
181  {
182  game["teamops"].teamProgress[team] = 0;
183  }
184 }
185 
186 function ‪processPlayerEvent( event, player )
187 {
188  teamopsName = game["teamops"].teamopsName;
189 
190  if( isplayer( player ) && isdefined( teamopsName ) )
191  {
192  level ‪processTeamEvent( event, player, player.team );
193  }
194 }
195 
196 function ‪processTeamEvent( event, player, team )
197 {
198  teamopsName = game["teamops"].teamopsName;
199  teamops = game["teamops"].data[teamopsName];
200 
201  if( isdefined( teamops.pushevent ) && ( event == teamops.pushevent ) )
202  {
203  game["teamops"].teamProgress[team] += 1;
204  level ‪updateTeamOps( event, player, team );
205  }
206 
207  if( isdefined( teamops.popevent ) && ( event == teamops.popevent ) )
208  {
209  game["teamops"].teamProgress[team] -= 1;
210  if( game["teamops"].teamProgress[team] < 0 )
211  game["teamops"].teamProgress[team]= 0;
212  level ‪updateTeamOps( event, player, team );
213  }
214 
215  if( isdefined( teamops.resetevent ) && ( event == teamops.resetevent ) )
216  {
217  game["teamops"].teamProgress[team] = 0;
218  level ‪updateTeamOps( event, player, team );
219  }
220 
221 }
222 
223 function ‪updateTeamOps( event, player, team )
224 {
225  teamopsName = game["teamops"].teamopsName;
226  teamops = game["teamops"].data[teamopsName];
227 
228  count_target = teamops.count;
229  progress = int( ( 100 * game["teamops"].teamProgress[team] ) / count_target );
230 
231  TeamOpsUpdateProgress( team, progress );
232 
233  if( game["teamops"].teamProgress[team] >= teamops.count )
234  {
235  if( isdefined( player ) )
236  {
237  level thread ‪teamOpsAcheived( player, team );
238  }
239  }
240 }
241 
242 function ‪teamOpsAcheived( player, team )
243 {
244  game["teamops"].teamopsName = undefined;
245  wait 0.5;
246  TeamOpsShowHUD( 0 );
247 
248  wait 2;
249  ‪globallogic_audio::leader_dialog( "teamops_win", team );
251 
252  player ‪killstreaks::give( game["teamops"].teamopsReward, 1 );
253  wait 2;
254  player ‪killstreaks::useKillstreak( game["teamops"].teamopsReward, 1 );
255 }
256 
257 function ‪main()
258 {
259  thread ‪watchTeamOpsTime();
260  level.teamopsTargetKills = GetDvarInt( "teamOpsKillsCountTrigger_" + level.gameType, 37 );
261  if ( level.teamopsTargetKills > 0 )
262  {
263  level.teamopsOnPlayerKilled = &‪teamops::onPlayerKilled;
264  }
265 }
266 
268 {
269  operations = StrTok( GetDvarString( "teamOpsName" ), "," );
270 
271  // try to pickup a random one
272  for( i = 0; i < 20; i++ )
273  {
274  operation = operations[RandomIntRange( 0, operations.size )];
275  if( ‪teamOpsAllowed( operation ) )
276  return operation;
277  }
278 
279  // check if we have any compatible operation
280  for( i = 0; i < operations.size; i++ )
281  {
282  operation = operations[i];
283  if( ‪teamOpsAllowed( operation ) )
284  return operation;
285  }
286 
287  return undefined;
288 }
289 
291 {
292  level endon( "teamops_starting" );
293 
294  if ( ‪IS_TRUE( level.inPrematchPeriod ) )
295  level waittill("prematch_over");
296 
297  activeTeamOps = ‪GetCompatibleOperation();
298  if( !isdefined( activeTeamOps ) )
299  return;
300 
301  startDelay = GetDvarInt( "teamOpsStartDelay_" + level.gameType, 300 );
302 
303  while( 1 )
304  {
305  if( isdefined( game["teamops"].teamopsName ) )
306  {
307  if ( GetDvarInt( "scr_stop_teamops" ) == 1 )
308  {
310  SetDvar( "scr_stop_teamops", 0 );
311  }
312  }
313 
314  timePassed = ‪globallogic_utils::getTimePassed() / 1000;
315 
316  startTeamOps = 0;
317  if( timePassed > startDelay )
318  {
319  level thread ‪startTeamops( activeTeamOps );
320  break;
321  }
322 
323  wait 1;
324  }
325 }
326 
327 
328 function ‪onPlayerKilled( eInflictor, attacker, iDamage, sMeansOfDeath, weapon, vDir, sHitLoc, psOffsetTime, deathAnimDuration )
329 {
330  level endon( "teamops_starting" );
331 
332  if ( isPlayer( attacker ) == false || attacker.team == self.team )
333  return;
334 
335  if ( !isdefined( level.teamopsKillTracker ) )
336  {
337  level.teamopsKillTracker = [];
338  }
339 
340  if ( !isdefined( level.teamopsKillTracker[attacker.team] ) )
341  {
342  level.teamopsKillTracker[attacker.team] = 0;
343  }
344 
345  level.teamopsKillTracker[attacker.team]++;
346 
347  if ( level.teamopsKillTracker[attacker.team] >= level.teamopsTargetKills )
348  {
349  activeTeamOps = ‪GetCompatibleOperation();
350  if( !isdefined( activeTeamOps ) )
351  return;
352 
353  level thread ‪startTeamops( activeTeamOps );
354  }
355 }
‪GAMEOPS_EVENT_MAX_COUNT
‪#define GAMEOPS_EVENT_MAX_COUNT
Definition: _teamops.gsh:13
‪leader_dialog_for_other_teams
‪function leader_dialog_for_other_teams(dialogKey, skipTeam, objectiveKey, killstreakId, dialogBufferKey)
Definition: _globallogic_audio.gsc:422
‪processPlayerEvent
‪function processPlayerEvent(event, player)
Definition: _teamops.gsc:186
‪teamOpsWatcher
‪function teamOpsWatcher()
Definition: _teamops.gsc:152
‪GAMEOPS_RESET_EVENT
‪#define GAMEOPS_RESET_EVENT
Definition: _teamops.gsh:7
‪startTeamops
‪function startTeamops(name)
Definition: _teamops.gsc:101
‪getTeamopsTableID
‪function getTeamopsTableID()
Definition: _teamops.gsc:17
‪GAMEOPS_TIME
‪#define GAMEOPS_TIME
Definition: _teamops.gsh:9
‪GAMEOPS_COUNT
‪#define GAMEOPS_COUNT
Definition: _teamops.gsh:8
‪stopTeamops
‪function stopTeamops()
Definition: _teamops.gsc:173
‪IS_TRUE
‪#define IS_TRUE(__a)
Definition: shared.gsh:251
‪useKillstreak
‪function useKillstreak(killstreak, isFromInventory)
Definition: _killstreaks.gsc:1209
‪GAMEOPS_REWARD
‪#define GAMEOPS_REWARD
Definition: _teamops.gsh:11
‪getTimePassed
‪function getTimePassed()
Definition: _globallogic_utils.gsc:274
‪watchTeamOpsTime
‪function watchTeamOpsTime()
Definition: _teamops.gsc:290
‪GetCompatibleOperation
‪function GetCompatibleOperation()
Definition: _teamops.gsc:267
‪GAMEOPS_DESCRIPTION
‪#define GAMEOPS_DESCRIPTION
Definition: _teamops.gsh:4
‪GAMEOPS_PUSH_EVENT
‪#define GAMEOPS_PUSH_EVENT
Definition: _teamops.gsh:5
‪GAMEOPS_EVENT_TABLE_NAME
‪#define GAMEOPS_EVENT_TABLE_NAME
Definition: _teamops.gsh:1
‪getID
‪function getID(name)
Definition: _teamops.gsc:74
‪GAMEOPS_MODE
‪#define GAMEOPS_MODE
Definition: _teamops.gsh:10
‪main
‪function main()
Definition: _teamops.gsc:257
‪leader_dialog
‪function leader_dialog(dialogKey, team, excludeList, objectiveKey, killstreakId, dialogBufferKey)
Definition: _globallogic_audio.gsc:435
‪processTeamEvent
‪function processTeamEvent(event, player, team)
Definition: _teamops.gsc:196
‪GAMEOPS_POP_EVENT
‪#define GAMEOPS_POP_EVENT
Definition: _teamops.gsh:6
‪give
‪function give(killstreakType, streak, suppressNotification, noXP, toBottom)
Definition: _killstreaks.gsc:539
‪onPlayerKilled
‪function onPlayerKilled(eInflictor, attacker, iDamage, sMeansOfDeath, weapon, vDir, sHitLoc, psOffsetTime, deathAnimDuration)
Definition: _teamops.gsc:328
‪GAMEOPS_NAME
‪#define GAMEOPS_NAME
Definition: _teamops.gsh:3
‪updateTeamOps
‪function updateTeamOps(event, player, team)
Definition: _teamops.gsc:223
‪teamOpsAllowed
‪function teamOpsAllowed(name)
Definition: _teamops.gsc:86
‪name
‪class GroundFx name
‪teamOpsAcheived
‪function teamOpsAcheived(player, team)
Definition: _teamops.gsc:242
‪init
‪function init()
Definition: _teamops.gsc:30