‪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 {
15 }
16 
17 function ‪main()
18 {
19  foreach( team in level.teams )
20  {
21  level.spectateOverride[team] = spawnstruct();
22  }
23 
25 }
26 
28 {
32 }
33 
35 {
36  self endon("disconnect");
37 
39 }
40 
42 {
43  self endon("disconnect");
44 
46 }
47 
49 {
50  self endon("disconnect");
51 
53 }
54 
56 {
57  level endon ( "game_ended" );
58 
59  for ( index = 0; index < level.players.size; index++ )
60  level.players[index] ‪setSpectatePermissions();
61 }
62 
63 
65 {
66  for ( index = 0; index < level.players.size; index++ )
67  {
68  if ( !isdefined(level.players[index]) )
69  continue;
70 
71  if ( level.players[index] == self )
72  continue;
73 
74  if ( !(self IsPlayerOnSameMachine( level.players[index] )) )
75  continue;
76 
77  team = level.players[index].sessionteam;
78 
79  // going to assume first non-spectator
80  if ( team != "spectator" )
81  return team;
82  }
83 
84  return self.sessionteam;
85 }
86 
88 {
89  for ( index = 0 ; index < level.players.size ; index++ )
90  {
91  if ( !isdefined( level.players[index] ) )
92  continue;
93 
94  if ( level.players[index] == self )
95  continue;
96 
97  if ( !( self IsPlayerOnSameMachine( level.players[index] ) ) )
98  continue;
99 
100  if ( IsAlive( level.players[index] ) )
101  return true;
102  }
103 
104  return false;
105 }
106 
107 function ‪allowSpectateAllTeams( allow )
108 {
109  foreach( team in level.teams )
110  {
111  self allowSpectateTeam( team, allow );
112  }
113 }
114 
115 function ‪allowSpectateAllTeamsExceptTeam( skip_team, allow )
116 {
117  foreach( team in level.teams )
118  {
119  if ( team == skip_team )
120  continue;
121  self allowSpectateTeam( team, allow );
122  }
123 }
124 
126 {
127  team = self.sessionteam;
128 
129  if ( team == "spectator" )
130  {
131  // in online splitscreen we are only going to allow spectators to
132  // spectate the team of the other player on splitscreen
133  if ( self IsSplitScreen() && !level.splitscreen )
134  {
135  team = ‪getSplitscreenTeam();
136  }
137 
138  if ( team == "spectator" )
139  {
140  self ‪allowSpectateAllTeams( true );
141  self allowSpectateTeam( "freelook", false );
142  self allowSpectateTeam( "none", true );
143  self allowSpectateTeam( "localplayers", true );
144  return;
145  }
146  }
147 
148  spectateType = level.spectateType;
149 
150  switch( spectateType )
151  {
152  case 0: // disabled
153  self ‪allowSpectateAllTeams( false );
154  self allowSpectateTeam( "freelook", false );
155  self allowSpectateTeam( "none", true );
156  self allowSpectateTeam( "localplayers", false );
157  break;
158  case 3: // team only - strict splitscreen
159  // player can only spectate other local players
160  if ( self IsSplitScreen() && self ‪OtherLocalPlayerStillAlive() )
161  {
162  self ‪allowSpectateAllTeams( false );
163  self allowSpectateTeam( "none", false );
164  self allowSpectateTeam( "freelook", false );
165  self allowSpectateTeam( "localplayers", true );
166  break;
167  }
168  // fall through
169  case 1: // team only
170  if ( !level.teamBased )
171  {
172  self ‪allowSpectateAllTeams( true );
173  self allowSpectateTeam( "none", true );
174  self allowSpectateTeam( "freelook", false );
175  self allowSpectateTeam( "localplayers", true );
176  }
177  else if ( isdefined( team ) && isdefined( level.teams[team] ) )
178  {
179  self allowSpectateTeam( team, true );
180  self ‪allowSpectateAllTeamsExceptTeam( team , false );
181  self allowSpectateTeam( "freelook", false );
182  self allowSpectateTeam( "none", false );
183  self allowSpectateTeam( "localplayers", true );
184  }
185  else
186  {
187  self ‪allowSpectateAllTeams( false );
188  self allowSpectateTeam( "freelook", false );
189  self allowSpectateTeam( "none", false );
190  self allowSpectateTeam( "localplayers", true );
191  }
192  break;
193  case 2: // free
194  self ‪allowSpectateAllTeams( true );
195  self allowSpectateTeam( "freelook", true );
196  self allowSpectateTeam( "none", true );
197  self allowSpectateTeam( "localplayers", true );
198  break;
199  }
200 
201  if ( isdefined( team ) && isdefined( level.teams[team] ) )
202  {
203  if ( isdefined(level.spectateOverride[team].allowFreeSpectate) )
204  self allowSpectateTeam( "freelook", true );
205 
206  if (isdefined(level.spectateOverride[team].allowEnemySpectate))
207  self ‪allowSpectateAllTeamsExceptTeam( team, true );
208  }
209 }
210 
212 {
213 // error
214 
216 
217  if ( !self IsSplitScreen() )
218  return;
219 
220  for ( index = 0; index < level.players.size; index++ )
221  {
222  if ( !isdefined(level.players[index]) )
223  continue;
224 
225  if ( level.players[index] == self )
226  continue;
227 
228  if ( !(self IsPlayerOnSameMachine( level.players[index] )) )
229  continue;
230 
231  level.players[index] ‪setSpectatePermissions();
232  }
233 }
‪main
‪function main()
Definition: _spectating.gsc:17
‪OtherLocalPlayerStillAlive
‪function OtherLocalPlayerStillAlive()
Definition: _spectating.gsc:87
‪setSpectatePermissions
‪function setSpectatePermissions()
Definition: _spectating.gsc:125
‪allowSpectateAllTeamsExceptTeam
‪function allowSpectateAllTeamsExceptTeam(skip_team, allow)
Definition: _spectating.gsc:115
‪allowSpectateAllTeams
‪function allowSpectateAllTeams(allow)
Definition: _spectating.gsc:107
‪on_start_gametype
‪function on_start_gametype(func, obj)
Definition: callbacks_shared.csc:285
‪getSplitscreenTeam
‪function getSplitscreenTeam()
Definition: _spectating.gsc:64
‪setSpectatePermissionsForMachine
‪function setSpectatePermissionsForMachine()
Definition: _spectating.gsc:211
‪on_player_spawned
‪function on_player_spawned()
Definition: _spectating.gsc:34
‪on_spawned
‪function on_spawned(func, obj)
Definition: callbacks_shared.csc:245
‪updateSpectateSettings
‪function updateSpectateSettings()
Definition: _spectating.gsc:55
‪on_joined_team
‪function on_joined_team()
Definition: _spectating.gsc:41
‪__init__
‪function __init__()
Definition: _spectating.gsc:12
‪REGISTER_SYSTEM
‪#define REGISTER_SYSTEM(__sys, __func_init_preload, __reqs)
Definition: shared.gsh:204
‪on_joined_spectate
‪function on_joined_spectate()
Definition: _spectating.gsc:48
‪on_connecting
‪function on_connecting(func, obj)
Definition: callbacks_shared.gsc:146
‪on_player_connecting
‪function on_player_connecting()
Definition: _spectating.gsc:27