‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
_gameadvertisement.gsc
Go to the documentation of this file.
1 #using scripts\codescripts\struct;
2 
3 #using scripts\shared\util_shared;
4 
5 #insert scripts\shared\shared.gsh;
6 
7 #using scripts\mp\gametypes\_dev;
8 #using scripts\mp\gametypes\_globallogic_utils;
9 
10 #using scripts\mp\_util;
11 
12 #namespace gameadvertisement;
13 
14 function ‪init()
15 {
16  level.gameAdvertisementRuleScorePercent = GetGametypeSetting( "gameAdvertisementRuleScorePercent" );
17  level.gameAdvertisementRuleTimeLeft = ( 1000 * 60 ) * GetGametypeSetting( "gameAdvertisementRuleTimeLeft" );
18  level.gameAdvertisementRuleRound = GetGametypeSetting( "gameAdvertisementRuleRound" );
19  level.gameAdvertisementRuleRoundsWon = GetGametypeSetting( "gameAdvertisementRuleRoundsWon" );
20 
22 }
23 
24 
25 function ‪setAdvertisedStatus( onOff )
26 {
27  changeAdvertisedStatus( onOff );
28 }
29 
31 {
32  if( SessionModeIsPrivate() )
33  return;
34 
35  runRules = ‪getGameTypeRules();
36 
37  if( !isdefined( runRules ) )
38  return;
39 
40  level endon( "game_end" );
41 
42  level waittill( "prematch_over" );
43 
44  currentAdvertisedStatus = undefined;
45  while( true )
46  {
47  sessionAdvertCheckwait = GetDvarInt( "sessionAdvertCheckwait", 1 );
48 
49  wait( sessionAdvertCheckwait );
50 
51  advertise = [[runRules]]();
52  if ( !isdefined( currentAdvertisedStatus ) || ( isdefined( advertise ) && ( currentAdvertisedStatus != advertise ) ) )
53  {
54  ‪setAdvertisedStatus( advertise );
55  }
56  currentAdvertisedStatus = advertise;
57  }
58 }
59 
61 {
62  gametype = level.gametype;
63 
64  switch( gametype )
65  {
66  case "gun":
67  return &‪gun_rules;
68  default:
69  return &‪default_rules;
70  }
71 
72  return;
73 }
74 
75 function ‪teamScoreLimitCheck( ruleScorePercent )
76 {
77  scoreLimit = 0;
78 
79  //====================================================================
80  // score check
81 
82  if ( level.roundScoreLimit )
83  {
85  }
86  else if ( level.scoreLimit )
87  {
88  scoreLimit = level.scoreLimit;
89  }
90 
91  if ( scoreLimit )
92  {
93  minScorePercentageLeft = 100;
94 
95  foreach ( team in level.teams )
96  {
97  scorePercentageLeft = 100 - ( ( game[ "teamScores" ][ team ] / scoreLimit ) * 100 );
98 
99  if( minScorePercentageLeft > scorePercentageLeft )
100  minScorePercentageLeft = scorePercentageLeft;
101 
102  if( ruleScorePercent >= scorePercentageLeft )
103  {
104  return false;
105  }
106  }
107  }
108 
109 
110  return true;
111 }
112 
113 function ‪timeLimitCheck( ruleTimeLeft )
114 {
115  maxTime = level.timeLimit;
116 
117  if( maxTime != 0 )
118  {
120 
121  if( ruleTimeLeft >= timeLeft )
122  {
123  return false;
124  }
125  }
126 
127  return true;
128 }
129 
130 //========================================================================================================================================
131 //========================================================================================================================================
132 //========================================================================================================================================
133 
135 {
136 
137  //====================================================================
138 
139  currentRound = game[ "roundsplayed" ] + 1;
140 
141  //====================================================================
142  // score check
143 
144  if( level.gameAdvertisementRuleScorePercent )
145  {
146  if ( level.teambased )
147  {
148  if ( (currentRound >= (level.gameAdvertisementRuleRound - 1)) )
149  {
150  if ( ‪teamScoreLimitCheck( level.gameAdvertisementRuleScorePercent ) == false )
151  return false;
152  }
153  }
154  else
155  {
156  if ( level.scoreLimit )
157  {
158  highestScore = 0;
159  players = GetPlayers();
160 
161  for( i = 0; i < players.size; i++)
162  {
163  if( players[i].pointstowin > highestScore )
164  highestScore = players[i].pointstowin;
165  }
166 
167  scorePercentageLeft = 100 - ( ( highestScore / level.scoreLimit ) * 100 );
168 
169  if( level.gameAdvertisementRuleScorePercent >= scorePercentageLeft )
170  {
171  return false;
172  }
173  }
174  }
175  }
176 
177  //====================================================================
178  // time left check
179 
180  if( level.gameAdvertisementRuleTimeLeft && (currentRound >= (level.gameAdvertisementRuleRound - 1)) )
181  {
182  if ( ‪timeLimitCheck( level.gameAdvertisementRuleTimeLeft ) == false )
183  return false;
184  }
185 
186  //====================================================================
187  // round check
188 
189  if( level.gameAdvertisementRuleRound )
190  {
191  if ( level.gameAdvertisementRuleRound <= currentRound )
192  return false;
193  }
194 
195  //====================================================================
196  // round won check
197 
198  if ( level.gameAdvertisementRuleRoundsWon )
199  {
200  maxRoundsWon = 0;
201  foreach ( team in level.teams )
202  {
203  roundsWon = game[ "teamScores" ][ team ];
204 
205  if( maxRoundsWon < roundsWon )
206  maxRoundsWon = roundsWon;
207 
208  if( level.gameAdvertisementRuleRoundsWon <= roundsWon )
209  {
210  return false;
211  }
212  }
213  }
214 
215  return true;
216 }
217 
218 function ‪gun_rules()
219 {
220  // Any player is within 3 weapons from winning
221 
222  //====================================================================
223 
224  ruleWeaponsLeft = 3; // within 3 weapons of winning
225 
226  //====================================================================
227 
228  //====================================================================
229  // weapons check
230  minWeaponsLeft = level.gunProgression.size;
231 
232  foreach ( player in level.activePlayers )
233  {
234  if ( !isdefined( player ) )
235  continue;
236 
237  if ( !isdefined( player.gunProgress ) )
238  continue;
239 
240  weaponsLeft = level.gunProgression.size - player.gunProgress;
241 
242  if( minWeaponsLeft > weaponsLeft )
243  minWeaponsLeft = weaponsLeft;
244 
245  if( ruleWeaponsLeft >= minWeaponsLeft )
246  {
247  return false;
248  }
249  }
250  return true;
251 }
252 
253 //========================================================================================================================================
254 //========================================================================================================================================
255 //========================================================================================================================================
256 
‪gun_rules
‪function gun_rules()
Definition: _gameadvertisement.gsc:218
‪teamScoreLimitCheck
‪function teamScoreLimitCheck(ruleScorePercent)
Definition: _gameadvertisement.gsc:75
‪getGameTypeRules
‪function getGameTypeRules()
Definition: _gameadvertisement.gsc:60
‪timeLimitCheck
‪function timeLimitCheck(ruleTimeLeft)
Definition: _gameadvertisement.gsc:113
‪getTimeRemaining
‪function getTimeRemaining()
Definition: _globallogic_utils.gsc:109
‪get_current_round_score_limit
‪function get_current_round_score_limit()
Definition: util_shared.gsc:3675
‪init
‪function init()
Definition: _gameadvertisement.gsc:14
‪sessionAdvertisementCheck
‪function sessionAdvertisementCheck()
Definition: _gameadvertisement.gsc:30
‪default_rules
‪function default_rules()
Definition: _gameadvertisement.gsc:134
‪setAdvertisedStatus
‪function setAdvertisedStatus(onOff)
Definition: _gameadvertisement.gsc:25