‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
rank_shared.gsc
Go to the documentation of this file.
1 #using scripts\codescripts\struct;
2 
3 #using scripts\shared\callbacks_shared;
4 #using scripts\shared\hud_shared;
5 #using scripts\shared\scoreevents_shared;
6 #using scripts\shared\system_shared;
7 #using scripts\shared\util_shared;
8 
9 #insert scripts\shared\shared.gsh;
10 
11 #insert scripts\shared\scoreevents_shared.gsh;
12 
13 #precache( "material", "white" );
14 #precache( "string", "MP_PLUS" );
15 
16 #namespace rank;
17 
18 ‪REGISTER_SYSTEM( "rank", &‪__init__, undefined )
19 
20 function ‪__init__()
21 {
23 }
24 
25 function ‪init()
26 {
27  level.scoreInfo = [];
28  level.codPointsXpScale = GetDvarfloat( "scr_codpointsxpscale" );
29  level.codPointsMatchScale = GetDvarfloat( "scr_codpointsmatchscale" );
30  level.codPointsChallengeScale = GetDvarfloat( "scr_codpointsperchallenge" );
31  level.rankXpCap = GetDvarint( "scr_rankXpCap" );
32  level.codPointsCap = GetDvarint( "scr_codPointsCap" );
33  level.usingMomentum = true;
34  level.usingScoreStreaks = GetDvarInt( "scr_scorestreaks" ) != 0;
35  level.scoreStreaksMaxStacking = GetDvarInt( "scr_scorestreaks_maxstacking" );
36  level.maxInventoryScoreStreaks = GetDvarInt( "scr_maxinventory_scorestreaks", 3 );
37  level.usingRampage = !isdefined( level.usingScoreStreaks ) || !level.usingScoreStreaks;
38  level.rampageBonusScale = GetDvarFloat( "scr_rampagebonusscale" );
39 
40  level.rankTable = [];
41 
42  if ( SessionModeIsCampaignGame() )
43  {
44  level.xpScale = GetDvarFloat( "scr_xpscalecp" );
45 
46  level.ranktable_name = "gamedata/tables/cp/cp_ranktable.csv";
47  level.rankicontable_name = "gamedata/tables/cp/cp_rankIconTable.csv";
48  }
49  else if ( SessionModeIsZombiesGame() )
50  {
51  level.xpScale = GetDvarFloat( "scr_xpscalezm" );
52 
53  level.ranktable_name = "gamedata/tables/zm/zm_ranktable.csv";
54  level.rankicontable_name = "gamedata/tables/zm/zm_rankIconTable.csv";
55  }
56  else
57  {
58  level.xpScale = GetDvarFloat( "scr_xpscalemp" );
59 
60  level.ranktable_name = "gamedata/tables/mp/mp_ranktable.csv";
61  level.rankicontable_name = "gamedata/tables/mp/mp_rankIconTable.csv";
62  }
63 
65 
66  level.maxRank = int(tableLookup( level.ranktable_name, 0, "maxrank", 1 ));
67  level.maxRankStarterPack = int(tableLookup( level.ranktable_name, 0, "maxrankstarterpack", 1 ));
68  level.maxPrestige = int(tableLookup( level.rankicontable_name, 0, "maxprestige", 1 ));
69 
70  rankId = 0;
71  rankName = tableLookup( level.ranktable_name, 0, rankId, 1 );
72  assert( isdefined( rankName ) && rankName != "" );
73 
74  while ( isdefined( rankName ) && rankName != "" )
75  {
76  level.rankTable[rankId][1] = tableLookup( level.ranktable_name, 0, rankId, 1 );
77  level.rankTable[rankId][2] = tableLookup( level.ranktable_name, 0, rankId, 2 );
78  level.rankTable[rankId][3] = tableLookup( level.ranktable_name, 0, rankId, 3 );
79  level.rankTable[rankId][7] = tableLookup( level.ranktable_name, 0, rankId, 7 );
80  level.rankTable[rankId][14] = tableLookup( level.ranktable_name, 0, rankId, 14 );
81 
82  if( SessionModeIsCampaignGame() )
83  { //cp has an extra column that awards extra tokens per rank
84  level.rankTable[rankId][18] = tablelookup( level.ranktable_name, 0, rankId, 18 );
85  }
86  rankId++;
87  rankName = tableLookup( level.ranktable_name, 0, rankId, 1 );
88  }
89 
91 }
92 
93 
94 function ‪initScoreInfo()
95 {
96  scoreInfoTableID = ‪scoreevents::getScoreEventTableID();
97 
98  assert( isdefined( scoreInfoTableID ) );
99  if ( !isdefined( scoreInfoTableID ) )
100  {
101  return;
102  }
103 
104  scoreColumn = ‪scoreevents::getScoreEventColumn( level.gameType );
105  xpColumn = ‪scoreevents::getXPEventColumn( level.gameType );
106 
107  assert( scoreColumn >= 0 );
108  if ( scoreColumn < 0 )
109  {
110  return;
111  }
112 
113  assert( xpColumn >= 0 );
114  if ( xpColumn < 0 )
115  {
116  return;
117  }
118 
119 
120  for( row = 1; row < ‪SCORE_EVENT_MAX_COUNT; row++ )
121  {
122  type = tableLookupColumnForRow( scoreInfoTableID, row, ‪SCOREINFOTABLE_SCRIPT_REFERENCE );
123  if ( type != "" )
124  {
125  labelString = tableLookupColumnForRow( scoreInfoTableID, row, ‪SCOREINFOTABLE_SCORE_STRING );
126  label = undefined;
127  if ( labelString != "" )
128  {
129  label = tableLookupIString( scoreInfoTableID, 0, type, ‪SCOREINFOTABLE_SCORE_STRING );
130  }
131 
132  teamScoreString = tableLookupColumnForRow( scoreInfoTableID, row, ‪SCOREINFOTABLE_TEAM_SCORE_MATERIAL );
133  teamscore_material = undefined;
134  if ( teamScorestring != "" )
135  {
136  teamscore_material = tableLookupIString( scoreInfoTableID, 0, type, ‪SCOREINFOTABLE_TEAM_SCORE_MATERIAL );
137  }
138 
139  scoreValue = int( tableLookupColumnForRow( scoreInfoTableID, row, scoreColumn ) );
140  xpValue = int( tableLookupColumnForRow( scoreInfoTableID, row, xpColumn ) );
141  ‪registerScoreInfo( type, scoreValue, xpValue, label, teamscore_material );
142 
143  if ( !isdefined( game["ScoreInfoInitialized"] ) )
144  {
145  xpValue = float( tableLookupColumnForRow( scoreInfoTableID, row, xpColumn ) );
146 
147  setDDLStat = tableLookupColumnForRow( scoreInfoTableID, row, ‪SCOREINFOTABLE_SAVE_MEDAL_STATS );
148  addPlayerStat = false;
149  if ( setDDLStat == "TRUE" )
150  {
151  addPlayerStat = true;
152  }
153  isMedal = false;
154  iString = tableLookupIString( scoreInfoTableID, 0, type, ‪SCOREINFOTABLE_MEDAL_REFERENCE );
155  if ( isdefined( iString ) && iString != &"" )
156  {
157  isMedal = true;
158  }
159 
160  demoBookmarkPriority = int( tableLookupColumnForRow( scoreInfoTableID, row, ‪SCOREINFOTABLE_DEMO_BOOKMARK_PRIORITY ) );
161  if ( !isdefined( demoBookmarkPriority ) )
162  {
163  demoBookmarkPriority = 0;
164  }
165 
166  RegisterXP( type, xpValue, addPlayerStat, isMedal, demoBookmarkPriority, row );
167  }
168 
169  allowKillstreakWeapons = tableLookupColumnForRow( scoreInfoTableID, row, ‪SCOREINFOTABLE_INCLUDE_KILLSTREAKS );
170  if ( allowKillstreakWeapons == "TRUE" )
171  {
172  level.scoreInfo[ type ][ "allowKillstreakWeapons" ] = true;
173  }
174 
175  allowHero = tableLookupColumnForRow( scoreInfoTableID, row, ‪SCOREINFOTABLE_INCLUDE_HERO );
176  if ( allowHero == "TRUE" )
177  {
178  level.scoreInfo[ type ][ "allow_hero" ] = true;
179  }
180 
181  combatEfficiencyEvent = tableLookupColumnForRow( scoreInfoTableID, row, ‪SCOREINFOTABLE_INCLUDE_COMBAT_EFFICIENCY_EVENT );
182  if( IsDefined( combatEfficiencyEvent ) && combatEfficiencyEvent != "" )
183  {
184  level.scoreInfo[ type ][ "combat_efficiency_event" ] = combatEfficiencyEvent;
185  }
186  }
187  }
188 
189  game["ScoreInfoInitialized"] = true;
190 }
191 
192 
193 function ‪getRankXPCapped( inRankXp )
194 {
195  if ( ( isdefined( level.rankXpCap ) ) && level.rankXpCap && ( level.rankXpCap <= inRankXp ) )
196  {
197  return level.rankXpCap;
198  }
199 
200  return inRankXp;
201 }
202 
203 function ‪getCodPointsCapped( inCodPoints )
204 {
205  if ( ( isdefined( level.codPointsCap ) ) && level.codPointsCap && ( level.codPointsCap <= inCodPoints ) )
206  {
207  return level.codPointsCap;
208  }
209 
210  return inCodPoints;
211 }
212 
213 function ‪registerScoreInfo( type, value, xp, label, teamscore_material )
214 {
215  overrideDvar = "scr_" + level.gameType + "_score_" + type;
216  if ( GetDvarString( overrideDvar ) != "" )
217  {
218  value = getDvarInt( overrideDvar );
219  }
220 
221  if( type == "kill" )
222  {
223  multiplier = GetGametypeSetting( "killEventScoreMultiplier" );
224  level.scoreInfo[type]["value"] = value;
225  if ( multiplier > 0 )
226  {
227  level.scoreInfo[type]["value"] = int((multiplier) * value);
228  }
229  }
230  else
231  {
232  level.scoreInfo[type]["value"] = value;
233  }
234 
235  level.scoreInfo[type]["xp"] = xp;
236 
237  if ( isdefined( label ) )
238  {
239  level.scoreInfo[type]["label"] = label;
240  }
241 
242  if ( isdefined( teamscore_material ) )
243  {
244  level.scoreInfo[type]["team_icon"] = teamscore_material;
245  }
246 }
247 
248 function ‪getScoreInfoValue( type )
249 {
250  if ( isdefined( level.scoreInfo[type] ) )
251  {
252  n_score = level.scoreInfo[type]["value"];
253  if ( isdefined( level.scoreModifierCallback ) && isdefined( n_score ) )
254  {
255  n_score = [[level.scoreModifierCallback]](type, n_score);
256  }
257 
258  return n_score;
259  }
260 }
261 
262 function ‪getScoreInfoXP( type )
263 {
264  if ( isdefined( level.scoreInfo[type] ) )
265  {
266  n_xp = level.scoreInfo[type]["xp"];
267  if ( isdefined( level.xpModifierCallback ) && isdefined( n_xp ) )
268  {
269  n_xp = [[level.xpModifierCallback]]( type, n_xp );
270  }
271 
272  return n_xp;
273  }
274 }
275 
277 {
278  if( ‪IS_TRUE(level.disableMomentum) )
279  return true;
280 
281  // If teamscore UI has been overridden, and this has a teamscore icon, don't display it in the momentum indicator.
282  //
283  if (isdefined(level.teamScoreUICallback) && isdefined( level.scoreInfo[type]["team_icon"] ))
284  {
285  return true;
286  }
287 
288  return false;
289 }
290 
291 function ‪getScoreInfoLabel( type )
292 {
293  return ( level.scoreInfo[type]["label"] );
294 }
295 
297 {
298  return ( level.scoreInfo[type]["combat_efficiency_event"] );
299 }
300 
302 {
303  return isdefined( level.scoreInfo[type]["rampage"] ) && level.scoreInfo[type]["rampage"];
304 }
305 
306 function ‪getRankInfoMinXP( rankId )
307 {
308  return int(level.rankTable[rankId][2]);
309 }
310 
311 function ‪getRankInfoXPAmt( rankId )
312 {
313  return int(level.rankTable[rankId][3]);
314 }
315 
316 function ‪getRankInfoMaxXp( rankId )
317 {
318  return int(level.rankTable[rankId][7]);
319 }
320 
321 function ‪getRankInfoFull( rankId )
322 {
323  return tableLookupIString( level.ranktable_name, 0, rankId, 16 );
324 }
325 
326 function ‪getRankInfoIcon( rankId, prestigeId )
327 {
328  return tableLookup( level.rankicontable_name, 0, rankId, prestigeId+1 );
329 }
330 
331 function ‪getRankInfoLevel( rankId )
332 {
333  return int( tableLookup( level.ranktable_name, 0, rankId, 13 ) );
334 }
335 
337 {
338  return int( tableLookup( level.ranktable_name, 0, rankId, 17 ) );
339 }
340 
342 {
343  if ( self IsHost() )
344  {
345  // don't try to kick the host
346  return false;
347  }
348 
349  if (level.rankCap > 0 && self.pers["rank"] > level.rankCap)
350  {
351  return true;
352  }
353 
354  if ( ( level.rankCap > 0 ) && ( level.minPrestige == 0 ) && ( self.pers["plevel"] > 0 ) )
355  {
356  return true;
357  }
358 
359  if ( level.minPrestige > self.pers["plevel"] )
360  {
361  return true;
362  }
363 
364  return false;
365 }
366 
368 {
369  codPoints = self GetDStat( "playerstatslist", "CODPOINTS", "StatValue" );
370  codPointsCapped = ‪getCodPointsCapped( codPoints );
371 
372  if ( codPoints > codPointsCapped )
373  {
374  self ‪setCodPointsStat( codPointsCapped );
375  }
376 
377  return codPointsCapped;
378 }
379 
380 function ‪setCodPointsStat( codPoints )
381 {
382  self SetDStat( "PlayerStatsList", "CODPOINTS", "StatValue", ‪getCodPointsCapped( codPoints ) );
383 }
384 
386 {
387  rankXp = self GetDStat( "playerstatslist", "RANKXP", "StatValue" );
388  rankXpCapped = ‪getRankXPCapped( rankXp );
389 
390  if ( rankXp > rankXpCapped )
391  {
392  self SetDStat( "playerstatslist", "RANKXP", "StatValue", rankXpCapped );
393  }
394 
395  return rankXpCapped;
396 }
397 
399 {
400  arenaSlot = ArenaGetSlot();
401  arenaPoints = self GetDStat( "arenaStats", arenaSlot, "points" );
402 
403  //Increment arena points by 1, because we immediatly deduct a point from the player to prevent
404  //players leaving early without penalty.
405  return arenaPoints + 1;
406 }
407 
409 {
410  self.pers["rankxp"] = self ‪getRankXpStat();
411  self.pers["codpoints"] = self ‪getCodPointsStat();
412  self.pers["currencyspent"] = self GetDStat( "playerstatslist", "currencyspent", "StatValue" );
413  rankId = self ‪getRankForXp( self ‪getRankXP() );
414  self.pers["rank"] = rankId;
415  self.pers["plevel"] = self GetDStat( "playerstatslist", "PLEVEL", "StatValue" );
416 
417  if ( self ‪shouldKickByRank() )
418  {
419  kick( self getEntityNumber() );
420  return;
421  }
422 
423  ‪DEFAULT( self.pers["participation"], 0 );
424 
425  self.rankUpdateTotal = 0;
426 
427  // attempt to move logic out of menus as much as possible
428  self.cur_rankNum = rankId;
429  assert( isdefined(self.cur_rankNum), "rank: "+ rankId + " does not have an index, check " + level.ranktable_name );
430 
431  prestige = self GetDStat( "playerstatslist", "plevel", "StatValue" );
432  self setRank( rankId, prestige );
433  self.pers["prestige"] = prestige;
434 
435  if ( ( SessionModeIsMultiplayerGame() && GameModeIsUsingStats() ) || ( SessionModeIsZombiesGame() && SessionModeIsOnlineGame() ) )
436  {
437  paragonRank = self GetDStat( "playerstatslist", "paragon_rank", "StatValue" );
438  self setParagonRank( paragonRank );
439  self.pers["paragonrank"] = paragonRank;
440 
441  paragonIconId = self GetDStat( "playerstatslist", "paragon_icon_id", "StatValue" );
442  self setParagonIconId( paragonIconId );
443  self.pers["paragoniconid"] = paragonIconId;
444  }
445 
446  if ( !isdefined( self.pers["summary"] ) )
447  {
448  self.pers["summary"] = [];
449  self.pers["summary"]["xp"] = 0;
450  self.pers["summary"]["score"] = 0;
451  self.pers["summary"]["challenge"] = 0;
452  self.pers["summary"]["match"] = 0;
453  self.pers["summary"]["misc"] = 0;
454  self.pers["summary"]["codpoints"] = 0;
455  }
456 
457  if( GameModeIsMode( ‪GAMEMODE_LEAGUE_MATCH ) && !( self ‪util::is_bot() ) )
458  {
459  arenaPoints = self ‪getArenaPointsStat();
460  arenaPoints = int( min( arenaPoints, 100 ) ); // JATODO: 100 = max arena points, temp until TU4
461 
462  self.pers["arenapoints"] = arenaPoints;
463  self setArenaPoints( arenaPoints );
464  }
465 
466  if ( level.rankedMatch )
467  {
468  self SetDStat( "playerstatslist", "rank", "StatValue", rankId );
469  self SetDStat( "playerstatslist", "minxp", "StatValue", getRankInfoMinXp( rankId ) );
470  self SetDStat( "playerstatslist", "maxxp", "StatValue", ‪getRankInfoMaxXp( rankId ) );
471  self SetDStat( "playerstatslist", "lastxp", "StatValue", ‪getRankXPCapped( self.pers["rankxp"] ) );
472  }
473 
474  self.explosiveKills[0] = 0;
475 
479 }
480 
482 {
483  self endon("disconnect");
484 
485  self thread ‪removeRankHUD();
486 }
487 
489 {
490  self endon("disconnect");
491 
492  self thread ‪removeRankHUD();
493 }
494 
496 {
497  self endon("disconnect");
498 
499  /*if ( !isdefined( self.hud_momentumupdate ) )
500  {
501  self.hud_momentumupdate = NewScoreHudElem(self);
502  self.hud_momentumupdate.horzAlign = "center";
503  self.hud_momentumupdate.vertAlign = "middle";
504  self.hud_momentumupdate.alignX = "center";
505  self.hud_momentumupdate.alignY = "middle";
506  self.hud_momentumupdate.x = 0;
507  if( self IsSplitscreen() )
508  self.hud_momentumupdate.y = -72;
509  else
510  self.hud_momentumupdate.y = -117;
511  self.hud_momentumupdate.baseY = self.hud_momentumupdate.y;
512  self.hud_momentumupdate.font = "default";
513  self.hud_momentumupdate.fontscale = 1.5;
514  self.hud_momentumupdate.archived = false;
515  self.hud_momentumupdate.color = (1,1,0.5);
516  self.hud_momentumupdate.alpha = 0;
517  self.hud_momentumupdate.sort = 50;
518  }*/
519 
520  if(!isdefined(self.hud_rankscroreupdate))
521  {
522  self.hud_rankscroreupdate = NewScoreHudElem(self);
523  self.hud_rankscroreupdate.horzAlign = "center";
524  self.hud_rankscroreupdate.vertAlign = "middle";
525  self.hud_rankscroreupdate.alignX = "center";
526  self.hud_rankscroreupdate.alignY = "middle";
527  self.hud_rankscroreupdate.x = 0;
528  if( self IsSplitscreen() )
529  self.hud_rankscroreupdate.y = -15;
530  else
531  self.hud_rankscroreupdate.y = -60;
532  self.hud_rankscroreupdate.font = "default";
533  self.hud_rankscroreupdate.fontscale = 2.0;
534  self.hud_rankscroreupdate.archived = false;
535  self.hud_rankscroreupdate.color = (1,1,0.5);
536  self.hud_rankscroreupdate.alpha = 0;
537  self.hud_rankscroreupdate.sort = 50;
538  self.hud_rankscroreupdate ‪hud::font_pulse_init();
539  }
540 
541  /*if(!isdefined(self.hud_momentumreason))
542  {
543  self.hud_momentumreason = NewScoreHudElem(self);
544  self.hud_momentumreason.horzAlign = "center";
545  self.hud_momentumreason.vertAlign = "middle";
546  self.hud_momentumreason.alignX = "center";
547  self.hud_momentumreason.alignY = "middle";
548  self.hud_momentumreason.x = 0;
549  if( self IsSplitscreen() )
550  self.hud_momentumreason.y = -32;
551  else
552  self.hud_momentumreason.y = -77;
553  self.hud_momentumreason.font = "default";
554  self.hud_momentumreason.fontscale = 1.5;
555  self.hud_momentumreason.archived = false;
556  self.hud_momentumreason.color = (1,1,1);
557  self.hud_momentumreason.alpha = 0;
558  self.hud_momentumreason.sort = 50;
559  self.hud_momentumreason hud::font_pulse_init();
560  self.hud_momentumreason.maxFontScale = 6.3;
561  self.hud_momentumreason.outFrames = self.hud_momentumreason.inFrames + self.hud_momentumreason.outFrames;
562  self.hud_momentumreason.inFrames = 0;
563  }*/
564 }
565 
566 function ‪incCodPoints( amount )
567 {
568  if( !‪util::isRankEnabled() )
569  return;
570 
571  if( !level.rankedMatch )
572  return;
573 
574  newCodPoints = ‪getCodPointsCapped( self.pers["codpoints"] + amount );
575  if ( newCodPoints > self.pers["codpoints"] )
576  {
577  self.pers["summary"]["codpoints"] += ( newCodPoints - self.pers["codpoints"] );
578  }
579  self.pers["codpoints"] = newCodPoints;
580 
581  ‪setCodPointsStat( int( newCodPoints ) );
582 }
583 
585 {
586  foreach( team in level.teams )
587  {
588  if ( !level.playerCount[team] )
589  return false;
590  }
591  return true;
592 }
593 
594 function ‪giveRankXP( type, value, devAdd )
595 {
596  self endon("disconnect");
597 
598  // TODO: will enable it after zombies ranking system is working
599  if( SessionModeIsZombiesGame() )
600  {
601  return;
602  }
603 
604  if ( level.teamBased && (!‪atLeastOnePlayerOnEachTeam()) && !isdefined( devAdd ) )
605  return;
606  else if ( !level.teamBased && ( ‪util::totalPlayerCount() < 2) && !isdefined( devAdd ) )
607  return;
608 
609  if( !‪util::isRankEnabled() )
610  return;
611 
612  pixbeginevent("giveRankXP");
613 
614  if ( !isdefined( value ) )
615  value = ‪getScoreInfoValue( type );
616 
617  // this switch statement should be inverted. I am pretty sure there are fewer
618  // things that we dont want to scale then there are that we do.
619  switch( type )
620  {
621  case "kill":
622  case "headshot":
623  case "assist":
624  case "assist_25":
625  case "assist_50":
626  case "assist_75":
627  case "helicopterassist":
628  case "helicopterassist_25":
629  case "helicopterassist_50":
630  case "helicopterassist_75":
631  case "helicopterkill":
632  case "rcbombdestroy":
633  case "spyplanekill":
634  case "spyplaneassist":
635  case "dogkill":
636  case "dogassist":
637  case "capture":
638  case "defend":
639  case "return":
640  case "pickup":
641  case "plant":
642  case "defuse":
643  case "destroyer":
644  case "assault":
645  case "assault_assist":
646  case "revive":
647  case "medal":
648  value = int( value * level.xpScale );
649  break;
650  default:
651  if ( level.xpScale == 0 )
652  value = 0;
653  break;
654  }
655 
656  xpIncrease = self ‪incRankXP( value );
657 
658  if ( level.rankedMatch )
659  {
660  self ‪updateRank();
661  }
662 
663  // Set the XP stat after any unlocks, so that if the final stat set gets lost the unlocks won't be gone for good.
664  if ( value != 0 )
665  {
666  self ‪syncXPStat();
667  }
668 
669  if ( isdefined( self.enableText ) && self.enableText && !level.hardcoreMode )
670  {
671  if ( type == "teamkill" )
672  self thread ‪updateRankScoreHUD( 0 - ‪getScoreInfoValue( "kill" ) );
673  else
674  self thread ‪updateRankScoreHUD( value );
675  }
676 
677  switch( type )
678  {
679  case "kill":
680  case "headshot":
681  case "suicide":
682  case "teamkill":
683  case "assist":
684  case "assist_25":
685  case "assist_50":
686  case "assist_75":
687  case "helicopterassist":
688  case "helicopterassist_25":
689  case "helicopterassist_50":
690  case "helicopterassist_75":
691  case "capture":
692  case "defend":
693  case "return":
694  case "pickup":
695  case "assault":
696  case "revive":
697  case "medal":
698  self.pers["summary"]["score"] += value;
699  ‪incCodPoints( ‪round_this_number( value * level.codPointsXPScale ) );
700  break;
701 
702  case "win":
703  case "loss":
704  case "tie":
705  self.pers["summary"]["match"] += value;
706  ‪incCodPoints( ‪round_this_number( value * level.codPointsMatchScale ) );
707  break;
708 
709  case "challenge":
710  self.pers["summary"]["challenge"] += value;
711  ‪incCodPoints( ‪round_this_number( value * level.codPointsChallengeScale ) );
712  break;
713 
714  default:
715  self.pers["summary"]["misc"] += value; //keeps track of ungrouped match xp reward
716  self.pers["summary"]["match"] += value;
717  ‪incCodPoints( ‪round_this_number( value * level.codPointsMatchScale ) );
718  break;
719  }
720 
721  self.pers["summary"]["xp"] += xpIncrease;
722 
723  pixendevent();
724 }
725 
726 function ‪round_this_number( value )
727 {
728  value = int( value + 0.5 );
729  return value;
730 }
731 
732 function ‪updateRank()
733 {
734  newRankId = self ‪getRank();
735  if ( newRankId == self.pers["rank"] )
736  return false;
737 
738  oldRank = self.pers["rank"];
739  rankId = self.pers["rank"];
740  self.pers["rank"] = newRankId;
741 
742  // This function is a bit 'funny' - it decides to handle all of the unlocks for the current rank
743  // before handling all of the unlocks for any new ranks - it's probably as a safety to handle the
744  // case where unlocks have not happened for the current rank (which should only be the case for rank 0)
745  // This will hopefully go away once the new ranking system is in place fully
746  while ( rankId <= newRankId )
747  {
748  self SetDStat( "playerstatslist", "rank", "StatValue", rankId );
749  self SetDStat( "playerstatslist", "minxp", "StatValue", int(level.rankTable[rankId][2]) );
750  self SetDStat( "playerstatslist", "maxxp", "StatValue", int(level.rankTable[rankId][7]) );
751 
752  // tell lobby to popup promotion window instead
753  self.setPromotion = true;
754  if ( level.rankedMatch && level.gameEnded && !self IsSplitscreen() )
755  self setDStat( "AfterActionReportStats", "lobbyPopup", "promotion" );
756 
757  // Don't add CoD Points for the old rank - only add when actually ranking up
758  if ( rankId != oldRank )
759  {
760  codPointsEarnedForRank = ‪getRankInfoCodPointsEarned( rankId );
761 
762  ‪incCodPoints( codPointsEarnedForRank );
763 
764 
765  if ( !isdefined( self.pers["rankcp"] ) )
766  {
767  self.pers["rankcp"] = 0;
768  }
769 
770  self.pers["rankcp"] += codPointsEarnedForRank;
771  }
772 
773  rankId++;
774  }
775  /#print( "promoted from " + oldRank + " to " + newRankId + " timeplayed: " + self GetDStat( "playerstatslist", "time_played_total", "StatValue" ) ); #/
776 
777  self setRank( newRankId );
778 
779  return true;
780 }
781 
782 
783 function ‪CodeCallback_RankUp( rank, prestige, unlockTokensAdded )
784 {
785  //No campaign notifications, handled in AAR
786  if( SessionModeIsCampaignGame() )
787  {
788  // If extra tokens should be awarded at this player level, award them immediately.
789  n_extra_tokens = level.rankTable[rank][18];
790 
791  if (isdefined(n_extra_tokens) && n_extra_tokens != "" )
792  {
793  self GiveUnlockToken(int(n_extra_tokens));
794  }
795 
796  UploadStats( self );
797  return;
798  }
799 
800  if( SessionModeIsMultiplayerGame() )
801  {
802  if ( rank > 53 )
803  {
804  self GiveAchievement( "MP_REACH_ARENA" );// Reach Commander (Level 55) in Multiplayer by playing in Public Match and/or Arena.
805  }
806  if ( rank > 8 )
807  {
808  self GiveAchievement( "MP_REACH_SERGEANT" );// Welcome to the Club Reach Sergeant (Level 10) in Multiplayer by playing in Public Match and/or Arena.
809  }
810  }
811 
812  self LUINotifyEvent( &"rank_up", 3, rank, prestige, unlockTokensAdded );
813  self LUINotifyEventToSpectators( &"rank_up", 3, rank, prestige, unlockTokensAdded );
814 
815  if ( isdefined( level.playPromotionReaction ) )
816  {
817  self thread [[level.playPromotionReaction]]();
818  }
819 }
820 
821 function ‪getItemIndex( refString )
822 {
823  statsTableName = ‪util::getStatsTableName();
824  itemIndex = int( tableLookup( statsTableName, 4, refString, 0 ) );
825  assert( itemIndex > 0, "statsTable refstring " + refString + " has invalid index: " + itemIndex );
826 
827  return itemIndex;
828 }
829 
831 {
832  player = self;
833 }
834 
835 function ‪updateRankScoreHUD( amount )
836 {
837  self endon( "disconnect" );
838  self endon( "joined_team" );
839  self endon( "joined_spectators" );
840 
841  if ( isdefined( level.usingMomentum ) && level.usingMomentum )
842  {
843  return; // Disabled because this is now handled in updateMomentumHUD function
844  }
845 
846  if ( amount == 0 )
847  return;
848 
849  self notify( "update_score" );
850  self endon( "update_score" );
851 
852  self.rankUpdateTotal += amount;
853 
855 
856  if( isdefined( self.hud_rankscroreupdate ) )
857  {
858  if ( self.rankUpdateTotal < 0 )
859  {
860  self.hud_rankscroreupdate.label = &"";
861  self.hud_rankscroreupdate.color = (0.73,0.19,0.19);
862  }
863  else
864  {
865  self.hud_rankscroreupdate.label = &"MP_PLUS";
866  self.hud_rankscroreupdate.color = (1,1,0.5);
867  }
868 
869  self.hud_rankscroreupdate setValue(self.rankUpdateTotal);
870 
871  self.hud_rankscroreupdate.alpha = 0.85;
872  self.hud_rankscroreupdate thread ‪hud::font_pulse( self );
873 
874  wait 1;
875  self.hud_rankscroreupdate fadeOverTime( 0.75 );
876  self.hud_rankscroreupdate.alpha = 0;
877 
878  self.rankUpdateTotal = 0;
879  }
880 }
881 
882 function ‪updateMomentumHUD( amount, reason, reasonValue )
883 {
884  self endon( "disconnect" );
885  self endon( "joined_team" );
886  self endon( "joined_spectators" );
887 
888  if ( amount == 0 )
889  return;
890 
891  self notify( "update_score" );
892  self endon( "update_score" );
893 
894  self.rankUpdateTotal += amount;
895 
896  if( isdefined( self.hud_rankscroreupdate ) )
897  {
898  if ( self.rankUpdateTotal < 0 )
899  {
900  self.hud_rankscroreupdate.label = &"";
901  self.hud_rankscroreupdate.color = (0.73,0.19,0.19);
902  }
903  else
904  {
905  self.hud_rankscroreupdate.label = &"MP_PLUS";
906  self.hud_rankscroreupdate.color = (1,1,0.5);
907  }
908 
909  self.hud_rankscroreupdate setValue( self.rankUpdateTotal );
910 
911  self.hud_rankscroreupdate.alpha = 0.85;
912  self.hud_rankscroreupdate thread ‪hud::font_pulse( self );
913 
914  /*if ( isdefined( self.hud_momentumupdate ) && ( amount != self.rankUpdateTotal ) )
915  {
916  self.hud_momentumupdate.label = &"MP_PLUS";
917  self.hud_momentumupdate setValue( amount );
918  self.hud_momentumupdate.alpha = 1;
919  self.hud_momentumupdate.y = self.hud_momentumupdate.baseY;
920  self.hud_momentumupdate FadeOverTime( 0.5 );
921  self.hud_momentumupdate MoveOverTime( 0.5 );
922  self.hud_momentumupdate.y -= 20;
923  self.hud_momentumupdate.alpha = 0;
924  }*/
925 
926  if ( isdefined( self.hud_momentumreason ) )
927  {
928  if ( isdefined( reason ) )
929  {
930  if ( isdefined( reasonValue ) )
931  {
932  self.hud_momentumreason.label = reason;
933  self.hud_momentumreason setValue( reasonValue );
934  }
935  else
936  {
937  /*self.hud_momentumreason.label = &"";
938  self.hud_momentumreason SetText( reason );*/
939  self.hud_momentumreason.label = reason;
940  self.hud_momentumreason setValue( amount );
941  }
942  self.hud_momentumreason.alpha = 0.85;
943  self.hud_momentumreason thread ‪hud::font_pulse( self );
944  }
945  else
946  {
947  self.hud_momentumreason fadeOverTime( 0.01 );
948  self.hud_momentumreason.alpha = 0;
949  }
950  }
951 
952  wait 1;
953  self.hud_rankscroreupdate fadeOverTime( 0.75 );
954  self.hud_rankscroreupdate.alpha = 0;
955 
956  if ( isdefined( self.hud_momentumreason ) && isdefined( reason ) )
957  {
958  self.hud_momentumreason fadeOverTime( 0.75 );
959  self.hud_momentumreason.alpha = 0;
960  }
961 
962  wait 0.75;
963 
964  self.rankUpdateTotal = 0;
965  }
966 }
967 
969 {
970  if(isdefined(self.hud_rankscroreupdate))
971  self.hud_rankscroreupdate.alpha = 0;
972 
973  if ( isdefined( self.hud_momentumreason ) )
974  {
975  self.hud_momentumreason.alpha = 0;
976  }
977 }
978 
979 function ‪getRank()
980 {
981  rankXp = ‪getRankXPCapped( self.pers["rankxp"] );
982  rankId = self.pers["rank"];
983 
984  if ( rankXp < (‪getRankInfoMinXP( rankId ) + ‪getRankInfoXPAmt( rankId )) )
985  return rankId;
986  else
987  return self ‪getRankForXp( rankXp );
988 }
989 
990 function ‪getRankForXp( xpVal )
991 {
992  rankId = 0;
993  rankName = level.rankTable[rankId][1];
994  assert( isdefined( rankName ) );
995 
996  while ( isdefined( rankName ) && rankName != "" )
997  {
998  if ( xpVal < ‪getRankInfoMinXP( rankId ) + ‪getRankInfoXPAmt( rankId ) )
999  return rankId;
1000 
1001  rankId++;
1002  if ( isdefined( level.rankTable[rankId] ) )
1003  rankName = level.rankTable[rankId][1];
1004  else
1005  rankName = undefined;
1006  }
1007 
1008  rankId--;
1009  return rankId;
1010 }
1011 
1012 function ‪getSPM()
1013 {
1014  rankLevel = self ‪getRank() + 1;
1015  return (3 + (rankLevel * 0.5))*10;
1016 }
1017 
1018 function ‪getRankXP()
1019 {
1020  return ‪getRankXPCapped( self.pers["rankxp"] );
1021 }
1022 
1023 function ‪incRankXP( amount )
1024 {
1025  if ( !level.rankedMatch )
1026  return 0;
1027 
1028  xp = self ‪getRankXP();
1029  newXp = ‪getRankXPCapped( xp + amount );
1030 
1031  if ( self.pers["rank"] == level.maxRank && newXp >= getRankInfoMaxXP( level.maxRank ) )
1032  newXp = getRankInfoMaxXP( level.maxRank );
1033 
1034  if ( self IsStarterPack() && self.pers["rank"] >= level.maxRankStarterPack && newXp >= ‪getRankInfoMinXP( level.maxRankStarterPack ) )
1035  newXp = ‪getRankInfoMinXP( level.maxRankStarterPack );
1036 
1037  xpIncrease = ‪getRankXPCapped( newXp ) - self.pers["rankxp"];
1038 
1039  if ( xpIncrease < 0 )
1040  {
1041  xpIncrease = 0;
1042  }
1043 
1044  self.pers["rankxp"] = ‪getRankXPCapped( newXp );
1045 
1046  return xpIncrease;
1047 }
1048 
1049 function ‪syncXPStat()
1050 {
1051  xp = ‪getRankXPCapped( self ‪getRankXP() );
1052 
1053  cp = ‪getCodPointsCapped( int( self.pers["codpoints"] ) );
1054 
1055  self SetDStat( "playerstatslist", "rankxp", "StatValue", xp );
1056 
1057  self SetDStat( "playerstatslist", "codpoints", "StatValue", cp );
1058 }
‪doesScoreInfoCountTowardRampage
‪function doesScoreInfoCountTowardRampage(type)
Definition: rank_shared.gsc:301
‪getScoreEventTableID
‪function getScoreEventTableID()
Definition: scoreevents_shared.gsc:185
‪getCombatEfficiencyEvent
‪function getCombatEfficiencyEvent(type)
Definition: rank_shared.gsc:296
‪getRankInfoCodPointsEarned
‪function getRankInfoCodPointsEarned(rankId)
Definition: rank_shared.gsc:336
‪updateMomentumHUD
‪function updateMomentumHUD(amount, reason, reasonValue)
Definition: rank_shared.gsc:882
‪GAMEMODE_LEAGUE_MATCH
‪#define GAMEMODE_LEAGUE_MATCH
Definition: shared.gsh:15
‪is_bot
‪function is_bot()
Definition: util_shared.gsc:2488
‪setCodPointsStat
‪function setCodPointsStat(codPoints)
Definition: rank_shared.gsc:380
‪on_player_spawned
‪function on_player_spawned()
Definition: rank_shared.gsc:495
‪incCodPoints
‪function incCodPoints(amount)
Definition: rank_shared.gsc:566
‪SCOREINFOTABLE_MEDAL_REFERENCE
‪#define SCOREINFOTABLE_MEDAL_REFERENCE
Definition: scoreevents_shared.gsh:7
‪on_start_gametype
‪function on_start_gametype(func, obj)
Definition: callbacks_shared.csc:285
‪endGameUpdate
‪function endGameUpdate()
Definition: rank_shared.gsc:830
‪getRankInfoLevel
‪function getRankInfoLevel(rankId)
Definition: rank_shared.gsc:331
‪getRank
‪function getRank()
Definition: rank_shared.gsc:979
‪SCORE_EVENT_MAX_COUNT
‪#define SCORE_EVENT_MAX_COUNT
Definition: scoreevents_shared.gsh:26
‪getCodPointsStat
‪function getCodPointsStat()
Definition: rank_shared.gsc:367
‪removeRankHUD
‪function removeRankHUD()
Definition: rank_shared.gsc:968
‪getItemIndex
‪function getItemIndex(refString)
Definition: rank_shared.gsc:821
‪IS_TRUE
‪#define IS_TRUE(__a)
Definition: shared.gsh:251
‪getRankInfoMaxXp
‪function getRankInfoMaxXp(rankId)
Definition: rank_shared.gsc:316
‪getRankInfoXPAmt
‪function getRankInfoXPAmt(rankId)
Definition: rank_shared.gsc:311
‪getScoreInfoValue
‪function getScoreInfoValue(type)
Definition: rank_shared.gsc:248
‪isRankEnabled
‪function isRankEnabled()
Definition: util_shared.gsc:3492
‪getXPEventColumn
‪function getXPEventColumn(gameType)
Definition: scoreevents_shared.gsc:209
‪DEFAULT
‪#define DEFAULT(__var, __default)
Definition: shared.gsh:270
‪getScoreInfoLabel
‪function getScoreInfoLabel(type)
Definition: rank_shared.gsc:291
‪on_spawned
‪function on_spawned(func, obj)
Definition: callbacks_shared.csc:245
‪SCOREINFOTABLE_SAVE_MEDAL_STATS
‪#define SCOREINFOTABLE_SAVE_MEDAL_STATS
Definition: scoreevents_shared.gsh:13
‪init
‪function init()
Definition: rank_shared.gsc:25
‪getRankForXp
‪function getRankForXp(xpVal)
Definition: rank_shared.gsc:990
‪syncXPStat
‪function syncXPStat()
Definition: rank_shared.gsc:1049
‪font_pulse_init
‪function font_pulse_init()
Definition: hud_shared.gsc:187
‪totalPlayerCount
‪function totalPlayerCount()
Definition: util_shared.gsc:3482
‪font_pulse
‪function font_pulse(player)
Definition: hud_shared.gsc:196
‪SCOREINFOTABLE_SCRIPT_REFERENCE
‪#define SCOREINFOTABLE_SCRIPT_REFERENCE
Definition: scoreevents_shared.gsh:5
‪registerScoreInfo
‪function registerScoreInfo(type, value, xp, label, teamscore_material)
Definition: rank_shared.gsc:213
‪on_joined_spectators
‪function on_joined_spectators()
Definition: rank_shared.gsc:488
‪getRankInfoFull
‪function getRankInfoFull(rankId)
Definition: rank_shared.gsc:321
‪incRankXP
‪function incRankXP(amount)
Definition: rank_shared.gsc:1023
‪REGISTER_SYSTEM
‪#define REGISTER_SYSTEM(__sys, __func_init_preload, __reqs)
Definition: shared.gsh:204
‪SCOREINFOTABLE_TEAM_SCORE_MATERIAL
‪#define SCOREINFOTABLE_TEAM_SCORE_MATERIAL
Definition: scoreevents_shared.gsh:9
‪getRankInfoMinXP
‪function getRankInfoMinXP(rankId)
Definition: rank_shared.gsc:306
‪updateRankScoreHUD
‪function updateRankScoreHUD(amount)
Definition: rank_shared.gsc:835
‪__init__
‪function __init__()
Definition: rank_shared.gsc:20
‪updateRank
‪function updateRank()
Definition: rank_shared.gsc:732
‪on_joined_team
‪function on_joined_team()
Definition: rank_shared.gsc:481
‪on_joined_spectate
‪function on_joined_spectate(func, obj)
Definition: callbacks_shared.gsc:290
‪getArenaPointsStat
‪function getArenaPointsStat()
Definition: rank_shared.gsc:398
‪shouldSkipMomentumDisplay
‪function shouldSkipMomentumDisplay(type)
Definition: rank_shared.gsc:276
‪round_this_number
‪function round_this_number(value)
Definition: rank_shared.gsc:726
‪SCOREINFOTABLE_INCLUDE_KILLSTREAKS
‪#define SCOREINFOTABLE_INCLUDE_KILLSTREAKS
Definition: scoreevents_shared.gsh:10
‪getRankInfoIcon
‪function getRankInfoIcon(rankId, prestigeId)
Definition: rank_shared.gsc:326
‪SCOREINFOTABLE_INCLUDE_HERO
‪#define SCOREINFOTABLE_INCLUDE_HERO
Definition: scoreevents_shared.gsh:12
‪on_player_connect
‪function on_player_connect()
Definition: rank_shared.gsc:408
‪SCOREINFOTABLE_DEMO_BOOKMARK_PRIORITY
‪#define SCOREINFOTABLE_DEMO_BOOKMARK_PRIORITY
Definition: scoreevents_shared.gsh:14
‪getSPM
‪function getSPM()
Definition: rank_shared.gsc:1012
‪getRankXP
‪function getRankXP()
Definition: rank_shared.gsc:1018
‪giveRankXP
‪function giveRankXP(type, value, devAdd)
Definition: rank_shared.gsc:594
‪CodeCallback_RankUp
‪function CodeCallback_RankUp(rank, prestige, unlockTokensAdded)
Definition: rank_shared.gsc:783
‪on_connect
‪function on_connect()
Definition: _arena.gsc:20
‪SCOREINFOTABLE_SCORE_STRING
‪#define SCOREINFOTABLE_SCORE_STRING
Definition: scoreevents_shared.gsh:6
‪getScoreInfoXP
‪function getScoreInfoXP(type)
Definition: rank_shared.gsc:262
‪getRankXpStat
‪function getRankXpStat()
Definition: rank_shared.gsc:385
‪getStatsTableName
‪function getStatsTableName()
Definition: util_shared.csc:1343
‪atLeastOnePlayerOnEachTeam
‪function atLeastOnePlayerOnEachTeam()
Definition: rank_shared.gsc:584
‪shouldKickByRank
‪function shouldKickByRank()
Definition: rank_shared.gsc:341
‪initScoreInfo
‪function initScoreInfo()
Definition: rank_shared.gsc:94
‪getCodPointsCapped
‪function getCodPointsCapped(inCodPoints)
Definition: rank_shared.gsc:203
‪SCOREINFOTABLE_INCLUDE_COMBAT_EFFICIENCY_EVENT
‪#define SCOREINFOTABLE_INCLUDE_COMBAT_EFFICIENCY_EVENT
Definition: scoreevents_shared.gsh:11
‪WAIT_SERVER_FRAME
‪#define WAIT_SERVER_FRAME
Definition: shared.gsh:265
‪getScoreEventColumn
‪function getScoreEventColumn(gameType)
Definition: scoreevents_shared.gsc:198
‪getRankXPCapped
‪function getRankXPCapped(inRankXp)
Definition: rank_shared.gsc:193