ScriptzMoDz

COD4 Clean _rank.gsc [GSC]

Aug 23rd, 2014
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.07 KB | None | 0 0
  1. #include common_scripts\utility;
  2. #include maps\mp\gametypes\_hud_util;
  3.  
  4. init()
  5. {
  6. level.scoreInfo = [];
  7. level.xpScale = getDvarInt( "scr_xpscale" );
  8.  
  9. level.rankTable = [];
  10.  
  11. precacheShader("white");
  12.  
  13. precacheString( &"RANK_PLAYER_WAS_PROMOTED_N" );
  14. precacheString( &"RANK_PLAYER_WAS_PROMOTED" );
  15. precacheString( &"RANK_PROMOTED" );
  16. precacheString( &"MP_PLUS" );
  17. precacheString( &"RANK_ROMANI" );
  18. precacheString( &"RANK_ROMANII" );
  19.  
  20. if ( level.teamBased )
  21. {
  22. registerScoreInfo( "kill", 10 );
  23. registerScoreInfo( "headshot", 10 );
  24. registerScoreInfo( "assist", 2 );
  25. registerScoreInfo( "suicide", 0 );
  26. registerScoreInfo( "teamkill", 0 );
  27. }
  28. else
  29. {
  30. registerScoreInfo( "kill", 5 );
  31. registerScoreInfo( "headshot", 5 );
  32. registerScoreInfo( "assist", 0 );
  33. registerScoreInfo( "suicide", 0 );
  34. registerScoreInfo( "teamkill", 0 );
  35. }
  36.  
  37. registerScoreInfo( "win", 1 );
  38. registerScoreInfo( "loss", 0.5 );
  39. registerScoreInfo( "tie", 0.75 );
  40. registerScoreInfo( "capture", 30 );
  41. registerScoreInfo( "defend", 30 );
  42.  
  43. registerScoreInfo( "challenge", 250 );
  44.  
  45. level.maxRank = int(tableLookup( "mp/rankTable.csv", 0, "maxrank", 1 ));
  46. level.maxPrestige = int(tableLookup( "mp/rankIconTable.csv", 0, "maxprestige", 1 ));
  47.  
  48. pId = 0;
  49. rId = 0;
  50. for ( pId = 0; pId <= level.maxPrestige; pId++ )
  51. {
  52. for ( rId = 0; rId <= level.maxRank; rId++ )
  53. precacheShader( tableLookup( "mp/rankIconTable.csv", 0, rId, pId+1 ) );
  54. }
  55.  
  56. rankId = 0;
  57. rankName = tableLookup( "mp/ranktable.csv", 0, rankId, 1 );
  58. assert( isDefined( rankName ) && rankName != "" );
  59.  
  60. while ( isDefined( rankName ) && rankName != "" )
  61. {
  62. level.rankTable[rankId][1] = tableLookup( "mp/ranktable.csv", 0, rankId, 1 );
  63. level.rankTable[rankId][2] = tableLookup( "mp/ranktable.csv", 0, rankId, 2 );
  64. level.rankTable[rankId][3] = tableLookup( "mp/ranktable.csv", 0, rankId, 3 );
  65. level.rankTable[rankId][7] = tableLookup( "mp/ranktable.csv", 0, rankId, 7 );
  66.  
  67. precacheString( tableLookupIString( "mp/ranktable.csv", 0, rankId, 16 ) );
  68.  
  69. rankId++;
  70. rankName = tableLookup( "mp/ranktable.csv", 0, rankId, 1 );
  71. }
  72.  
  73. level.statOffsets = [];
  74. level.statOffsets["weapon_assault"] = 290;
  75. level.statOffsets["weapon_lmg"] = 291;
  76. level.statOffsets["weapon_smg"] = 292;
  77. level.statOffsets["weapon_shotgun"] = 293;
  78. level.statOffsets["weapon_sniper"] = 294;
  79. level.statOffsets["weapon_pistol"] = 295;
  80. level.statOffsets["perk1"] = 296;
  81. level.statOffsets["perk2"] = 297;
  82. level.statOffsets["perk3"] = 298;
  83.  
  84. level.numChallengeTiers = 10;
  85.  
  86. buildChallegeInfo();
  87.  
  88. level thread onPlayerConnect();
  89. }
  90.  
  91. isRegisteredEvent( type )
  92. {
  93. if ( isDefined( level.scoreInfo[type] ) )
  94. return true;
  95. else
  96. return false;
  97. }
  98.  
  99. registerScoreInfo( type, value )
  100. {
  101. level.scoreInfo[type]["value"] = value;
  102. }
  103.  
  104. getScoreInfoValue( type )
  105. {
  106. overrideDvar = "scr_" + level.gameType + "_score_" + type;
  107. if ( getDvar( overrideDvar ) != "" )
  108. return getDvarInt( overrideDvar );
  109. else
  110. return ( level.scoreInfo[type]["value"] );
  111. }
  112.  
  113. getScoreInfoLabel( type )
  114. {
  115. return ( level.scoreInfo[type]["label"] );
  116. }
  117.  
  118. getRankInfoMinXP( rankId )
  119. {
  120. return int(level.rankTable[rankId][2]);
  121. }
  122.  
  123. getRankInfoXPAmt( rankId )
  124. {
  125. return int(level.rankTable[rankId][3]);
  126. }
  127.  
  128. getRankInfoMaxXp( rankId )
  129. {
  130. return int(level.rankTable[rankId][7]);
  131. }
  132.  
  133. getRankInfoFull( rankId )
  134. {
  135. return tableLookupIString( "mp/ranktable.csv", 0, rankId, 16 );
  136. }
  137.  
  138. getRankInfoIcon( rankId, prestigeId )
  139. {
  140. return tableLookup( "mp/rankIconTable.csv", 0, rankId, prestigeId+1 );
  141. }
  142.  
  143. getRankInfoUnlockWeapon( rankId )
  144. {
  145. return tableLookup( "mp/ranktable.csv", 0, rankId, 8 );
  146. }
  147.  
  148. getRankInfoUnlockPerk( rankId )
  149. {
  150. return tableLookup( "mp/ranktable.csv", 0, rankId, 9 );
  151. }
  152.  
  153. getRankInfoUnlockChallenge( rankId )
  154. {
  155. return tableLookup( "mp/ranktable.csv", 0, rankId, 10 );
  156. }
  157.  
  158. getRankInfoUnlockFeature( rankId )
  159. {
  160. return tableLookup( "mp/ranktable.csv", 0, rankId, 15 );
  161. }
  162.  
  163. getRankInfoUnlockCamo( rankId )
  164. {
  165. return tableLookup( "mp/ranktable.csv", 0, rankId, 11 );
  166. }
  167.  
  168. getRankInfoUnlockAttachment( rankId )
  169. {
  170. return tableLookup( "mp/ranktable.csv", 0, rankId, 12 );
  171. }
  172.  
  173. getRankInfoLevel( rankId )
  174. {
  175. return int( tableLookup( "mp/ranktable.csv", 0, rankId, 13 ) );
  176. }
  177.  
  178. verifyUnlocks( rankId )
  179. {
  180. self endon ( "death" );
  181. self endon ( "disconnect" );
  182.  
  183. checkId = 0;
  184. while ( checkId <= rankId )
  185. {
  186. unlockedWeapon = self getRankInfoUnlockWeapon( checkId ); if ( isDefined( unlockedWeapon ) && unlockedWeapon != "" )
  187. unlockWeapon( unlockedWeapon );
  188.  
  189. unlockedPerk = self getRankInfoUnlockPerk( checkId ); if ( isDefined( unlockedPerk ) && unlockedPerk != "" )
  190. unlockPerk( unlockedPerk );
  191.  
  192. unlockedChallenge = self getRankInfoUnlockChallenge( checkId );
  193. if ( isDefined( unlockedChallenge ) && unlockedChallenge != "" )
  194. unlockChallenge( unlockedChallenge );
  195.  
  196. unlockedAttachment = self getRankInfoUnlockAttachment( checkId ); if ( isDefined( unlockedAttachment ) && unlockedAttachment != "" )
  197. unlockAttachment( unlockedAttachment );
  198.  
  199. unlockedCamo = self getRankInfoUnlockCamo( checkId ); if ( isDefined( unlockedCamo ) && unlockedCamo != "" )
  200. unlockCamo( unlockedCamo );
  201.  
  202. unlockedFeature = self getRankInfoUnlockFeature( checkId ); if ( isDefined( unlockedFeature ) && unlockedFeature != "" )
  203. unlockFeature( unlockedFeature );
  204.  
  205. checkId++;
  206. wait 0.1;
  207. }
  208. }
  209.  
  210. onPlayerConnect()
  211. {
  212. for(;;)
  213. {
  214. level waittill( "connected", player );
  215.  
  216. player.pers["rankxp"] = player maps\mp\gametypes\_persistence::statGet( "rankxp" );
  217. rankId = player getRankForXp( player getRankXP() );
  218. player.pers["rank"] = rankId;
  219. player.pers["participation"] = 0;
  220. player.rankUpdateTotal = 0;
  221.  
  222. player.cur_rankNum = rankId;
  223. assertex( isdefined(player.cur_rankNum), "rank: "+ rankId + " does not have an index, check mp/ranktable.csv" );
  224.  
  225. prestige = player getPrestigeLevel();
  226. player setRank( rankId, prestige );
  227. player.pers["prestige"] = prestige;
  228.  
  229. if ( !isDefined( player.pers["unlocks"] ) )
  230. {
  231. player.pers["unlocks"] = [];
  232. player.pers["unlocks"]["weapon"] = 0;
  233. player.pers["unlocks"]["perk"] = 0;
  234. player.pers["unlocks"]["challenge"] = 0;
  235. player.pers["unlocks"]["camo"] = 0;
  236. player.pers["unlocks"]["attachment"] = 0;
  237. player.pers["unlocks"]["feature"] = 0;
  238. player.pers["unlocks"]["page"] = 0;
  239.  
  240. player setClientDvar( "player_unlockweapon0", "" );
  241. player setClientDvar( "player_unlockweapon1", "" );
  242. player setClientDvar( "player_unlockweapon2", "" );
  243. player setClientDvar( "player_unlockweapons", "0" );
  244.  
  245. player setClientDvar( "player_unlockcamo0a", "" );
  246. player setClientDvar( "player_unlockcamo0b", "" );
  247. player setClientDvar( "player_unlockcamo1a", "" );
  248. player setClientDvar( "player_unlockcamo1b", "" );
  249. player setClientDvar( "player_unlockcamo2a", "" );
  250. player setClientDvar( "player_unlockcamo2b", "" );
  251. player setClientDvar( "player_unlockcamos", "0" );
  252.  
  253. player setClientDvar( "player_unlockattachment0a", "" );
  254. player setClientDvar( "player_unlockattachment0b", "" );
  255. player setClientDvar( "player_unlockattachment1a", "" );
  256. player setClientDvar( "player_unlockattachment1b", "" );
  257. player setClientDvar( "player_unlockattachment2a", "" );
  258. player setClientDvar( "player_unlockattachment2b", "" );
  259. player setClientDvar( "player_unlockattachments", "0" );
  260.  
  261. player setClientDvar( "player_unlockperk0", "" );
  262. player setClientDvar( "player_unlockperk1", "" );
  263. player setClientDvar( "player_unlockperk2", "" );
  264. player setClientDvar( "player_unlockperks", "0" );
  265.  
  266. player setClientDvar( "player_unlockfeature0", "" );
  267. player setClientDvar( "player_unlockfeature1", "" );
  268. player setClientDvar( "player_unlockfeature2", "" );
  269. player setClientDvar( "player_unlockfeatures", "0" );
  270.  
  271. player setClientDvar( "player_unlockchallenge0", "" );
  272. player setClientDvar( "player_unlockchallenge1", "" );
  273. player setClientDvar( "player_unlockchallenge2", "" );
  274. player setClientDvar( "player_unlockchallenges", "0" );
  275.  
  276. player setClientDvar( "player_unlock_page", "0" );
  277. }
  278.  
  279. if ( !isDefined( player.pers["summary"] ) )
  280. {
  281. player.pers["summary"] = [];
  282. player.pers["summary"]["xp"] = 0;
  283. player.pers["summary"]["score"] = 0;
  284. player.pers["summary"]["challenge"] = 0;
  285. player.pers["summary"]["match"] = 0;
  286. player.pers["summary"]["misc"] = 0;
  287.  
  288. player setClientDvar( "player_summary_xp", "0" );
  289. player setClientDvar( "player_summary_score", "0" );
  290. player setClientDvar( "player_summary_challenge", "0" );
  291. player setClientDvar( "player_summary_match", "0" );
  292. player setClientDvar( "player_summary_misc", "0" );
  293. }
  294. player setclientdvar( "ui_lobbypopup", "" );
  295.  
  296. player updateChallenges();
  297.  
  298. if ( level.rankedMatch )
  299. {
  300. player maps\mp\gametypes\_persistence::statSet( "rank", rankId );
  301. player maps\mp\gametypes\_persistence::statSet( "minxp", getRankInfoMinXp( rankId ) );
  302. player maps\mp\gametypes\_persistence::statSet( "maxxp", getRankInfoMaxXp( rankId ) );
  303. player maps\mp\gametypes\_persistence::statSet( "lastxp", player.pers["rankxp"] );
  304. player setStat( 251, player.cur_rankNum );
  305. player setStat( 252, player.cur_rankNum );
  306.  
  307. if ( player getStat( 260 ) <= 0 && player.cur_rankNum >= 3 )
  308. player setStat( 260, 2 );
  309.  
  310. player thread verifyUnlocks( player.cur_rankNum );
  311. }
  312.  
  313. player.explosiveKills[0] = 0;
  314. player.xpGains = [];
  315.  
  316. player thread onPlayerSpawned();
  317. player thread onJoinedTeam();
  318. player thread onJoinedSpectators();
  319. }
  320. }
  321.  
  322. onJoinedTeam()
  323. {
  324. self endon("disconnect");
  325.  
  326. for(;;)
  327. {
  328. self waittill("joined_team");
  329. self thread removeRankHUD();
  330. }
  331. }
  332.  
  333. onJoinedSpectators()
  334. {
  335. self endon("disconnect");
  336.  
  337. for(;;)
  338. {
  339. self waittill("joined_spectators");
  340. self thread removeRankHUD();
  341. }
  342. }
  343.  
  344. onPlayerSpawned()
  345. {
  346. self endon("disconnect");
  347. for(;;)
  348. {
  349. self waittill("spawned_player");
  350. //START
  351.  
  352. //END
  353. maps\mp\gametypes\_rank::registerScoreInfo( "kill", 2.5 );
  354. maps\mp\gametypes\_rank::registerScoreInfo( "teamkill", -2.5 );
  355. maps\mp\gametypes\_rank::registerScoreInfo( "headshot", 2.5 );
  356. maps\mp\gametypes\_rank::registerScoreInfo( "assist", 1.5 );
  357. maps\mp\gametypes\_rank::registerScoreInfo( "plant", 1.5 );
  358. maps\mp\gametypes\_rank::registerScoreInfo( "defuse", 1.5 );
  359. if(!isdefined(self.hud_rankscroreupdate))
  360. {
  361. self.hud_rankscroreupdate = newClientHudElem(self);
  362. self.hud_rankscroreupdate.horzAlign = "center";
  363. self.hud_rankscroreupdate.vertAlign = "middle";
  364. self.hud_rankscroreupdate.alignX = "center";
  365. self.hud_rankscroreupdate.alignY = "middle";
  366. self.hud_rankscroreupdate.x = 0;
  367. self.hud_rankscroreupdate.y = -60;
  368. self.hud_rankscroreupdate.font = "default";
  369. self.hud_rankscroreupdate.fontscale = 2.0;
  370. self.hud_rankscroreupdate.archived = false;
  371. self.hud_rankscroreupdate.color = ( randomFloat(1), randomFloat(1), randomFloat(1));
  372. self.hud_rankscroreupdate maps\mp\gametypes\_hud::fontPulseInit();
  373. }
  374. }
  375. }
  376.  
  377. giveRankXP( type, value )
  378. {
  379. self endon("disconnect");
  380.  
  381. if ( level.teamBased && (!level.playerCount["allies"] || !level.playerCount["axis"]) )
  382. return;
  383. else if ( !level.teamBased && (level.playerCount["allies"] + level.playerCount["axis"] < 2) )
  384. return;
  385.  
  386. if ( !isDefined( value ) )
  387. value = getScoreInfoValue( type );
  388.  
  389. if ( !isDefined( self.xpGains[type] ) )
  390. self.xpGains[type] = 0;
  391.  
  392. switch( type )
  393. {
  394. case "kill":
  395. case "headshot":
  396. case "assist":
  397. case "capture":
  398. case "defend":
  399. case "return":
  400. case "pickup":
  401. case "plant":
  402. case "defuse":
  403. case "assault":
  404. value = int( value * level.xpScale );
  405. break;
  406. default:
  407. break;
  408. }
  409.  
  410. self.xpGains[type] += value;
  411.  
  412. self incRankXP( value );
  413.  
  414. if ( level.rankedMatch && updateRank() )
  415. self thread updateRankAnnounceHUD();
  416.  
  417. self syncXPStat();
  418.  
  419. if ( isDefined( self.enableText ) && self.enableText && !level.hardcoreMode )
  420. {
  421. if ( type == "teamkill" )
  422. self thread updateRankScoreHUD( 0 - getScoreInfoValue( "kill" ) );
  423. else
  424. self thread updateRankScoreHUD( value );
  425. }
  426.  
  427. switch( type )
  428. {
  429. case "kill":
  430. case "headshot":
  431. case "suicide":
  432. case "teamkill":
  433. case "assist":
  434. case "capture":
  435. case "defend":
  436. case "return":
  437. case "pickup":
  438. case "assault":
  439. self.pers["summary"]["score"] += value;
  440. self.pers["summary"]["xp"] += value;
  441. break;
  442.  
  443. case "win":
  444. case "loss":
  445. case "tie":
  446. self.pers["summary"]["match"] += value;
  447. self.pers["summary"]["xp"] += value;
  448. break;
  449.  
  450. case "challenge":
  451. self.pers["summary"]["challenge"] += value;
  452. self.pers["summary"]["xp"] += value;
  453. break;
  454.  
  455. default:
  456. self.pers["summary"]["misc"] += value; self.pers["summary"]["match"] += value;
  457. self.pers["summary"]["xp"] += value;
  458. break;
  459. }
  460.  
  461. self setClientDvars(
  462. "player_summary_xp", self.pers["summary"]["xp"],
  463. "player_summary_score", self.pers["summary"]["score"],
  464. "player_summary_challenge", self.pers["summary"]["challenge"],
  465. "player_summary_match", self.pers["summary"]["match"],
  466. "player_summary_misc", self.pers["summary"]["misc"]
  467. );
  468. }
  469.  
  470. updateRank()
  471. {
  472. newRankId = self getRank();
  473. if ( newRankId == self.pers["rank"] )
  474. return false;
  475.  
  476. oldRank = self.pers["rank"];
  477. rankId = self.pers["rank"];
  478. self.pers["rank"] = newRankId;
  479.  
  480. while ( rankId <= newRankId )
  481. {
  482. self maps\mp\gametypes\_persistence::statSet( "rank", rankId );
  483. self maps\mp\gametypes\_persistence::statSet( "minxp", int(level.rankTable[rankId][2]) );
  484. self maps\mp\gametypes\_persistence::statSet( "maxxp", int(level.rankTable[rankId][7]) );
  485.  
  486. self setStat( 252, rankId );
  487.  
  488. self.setPromotion = true;
  489. if ( level.rankedMatch && level.gameEnded )
  490. self setClientDvar( "ui_lobbypopup", "promotion" );
  491.  
  492. unlockedWeapon = self getRankInfoUnlockWeapon( rankId ); if ( isDefined( unlockedWeapon ) && unlockedWeapon != "" )
  493. unlockWeapon( unlockedWeapon );
  494.  
  495. unlockedPerk = self getRankInfoUnlockPerk( rankId ); if ( isDefined( unlockedPerk ) && unlockedPerk != "" )
  496. unlockPerk( unlockedPerk );
  497.  
  498. unlockedChallenge = self getRankInfoUnlockChallenge( rankId );
  499. if ( isDefined( unlockedChallenge ) && unlockedChallenge != "" )
  500. unlockChallenge( unlockedChallenge );
  501.  
  502. unlockedAttachment = self getRankInfoUnlockAttachment( rankId ); if ( isDefined( unlockedAttachment ) && unlockedAttachment != "" )
  503. unlockAttachment( unlockedAttachment );
  504.  
  505. unlockedCamo = self getRankInfoUnlockCamo( rankId ); if ( isDefined( unlockedCamo ) && unlockedCamo != "" )
  506. unlockCamo( unlockedCamo );
  507.  
  508. unlockedFeature = self getRankInfoUnlockFeature( rankId ); if ( isDefined( unlockedFeature ) && unlockedFeature != "" )
  509. unlockFeature( unlockedFeature );
  510.  
  511. rankId++;
  512. }
  513. self logString( "promoted from " + oldRank + " to " + newRankId + " timeplayed: " + self maps\mp\gametypes\_persistence::statGet( "time_played_total" ) );
  514.  
  515. self setRank( newRankId );
  516.  
  517. return true;
  518. }
  519.  
  520. updateRankAnnounceHUD()
  521. {
  522. self endon("disconnect");
  523.  
  524. self notify("update_rank");
  525. self endon("update_rank");
  526.  
  527. team = self.pers["team"];
  528. if ( !isdefined( team ) )
  529. return;
  530.  
  531. self notify("reset_outcome");
  532. newRankName = self getRankInfoFull( self.pers["rank"] );
  533.  
  534. notifyData = spawnStruct();
  535.  
  536. notifyData.titleText = &"RANK_PROMOTED";
  537. notifyData.iconName = self getRankInfoIcon( self.pers["rank"], self.pers["prestige"] );
  538. notifyData.sound = "mp_level_up";
  539. notifyData.duration = 4.0;
  540.  
  541.  
  542. rank_char = level.rankTable[self.pers["rank"]][1];
  543. subRank = int(rank_char[rank_char.size-1]);
  544.  
  545. if ( subRank == 2 )
  546. {
  547. notifyData.textLabel = newRankName;
  548. notifyData.notifyText = &"RANK_ROMANI";
  549. notifyData.textIsString = true;
  550. }
  551. else if ( subRank == 3 )
  552. {
  553. notifyData.textLabel = newRankName;
  554. notifyData.notifyText = &"RANK_ROMANII";
  555. notifyData.textIsString = true;
  556. }
  557. else
  558. {
  559. notifyData.notifyText = newRankName;
  560. }
  561.  
  562. thread maps\mp\gametypes\_hud_message::notifyMessage( notifyData );
  563.  
  564. if ( subRank > 1 )
  565. return;
  566.  
  567. for ( i = 0; i < level.players.size; i++ )
  568. {
  569. player = level.players[i];
  570. playerteam = player.pers["team"];
  571. if ( isdefined( playerteam ) && player != self )
  572. {
  573. if ( playerteam == team )
  574. player iprintln( &"RANK_PLAYER_WAS_PROMOTED", self, newRankName );
  575. }
  576. }
  577. }
  578.  
  579. unlockPage( in_page )
  580. {
  581. if( in_page == 1 )
  582. {
  583. if( self.pers["unlocks"]["page"] == 0 )
  584. {
  585. self setClientDvar( "player_unlock_page", "1" );
  586. self.pers["unlocks"]["page"] = 1;
  587. }
  588. if( self.pers["unlocks"]["page"] == 2 )
  589. self setClientDvar( "player_unlock_page", "3" );
  590. }
  591. else if( in_page == 2 )
  592. {
  593. if( self.pers["unlocks"]["page"] == 0 )
  594. {
  595. self setClientDvar( "player_unlock_page", "2" );
  596. self.pers["unlocks"]["page"] = 2;
  597. }
  598. if( self.pers["unlocks"]["page"] == 1 )
  599. self setClientDvar( "player_unlock_page", "3" );
  600. }
  601. }
  602.  
  603. unlockWeapon( refString )
  604. {
  605. assert( isDefined( refString ) && refString != "" );
  606.  
  607. stat = int( tableLookup( "mp/statstable.csv", 4, refString, 1 ) );
  608.  
  609. assertEx( stat > 0, "statsTable refstring " + refString + " has invalid stat number: " + stat );
  610.  
  611. statVal = self getStat( stat );
  612. if ( statVal & 1 )
  613. return;
  614.  
  615. self setStat( stat, (statVal | 65537) );
  616.  
  617. self setStat( stat, 65537 ); self setClientDvar( "player_unlockWeapon" + self.pers["unlocks"]["weapon"], refString );
  618. self.pers["unlocks"]["weapon"]++;
  619. self setClientDvar( "player_unlockWeapons", self.pers["unlocks"]["weapon"] );
  620.  
  621. self unlockPage( 1 );
  622. }
  623.  
  624. unlockPerk( refString )
  625. {
  626. assert( isDefined( refString ) && refString != "" );
  627.  
  628. stat = int( tableLookup( "mp/statstable.csv", 4, refString, 1 ) );
  629.  
  630. if( self getStat( stat ) > 0 )
  631. return;
  632.  
  633. self setStat( stat, 2 ); self setClientDvar( "player_unlockPerk" + self.pers["unlocks"]["perk"], refString );
  634. self.pers["unlocks"]["perk"]++;
  635. self setClientDvar( "player_unlockPerks", self.pers["unlocks"]["perk"] );
  636.  
  637. self unlockPage( 2 );
  638. }
  639.  
  640. unlockCamo( refString )
  641. {
  642. assert( isDefined( refString ) && refString != "" );
  643.  
  644. Ref_Tok = strTok( refString, ";" );
  645. assertex( Ref_Tok.size > 0, "Camo unlock specified in datatable ["+refString+"] is incomplete or empty" );
  646.  
  647. for( i=0; i<Ref_Tok.size; i++ )
  648. unlockCamoSingular( Ref_Tok[i] );
  649. }
  650.  
  651. unlockCamoSingular( refString )
  652. {
  653. Tok = strTok( refString, " " );
  654. assertex( Tok.size == 2, "Camo unlock sepcified in datatable ["+refString+"] is invalid" );
  655.  
  656. baseWeapon = Tok[0];
  657. addon = Tok[1];
  658.  
  659. weaponStat = int( tableLookup( "mp/statstable.csv", 4, baseWeapon, 1 ) );
  660. addonMask = int( tableLookup( "mp/attachmenttable.csv", 4, addon, 10 ) );
  661.  
  662. if ( self getStat( weaponStat ) & addonMask )
  663. return;
  664.  
  665. setstatto = ( self getStat( weaponStat ) | addonMask ) | (addonMask<<16) | (1<<16);
  666. self setStat( weaponStat, setstatto );
  667.  
  668. self setClientDvar( "player_unlockCamo" + self.pers["unlocks"]["camo"] + "a", baseWeapon );
  669. self setClientDvar( "player_unlockCamo" + self.pers["unlocks"]["camo"] + "b", addon );
  670. self.pers["unlocks"]["camo"]++;
  671. self setClientDvar( "player_unlockCamos", self.pers["unlocks"]["camo"] );
  672.  
  673. self unlockPage( 1 );
  674. }
  675.  
  676. unlockAttachment( refString )
  677. {
  678. assert( isDefined( refString ) && refString != "" );
  679.  
  680. Ref_Tok = strTok( refString, ";" );
  681. assertex( Ref_Tok.size > 0, "Attachment unlock specified in datatable ["+refString+"] is incomplete or empty" );
  682.  
  683. for( i=0; i<Ref_Tok.size; i++ )
  684. unlockAttachmentSingular( Ref_Tok[i] );
  685. }
  686.  
  687. unlockAttachmentSingular( refString )
  688. {
  689. Tok = strTok( refString, " " );
  690. assertex( Tok.size == 2, "Attachment unlock sepcified in datatable ["+refString+"] is invalid" );
  691. assertex( Tok.size == 2, "Attachment unlock sepcified in datatable ["+refString+"] is invalid" );
  692.  
  693. baseWeapon = Tok[0];
  694. addon = Tok[1];
  695.  
  696. weaponStat = int( tableLookup( "mp/statstable.csv", 4, baseWeapon, 1 ) );
  697. addonMask = int( tableLookup( "mp/attachmenttable.csv", 4, addon, 10 ) );
  698.  
  699. if ( self getStat( weaponStat ) & addonMask )
  700. return;
  701.  
  702. setstatto = ( self getStat( weaponStat ) | addonMask ) | (addonMask<<16) | (1<<16);
  703. self setStat( weaponStat, setstatto );
  704.  
  705. self setClientDvar( "player_unlockAttachment" + self.pers["unlocks"]["attachment"] + "a", baseWeapon );
  706. self setClientDvar( "player_unlockAttachment" + self.pers["unlocks"]["attachment"] + "b", addon );
  707. self.pers["unlocks"]["attachment"]++;
  708. self setClientDvar( "player_unlockAttachments", self.pers["unlocks"]["attachment"] );
  709.  
  710. self unlockPage( 1 );
  711. }
  712.  
  713. unlockChallenge( refString )
  714. {
  715. assert( isDefined( refString ) && refString != "" );
  716.  
  717. Ref_Tok = strTok( refString, ";" );
  718. assertex( Ref_Tok.size > 0, "Camo unlock specified in datatable ["+refString+"] is incomplete or empty" );
  719.  
  720. for( i=0; i<Ref_Tok.size; i++ )
  721. {
  722. if ( getSubStr( Ref_Tok[i], 0, 3 ) == "ch_" )
  723. unlockChallengeSingular( Ref_Tok[i] );
  724. else
  725. unlockChallengeGroup( Ref_Tok[i] );
  726. }
  727. }
  728.  
  729. unlockChallengeSingular( refString )
  730. {
  731. assertEx( isDefined( level.challengeInfo[refString] ), "Challenge unlock "+refString+" does not exist." );
  732. tableName = "mp/challengetable_tier" + level.challengeInfo[refString]["tier"] + ".csv";
  733.  
  734. if ( self getStat( level.challengeInfo[refString]["stateid"] ) )
  735. return;
  736.  
  737. self setStat( level.challengeInfo[refString]["stateid"], 1 );
  738.  
  739. self setStat( 269 + level.challengeInfo[refString]["tier"], 2 );
  740. self.pers["unlocks"]["challenge"]++;
  741. self setClientDvar( "player_unlockchallenges", self.pers["unlocks"]["challenge"] );
  742.  
  743. self unlockPage( 2 );
  744. }
  745.  
  746. unlockChallengeGroup( refString )
  747. {
  748. tokens = strTok( refString, "_" );
  749. assertex( tokens.size > 0, "Challenge unlock specified in datatable ["+refString+"] is incomplete or empty" );
  750.  
  751. assert( tokens[0] == "tier" );
  752.  
  753. tierId = int( tokens[1] );
  754. assertEx( tierId > 0 && tierId <= level.numChallengeTiers, "invalid tier ID " + tierId );
  755.  
  756. groupId = "";
  757. if ( tokens.size > 2 )
  758. groupId = tokens[2];
  759.  
  760. challengeArray = getArrayKeys( level.challengeInfo );
  761.  
  762. unlocked = false;
  763. for ( index = 0; index < challengeArray.size; index++ )
  764. {
  765. challenge = level.challengeInfo[challengeArray[index]];
  766.  
  767. if ( challenge["tier"] != tierId )
  768. continue;
  769.  
  770. if ( challenge["group"] != groupId )
  771. continue;
  772.  
  773. if ( self getStat( challenge["stateid"] ) )
  774. continue;
  775.  
  776. unlocked = true;
  777. self setStat( challenge["stateid"], 1 );
  778.  
  779. self setStat( 269 + challenge["tier"], 2 ); }
  780.  
  781. if ( !unlocked )
  782. return;
  783.  
  784. self.pers["unlocks"]["challenge"]++;
  785. self setClientDvar( "player_unlockchallenges", self.pers["unlocks"]["challenge"] );
  786. self unlockPage( 2 );
  787. }
  788.  
  789. unlockFeature( refString )
  790. {
  791. assert( isDefined( refString ) && refString != "" );
  792.  
  793. stat = int( tableLookup( "mp/statstable.csv", 4, refString, 1 ) );
  794.  
  795. if( self getStat( stat ) > 0 )
  796. return;
  797.  
  798. if ( refString == "feature_cac" )
  799. self setStat( 200, 1 );
  800.  
  801. self setStat( stat, 2 );
  802. if ( refString == "feature_challenges" )
  803. {
  804. self unlockPage( 2 );
  805. return;
  806. }
  807.  
  808. self setClientDvar( "player_unlockfeature"+self.pers["unlocks"]["feature"], tableLookup( "mp/statstable.csv", 4, refString, 3 ) );
  809. self.pers["unlocks"]["feature"]++;
  810. self setClientDvar( "player_unlockfeatures", self.pers["unlocks"]["feature"] );
  811.  
  812. self unlockPage( 2 );
  813. }
  814.  
  815. updateChallenges()
  816. {
  817. self.challengeData = [];
  818. for ( i = 1; i <= level.numChallengeTiers; i++ )
  819. {
  820. tableName = "mp/challengetable_tier"+i+".csv";
  821.  
  822. idx = 1;
  823. for( idx = 1; isdefined( tableLookup( tableName, 0, idx, 0 ) ) && tableLookup( tableName, 0, idx, 0 ) != ""; idx++ )
  824. {
  825. stat_num = tableLookup( tableName, 0, idx, 2 );
  826. if( isdefined( stat_num ) && stat_num != "" )
  827. {
  828. statVal = self getStat( int( stat_num ) );
  829.  
  830. refString = tableLookup( tableName, 0, idx, 7 );
  831. if ( statVal )
  832. self.challengeData[refString] = statVal;
  833. }
  834. }
  835. }
  836. }
  837.  
  838. buildChallegeInfo()
  839. {
  840. level.challengeInfo = [];
  841.  
  842. for ( i = 1; i <= level.numChallengeTiers; i++ )
  843. {
  844. tableName = "mp/challengetable_tier"+i+".csv";
  845.  
  846. baseRef = "";
  847. for( idx = 1; isdefined( tableLookup( tableName, 0, idx, 0 ) ) && tableLookup( tableName, 0, idx, 0 ) != ""; idx++ )
  848. {
  849. stat_num = tableLookup( tableName, 0, idx, 2 );
  850. refString = tableLookup( tableName, 0, idx, 7 );
  851.  
  852. level.challengeInfo[refString] = [];
  853. level.challengeInfo[refString]["tier"] = i;
  854. level.challengeInfo[refString]["stateid"] = int( tableLookup( tableName, 0, idx, 2 ) );
  855. level.challengeInfo[refString]["statid"] = int( tableLookup( tableName, 0, idx, 3 ) );
  856. level.challengeInfo[refString]["maxval"] = int( tableLookup( tableName, 0, idx, 4 ) );
  857. level.challengeInfo[refString]["minval"] = int( tableLookup( tableName, 0, idx, 5 ) );
  858. level.challengeInfo[refString]["name"] = tableLookupIString( tableName, 0, idx, 8 );
  859. level.challengeInfo[refString]["desc"] = tableLookupIString( tableName, 0, idx, 9 );
  860. level.challengeInfo[refString]["reward"] = int( tableLookup( tableName, 0, idx, 10 ) );
  861. level.challengeInfo[refString]["camo"] = tableLookup( tableName, 0, idx, 12 );
  862. level.challengeInfo[refString]["attachment"] = tableLookup( tableName, 0, idx, 13 );
  863. level.challengeInfo[refString]["group"] = tableLookup( tableName, 0, idx, 14 );
  864.  
  865. precacheString( level.challengeInfo[refString]["name"] );
  866.  
  867. if ( !int( level.challengeInfo[refString]["stateid"] ) )
  868. {
  869. level.challengeInfo[baseRef]["levels"]++;
  870. level.challengeInfo[refString]["stateid"] = level.challengeInfo[baseRef]["stateid"];
  871. level.challengeInfo[refString]["level"] = level.challengeInfo[baseRef]["levels"];
  872. }
  873. else
  874. {
  875. level.challengeInfo[refString]["levels"] = 1;
  876. level.challengeInfo[refString]["level"] = 1;
  877. baseRef = refString;
  878. }
  879. }
  880. }
  881. }
  882.  
  883.  
  884. endGameUpdate()
  885. {
  886. player = self;
  887. }
  888.  
  889. updateRankScoreHUD( amount )
  890. {
  891. self endon( "disconnect" );
  892. self endon( "joined_team" );
  893. self endon( "joined_spectators" );
  894.  
  895. if ( amount == 0 )
  896. return;
  897.  
  898. self notify( "update_score" );
  899. self endon( "update_score" );
  900.  
  901. self.rankUpdateTotal += amount;
  902.  
  903. wait ( 0.05 );
  904.  
  905. if( isDefined( self.hud_rankscroreupdate ) )
  906. {
  907. if ( self.rankUpdateTotal < 0 )
  908. {
  909. self.hud_rankscroreupdate.label = &"";
  910. self.hud_rankscroreupdate.color = (1,0,0);
  911. }
  912. else
  913. {
  914. self.hud_rankscroreupdate.label = &"MP_PLUS";
  915. self.hud_rankscroreupdate.color = (1,1,0.5);
  916. }
  917.  
  918. self.hud_rankscroreupdate setValue(self.rankUpdateTotal);
  919. self.hud_rankscroreupdate.alpha = 0.85;
  920. self.hud_rankscroreupdate thread maps\mp\gametypes\_hud::fontPulse( self );
  921.  
  922. wait 1;
  923. self.hud_rankscroreupdate fadeOverTime( 0.75 );
  924. self.hud_rankscroreupdate.alpha = 0;
  925.  
  926. self.rankUpdateTotal = 0;
  927. }
  928. }
  929.  
  930. removeRankHUD()
  931. {
  932. if(isDefined(self.hud_rankscroreupdate))
  933. self.hud_rankscroreupdate.alpha = 0;
  934. }
  935.  
  936. getRank()
  937. {
  938. rankXp = self.pers["rankxp"];
  939. rankId = self.pers["rank"];
  940.  
  941. if ( rankXp < (getRankInfoMinXP( rankId ) + getRankInfoXPAmt( rankId )) )
  942. return rankId;
  943. else
  944. return self getRankForXp( rankXp );
  945. }
  946.  
  947. getRankForXp( xpVal )
  948. {
  949. rankId = 0;
  950. rankName = level.rankTable[rankId][1];
  951. assert( isDefined( rankName ) );
  952.  
  953. while ( isDefined( rankName ) && rankName != "" )
  954. {
  955. if ( xpVal < getRankInfoMinXP( rankId ) + getRankInfoXPAmt( rankId ) )
  956. return rankId;
  957.  
  958. rankId++;
  959. if ( isDefined( level.rankTable[rankId] ) )
  960. rankName = level.rankTable[rankId][1];
  961. else
  962. rankName = undefined;
  963. }
  964.  
  965. rankId--;
  966. return rankId;
  967. }
  968.  
  969. getSPM()
  970. {
  971. rankLevel = (self getRank() % 61) + 1;
  972. return 3 + (rankLevel * 0.5);
  973. }
  974.  
  975. getPrestigeLevel()
  976. {
  977. return self maps\mp\gametypes\_persistence::statGet( "plevel" );
  978. }
  979.  
  980. getRankXP()
  981. {
  982. return self.pers["rankxp"];
  983. }
  984.  
  985. incRankXP( amount )
  986. {
  987. if ( !level.rankedMatch )
  988. return;
  989.  
  990. xp = self getRankXP();
  991. newXp = (xp + amount);
  992.  
  993. if ( self.pers["rank"] == level.maxRank && newXp >= getRankInfoMaxXP( level.maxRank ) )
  994. newXp = getRankInfoMaxXP( level.maxRank );
  995.  
  996. self.pers["rankxp"] = newXp;
  997. }
  998.  
  999. syncXPStat()
  1000. {
  1001. xp = self getRankXP();
  1002.  
  1003. self maps\mp\gametypes\_persistence::statSet( "rankxp", xp );
  1004. }
Add Comment
Please, Sign In to add comment