‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
_spectating.gsc
Go to the documentation of this file.
1 #using scripts\codescripts\struct;
2 
3 #using scripts\shared\callbacks_shared;
4 #using scripts\shared\system_shared;
5 
6 #insert scripts\shared\shared.gsh;
7 
8 #namespace spectating;
9 
10 ‪REGISTER_SYSTEM( "spectating", &‪__init__, undefined )
11 
12 function ‪__init__()
13 {
18 }
19 
20 function ‪init()
21 {
22  foreach( team in level.teams )
23  {
24  level.spectateOverride[team] = spawnstruct();
25  }
26 }
27 
29 {
30  level endon ( "game_ended" );
31 
32  for ( index = 0; index < level.players.size; index++ )
33  level.players[index] ‪set_permissions();
34 }
35 
36 
38 {
39  for ( index = 0; index < level.players.size; index++ )
40  {
41  if ( !isdefined(level.players[index]) )
42  continue;
43 
44  if ( level.players[index] == self )
45  continue;
46 
47  if ( !(self IsPlayerOnSameMachine( level.players[index] )) )
48  continue;
49 
50  team = level.players[index].sessionteam;
51 
52  // going to assume first non-spectator
53  if ( team != "spectator" )
54  return team;
55  }
56 
57  return self.sessionteam;
58 }
59 
61 {
62  for ( index = 0 ; index < level.players.size ; index++ )
63  {
64  if ( !isdefined( level.players[index] ) )
65  continue;
66 
67  if ( level.players[index] == self )
68  continue;
69 
70  if ( !( self IsPlayerOnSameMachine( level.players[index] ) ) )
71  continue;
72 
73  if ( IsAlive( level.players[index] ) )
74  return true;
75  }
76 
77  return false;
78 }
79 
80 function ‪allow_all_teams( allow )
81 {
82  foreach( team in level.teams )
83  {
84  self allowSpectateTeam( team, allow );
85  }
86 }
87 
88 function ‪allow_all_teams_except( skip_team, allow )
89 {
90  foreach( team in level.teams )
91  {
92  if ( team == skip_team )
93  continue;
94  self allowSpectateTeam( team, allow );
95  }
96 }
97 
99 {
100  team = self.sessionteam;
101 
102  if ( team == "spectator" )
103  {
104  // in online splitscreen we are only going to allow spectators to
105  // spectate the team of the other player on splitscreen
106  if ( self IsSplitScreen() && !level.splitscreen )
107  {
108  team = ‪get_splitscreen_team();
109  }
110 
111  if ( team == "spectator" )
112  {
113  self ‪allow_all_teams( true );
114  self allowSpectateTeam( "freelook", false );
115  self allowSpectateTeam( "none", true );
116  self allowSpectateTeam( "localplayers", true );
117  return;
118  }
119  }
120 
121  spectateType = level.spectateType;
122 
123  switch( spectateType )
124  {
125  case 0: // disabled
126  self ‪allow_all_teams( false );
127  self allowSpectateTeam( "freelook", false );
128  self allowSpectateTeam( "none", true );
129  self allowSpectateTeam( "localplayers", false );
130  break;
131  case 3: // team only - strict splitscreen
132  // player can only spectate other local players
133  if ( self IsSplitScreen() && self ‪other_local_player_still_alive() )
134  {
135  self ‪allow_all_teams( false );
136  self allowSpectateTeam( "none", false );
137  self allowSpectateTeam( "freelook", false );
138  self allowSpectateTeam( "localplayers", true );
139  break;
140  }
141  // fall through
142  case 1: // team only
143  if ( !level.teamBased )
144  {
145  self ‪allow_all_teams( true );
146  self allowSpectateTeam( "none", true );
147  self allowSpectateTeam( "freelook", false );
148  self allowSpectateTeam( "localplayers", true );
149  }
150  else if ( isdefined( team ) && isdefined( level.teams[team] ) )
151  {
152  self allowSpectateTeam( team, true );
153  self ‪allow_all_teams_except( team , false );
154  self allowSpectateTeam( "freelook", false );
155  self allowSpectateTeam( "none", false );
156  self allowSpectateTeam( "localplayers", true );
157  }
158  else
159  {
160  self ‪allow_all_teams( false );
161  self allowSpectateTeam( "freelook", false );
162  self allowSpectateTeam( "none", false );
163  self allowSpectateTeam( "localplayers", true );
164  }
165  break;
166  case 2: // free
167  self ‪allow_all_teams( true );
168  self allowSpectateTeam( "freelook", true );
169  self allowSpectateTeam( "none", true );
170  self allowSpectateTeam( "localplayers", true );
171  break;
172  }
173 
174  if ( isdefined( team ) && isdefined( level.teams[team] ) )
175  {
176  if ( isdefined(level.spectateOverride[team].allowFreeSpectate) )
177  self allowSpectateTeam( "freelook", true );
178 
179  if (isdefined(level.spectateOverride[team].allowEnemySpectate))
180  self ‪allow_all_teams_except( team, true );
181  }
182 }
183 
185 {
186 // error
187 
188  self ‪set_permissions();
189 
190  if ( !self IsSplitScreen() )
191  return;
192 
193  for ( index = 0; index < level.players.size; index++ )
194  {
195  if ( !isdefined(level.players[index]) )
196  continue;
197 
198  if ( level.players[index] == self )
199  continue;
200 
201  if ( !(self IsPlayerOnSameMachine( level.players[index] )) )
202  continue;
203 
204  level.players[index] ‪set_permissions();
205  }
206 }
‪update_settings
‪function update_settings()
Definition: _spectating.gsc:28
‪set_permissions
‪function set_permissions()
Definition: _spectating.gsc:98
‪init
‪function init()
Definition: _spectating.gsc:20
‪on_start_gametype
‪function on_start_gametype(func, obj)
Definition: callbacks_shared.csc:285
‪set_permissions_for_machine
‪function set_permissions_for_machine()
Definition: _spectating.gsc:184
‪on_spawned
‪function on_spawned(func, obj)
Definition: callbacks_shared.csc:245
‪on_joined_team
‪function on_joined_team()
Definition: _spectating.gsc:41
‪other_local_player_still_alive
‪function other_local_player_still_alive()
Definition: _spectating.gsc:60
‪__init__
‪function __init__()
Definition: _spectating.gsc:12
‪allow_all_teams
‪function allow_all_teams(allow)
Definition: _spectating.gsc:80
‪REGISTER_SYSTEM
‪#define REGISTER_SYSTEM(__sys, __func_init_preload, __reqs)
Definition: shared.gsh:204
‪get_splitscreen_team
‪function get_splitscreen_team()
Definition: _spectating.gsc:37
‪allow_all_teams_except
‪function allow_all_teams_except(skip_team, allow)
Definition: _spectating.gsc:88
‪on_joined_spectate
‪function on_joined_spectate()
Definition: _spectating.gsc:48