Advertisement
Guest User

Clean _rank.gsc MW2

a guest
Sep 12th, 2010
942
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.47 KB | None | 0 0
  1. #include common_scripts\utility;
  2. #include maps\mp\_utility;
  3. #include maps\mp\gametypes\_hud_util;
  4.  
  5.  
  6. init()
  7. {
  8. level.scoreInfo = [];
  9. level.xpScale = getDvarInt( "scr_xpscale" );
  10.  
  11. if ( level.xpScale > 4 || level.xpScale < 0)
  12. exitLevel( false );
  13.  
  14. level.xpScale = min( level.xpScale, 4 );
  15. level.xpScale = max( level.xpScale, 0 );
  16.  
  17. level.rankTable = [];
  18.  
  19. precacheShader("white");
  20.  
  21. precacheString( &"RANK_PLAYER_WAS_PROMOTED_N" );
  22. precacheString( &"RANK_PLAYER_WAS_PROMOTED" );
  23. precacheString( &"RANK_PROMOTED" );
  24. precacheString( &"MP_PLUS" );
  25. precacheString( &"RANK_ROMANI" );
  26. precacheString( &"RANK_ROMANII" );
  27. precacheString( &"RANK_ROMANIII" );
  28.  
  29. if ( level.teamBased )
  30. {
  31. registerScoreInfo( "kill", 100 );
  32. registerScoreInfo( "headshot", 100 );
  33. registerScoreInfo( "assist", 20 );
  34. registerScoreInfo( "suicide", 0 );
  35. registerScoreInfo( "teamkill", 0 );
  36. }
  37. else
  38. {
  39. registerScoreInfo( "kill", 50 );
  40. registerScoreInfo( "headshot", 50 );
  41. registerScoreInfo( "assist", 0 );
  42. registerScoreInfo( "suicide", 0 );
  43. registerScoreInfo( "teamkill", 0 );
  44. }
  45.  
  46. registerScoreInfo( "win", 1 );
  47. registerScoreInfo( "loss", 0.5 );
  48. registerScoreInfo( "tie", 0.75 );
  49. registerScoreInfo( "capture", 300 );
  50. registerScoreInfo( "defend", 300 );
  51.  
  52. registerScoreInfo( "challenge", 2500 );
  53.  
  54. level.maxRank = int(tableLookup( "mp/rankTable.csv", 0, "maxrank", 1 ));
  55. level.maxPrestige = int(tableLookup( "mp/rankIconTable.csv", 0, "maxprestige", 1 ));
  56.  
  57. pId = 0;
  58. rId = 0;
  59. for ( pId = 0; pId <= level.maxPrestige; pId++ )
  60. {
  61. for ( rId = 0; rId <= level.maxRank; rId++ )
  62. precacheShader( tableLookup( "mp/rankIconTable.csv", 0, rId, pId+1 ) );
  63. }
  64.  
  65. rankId = 0;
  66. rankName = tableLookup( "mp/ranktable.csv", 0, rankId, 1 );
  67. assert( isDefined( rankName ) && rankName != "" );
  68.  
  69. while ( isDefined( rankName ) && rankName != "" )
  70. {
  71. level.rankTable[rankId][1] = tableLookup( "mp/ranktable.csv", 0, rankId, 1 );
  72. level.rankTable[rankId][2] = tableLookup( "mp/ranktable.csv", 0, rankId, 2 );
  73. level.rankTable[rankId][3] = tableLookup( "mp/ranktable.csv", 0, rankId, 3 );
  74. level.rankTable[rankId][7] = tableLookup( "mp/ranktable.csv", 0, rankId, 7 );
  75.  
  76. precacheString( tableLookupIString( "mp/ranktable.csv", 0, rankId, 16 ) );
  77.  
  78. rankId++;
  79. rankName = tableLookup( "mp/ranktable.csv", 0, rankId, 1 );
  80. }
  81.  
  82. maps\mp\gametypes\_missions::buildChallegeInfo();
  83.  
  84. level thread patientZeroWaiter();
  85.  
  86. level thread onPlayerConnect();
  87. }
  88.  
  89. patientZeroWaiter()
  90. {
  91. level endon( "game_ended" );
  92.  
  93. while ( !isDefined( level.players ) || !level.players.size )
  94. wait ( 0.05 );
  95.  
  96. if ( !matchMakingGame() )
  97. {
  98. if ( (getDvar( "mapname" ) == "mp_rust" && randomInt( 1000 ) == 999) )
  99. level.patientZeroName = level.players[0].name;
  100. }
  101. else
  102. {
  103. if ( getDvar( "scr_patientZero" ) != "" )
  104. level.patientZeroName = getDvar( "scr_patientZero" );
  105. }
  106. }
  107.  
  108. isRegisteredEvent( type )
  109. {
  110. if ( isDefined( level.scoreInfo[type] ) )
  111. return true;
  112. else
  113. return false;
  114. }
  115.  
  116.  
  117. registerScoreInfo( type, value )
  118. {
  119. level.scoreInfo[type]["value"] = value;
  120. }
  121.  
  122.  
  123. getScoreInfoValue( type )
  124. {
  125. overrideDvar = "scr_" + level.gameType + "_score_" + type;
  126. if ( getDvar( overrideDvar ) != "" )
  127. return getDvarInt( overrideDvar );
  128. else
  129. return ( level.scoreInfo[type]["value"] );
  130. }
  131.  
  132.  
  133. getScoreInfoLabel( type )
  134. {
  135. return ( level.scoreInfo[type]["label"] );
  136. }
  137.  
  138.  
  139. getRankInfoMinXP( rankId )
  140. {
  141. return int(level.rankTable[rankId][2]);
  142. }
  143.  
  144.  
  145. getRankInfoXPAmt( rankId )
  146. {
  147. return int(level.rankTable[rankId][3]);
  148. }
  149.  
  150.  
  151. getRankInfoMaxXp( rankId )
  152. {
  153. return int(level.rankTable[rankId][7]);
  154. }
  155.  
  156.  
  157. getRankInfoFull( rankId )
  158. {
  159. return tableLookupIString( "mp/ranktable.csv", 0, rankId, 16 );
  160. }
  161.  
  162.  
  163. getRankInfoIcon( rankId, prestigeId )
  164. {
  165. return tableLookup( "mp/rankIconTable.csv", 0, rankId, prestigeId+1 );
  166. }
  167.  
  168. getRankInfoLevel( rankId )
  169. {
  170. return int( tableLookup( "mp/ranktable.csv", 0, rankId, 13 ) );
  171. }
  172.  
  173.  
  174. onPlayerConnect()
  175. {
  176. for(;;)
  177. {
  178. level waittill( "connected", player );
  179.  
  180. /#
  181. if ( getDvarInt( "scr_forceSequence" ) )
  182. player setPlayerData( "experience", 145499 );
  183. #/
  184. player.pers["rankxp"] = player maps\mp\gametypes\_persistence::statGet( "experience" );
  185. if ( player.pers["rankxp"] < 0 ) // paranoid defensive
  186. player.pers["rankxp"] = 0;
  187.  
  188. rankId = player getRankForXp( player getRankXP() );
  189. player.pers[ "rank" ] = rankId;
  190. player.pers[ "participation" ] = 0;
  191.  
  192. player.xpUpdateTotal = 0;
  193. player.bonusUpdateTotal = 0;
  194.  
  195. prestige = player getPrestigeLevel();
  196. player setRank( rankId, prestige );
  197. player.pers["prestige"] = prestige;
  198.  
  199. player.postGamePromotion = false;
  200. if ( !isDefined( player.pers["postGameChallenges"] ) )
  201. {
  202. player setClientDvars( "ui_challenge_1_ref", "",
  203. "ui_challenge_2_ref", "",
  204. "ui_challenge_3_ref", "",
  205. "ui_challenge_4_ref", "",
  206. "ui_challenge_5_ref", "",
  207. "ui_challenge_6_ref", "",
  208. "ui_challenge_7_ref", ""
  209. );
  210. }
  211.  
  212. player setClientDvar( "ui_promotion", 0 );
  213.  
  214. if ( !isDefined( player.pers["summary"] ) )
  215. {
  216. player.pers["summary"] = [];
  217. player.pers["summary"]["xp"] = 0;
  218. player.pers["summary"]["score"] = 0;
  219. player.pers["summary"]["challenge"] = 0;
  220. player.pers["summary"]["match"] = 0;
  221. player.pers["summary"]["misc"] = 0;
  222.  
  223. // resetting game summary dvars
  224. player setClientDvar( "player_summary_xp", "0" );
  225. player setClientDvar( "player_summary_score", "0" );
  226. player setClientDvar( "player_summary_challenge", "0" );
  227. player setClientDvar( "player_summary_match", "0" );
  228. player setClientDvar( "player_summary_misc", "0" );
  229. }
  230.  
  231.  
  232. // resetting summary vars
  233.  
  234. player setClientDvar( "ui_opensummary", 0 );
  235.  
  236. player maps\mp\gametypes\_missions::updateChallenges();
  237. player.explosiveKills[0] = 0;
  238. player.xpGains = [];
  239.  
  240. player.hud_scorePopup = newClientHudElem( player );
  241. player.hud_scorePopup.horzAlign = "center";
  242. player.hud_scorePopup.vertAlign = "middle";
  243. player.hud_scorePopup.alignX = "center";
  244. player.hud_scorePopup.alignY = "middle";
  245. player.hud_scorePopup.x = 0;
  246. if ( level.splitScreen )
  247. player.hud_scorePopup.y = -40;
  248. else
  249. player.hud_scorePopup.y = -60;
  250. player.hud_scorePopup.font = "hudbig";
  251. player.hud_scorePopup.fontscale = 0.75;
  252. player.hud_scorePopup.archived = false;
  253. player.hud_scorePopup.color = (0.5,0.5,0.5);
  254. player.hud_scorePopup.sort = 10000;
  255. player.hud_scorePopup maps\mp\gametypes\_hud::fontPulseInit( 3.0 );
  256.  
  257. player thread onPlayerSpawned();
  258. player thread onJoinedTeam();
  259. player thread onJoinedSpectators();
  260. }
  261. }
  262.  
  263.  
  264. onJoinedTeam()
  265. {
  266. self endon("disconnect");
  267.  
  268. for(;;)
  269. {
  270. self waittill( "joined_team" );
  271. self thread removeRankHUD();
  272. }
  273. }
  274.  
  275.  
  276. onJoinedSpectators()
  277. {
  278. self endon("disconnect");
  279.  
  280. for(;;)
  281. {
  282. self waittill( "joined_spectators" );
  283. self thread removeRankHUD();
  284. }
  285. }
  286.  
  287.  
  288. onPlayerSpawned()
  289. {
  290. self endon("disconnect");
  291.  
  292. for(;;)
  293. {
  294. self waittill("spawned_player");
  295. }
  296. }
  297.  
  298.  
  299. roundUp( floatVal )
  300. {
  301. if ( int( floatVal ) != floatVal )
  302. return int( floatVal+1 );
  303. else
  304. return int( floatVal );
  305. }
  306.  
  307.  
  308. giveRankXP( type, value )
  309. {
  310. self endon("disconnect");
  311.  
  312. lootType = "none";
  313.  
  314. if ( !self rankingEnabled() )
  315. return;
  316.  
  317. if ( level.teamBased && (!level.teamCount["allies"] || !level.teamCount["axis"]) )
  318. return;
  319. else if ( !level.teamBased && (level.teamCount["allies"] + level.teamCount["axis"] < 2) )
  320. return;
  321.  
  322. if ( !isDefined( value ) )
  323. value = getScoreInfoValue( type );
  324.  
  325. if ( !isDefined( self.xpGains[type] ) )
  326. self.xpGains[type] = 0;
  327.  
  328. momentumBonus = 0;
  329. gotRestXP = false;
  330.  
  331. switch( type )
  332. {
  333. case "kill":
  334. case "headshot":
  335. case "shield_damage":
  336. value *= self.xpScaler;
  337. case "assist":
  338. case "suicide":
  339. case "teamkill":
  340. case "capture":
  341. case "defend":
  342. case "return":
  343. case "pickup":
  344. case "assault":
  345. case "plant":
  346. case "destroy":
  347. case "save":
  348. case "defuse":
  349. if ( getGametypeNumLives() > 0 )
  350. {
  351. multiplier = max(1,int( 10/getGametypeNumLives() ));
  352. value = int(value * multiplier);
  353. }
  354.  
  355. value = int( value * level.xpScale );
  356.  
  357. restXPAwarded = getRestXPAward( value );
  358. value += restXPAwarded;
  359. if ( restXPAwarded > 0 )
  360. {
  361. if ( isLastRestXPAward( value ) )
  362. thread maps\mp\gametypes\_hud_message::splashNotify( "rested_done" );
  363.  
  364. gotRestXP = true;
  365. }
  366. break;
  367. }
  368.  
  369. if ( !gotRestXP )
  370. {
  371. // if we didn't get rest XP for this type, we push the rest XP goal ahead so we didn't waste it
  372. if ( self getPlayerData( "restXPGoal" ) > self getRankXP() )
  373. self setPlayerData( "restXPGoal", self getPlayerData( "restXPGoal" ) + value );
  374. }
  375.  
  376. oldxp = self getRankXP();
  377. self.xpGains[type] += value;
  378.  
  379. self incRankXP( value );
  380.  
  381. if ( self rankingEnabled() && updateRank( oldxp ) )
  382. self thread updateRankAnnounceHUD();
  383.  
  384. // Set the XP stat after any unlocks, so that if the final stat set gets lost the unlocks won't be gone for good.
  385. self syncXPStat();
  386.  
  387. if ( !level.hardcoreMode )
  388. {
  389. if ( type == "teamkill" )
  390. {
  391. self thread scorePopup( 0 - getScoreInfoValue( "kill" ), 0, (1,0,0), 0 );
  392. }
  393. else
  394. {
  395. color = (1,1,0.5);
  396. if ( gotRestXP )
  397. color = (1,.65,0);
  398. self thread scorePopup( value, momentumBonus, color, 0 );
  399. }
  400. }
  401.  
  402. switch( type )
  403. {
  404. case "kill":
  405. case "headshot":
  406. case "suicide":
  407. case "teamkill":
  408. case "assist":
  409. case "capture":
  410. case "defend":
  411. case "return":
  412. case "pickup":
  413. case "assault":
  414. case "plant":
  415. case "defuse":
  416. self.pers["summary"]["score"] += value;
  417. self.pers["summary"]["xp"] += value;
  418. break;
  419.  
  420. case "win":
  421. case "loss":
  422. case "tie":
  423. self.pers["summary"]["match"] += value;
  424. self.pers["summary"]["xp"] += value;
  425. break;
  426.  
  427. case "challenge":
  428. self.pers["summary"]["challenge"] += value;
  429. self.pers["summary"]["xp"] += value;
  430. break;
  431.  
  432. default:
  433. self.pers["summary"]["misc"] += value; //keeps track of ungrouped match xp reward
  434. self.pers["summary"]["match"] += value;
  435. self.pers["summary"]["xp"] += value;
  436. break;
  437. }
  438. }
  439.  
  440. updateRank( oldxp )
  441. {
  442. newRankId = self getRank();
  443. if ( newRankId == self.pers["rank"] )
  444. return false;
  445.  
  446. oldRank = self.pers["rank"];
  447. rankId = self.pers["rank"];
  448. self.pers["rank"] = newRankId;
  449.  
  450. //self logString( "promoted from " + oldRank + " to " + newRankId + " timeplayed: " + self maps\mp\gametypes\_persistence::statGet( "timePlayedTotal" ) );
  451. println( "promoted " + self.name + " from rank " + oldRank + " to " + newRankId + ". Experience went from " + oldxp + " to " + self getRankXP() + "." );
  452.  
  453. self setRank( newRankId );
  454.  
  455. return true;
  456. }
  457.  
  458.  
  459. updateRankAnnounceHUD()
  460. {
  461. self endon("disconnect");
  462.  
  463. self notify("update_rank");
  464. self endon("update_rank");
  465.  
  466. team = self.pers["team"];
  467. if ( !isdefined( team ) )
  468. return;
  469.  
  470. // give challenges and other XP a chance to process
  471. // also ensure that post game promotions happen asap
  472. if ( !levelFlag( "game_over" ) )
  473. level waittill_notify_or_timeout( "game_over", 0.25 );
  474.  
  475.  
  476. newRankName = self getRankInfoFull( self.pers["rank"] );
  477. rank_char = level.rankTable[self.pers["rank"]][1];
  478. subRank = int(rank_char[rank_char.size-1]);
  479.  
  480. thread maps\mp\gametypes\_hud_message::promotionSplashNotify();
  481.  
  482. if ( subRank > 1 )
  483. return;
  484.  
  485. for ( i = 0; i < level.players.size; i++ )
  486. {
  487. player = level.players[i];
  488. playerteam = player.pers["team"];
  489. if ( isdefined( playerteam ) && player != self )
  490. {
  491. if ( playerteam == team )
  492. player iPrintLn( &"RANK_PLAYER_WAS_PROMOTED", self, newRankName );
  493. }
  494. }
  495. }
  496.  
  497.  
  498. endGameUpdate()
  499. {
  500. player = self;
  501. }
  502.  
  503.  
  504. scorePopup( amount, bonus, hudColor, glowAlpha )
  505. {
  506. self endon( "disconnect" );
  507. self endon( "joined_team" );
  508. self endon( "joined_spectators" );
  509.  
  510. if ( amount == 0 )
  511. return;
  512.  
  513. self notify( "scorePopup" );
  514. self endon( "scorePopup" );
  515.  
  516. self.xpUpdateTotal += amount;
  517. self.bonusUpdateTotal += bonus;
  518.  
  519. wait ( 0.05 );
  520.  
  521. if ( self.xpUpdateTotal < 0 )
  522. self.hud_scorePopup.label = &"";
  523. else
  524. self.hud_scorePopup.label = &"MP_PLUS";
  525.  
  526. self.hud_scorePopup.color = hudColor;
  527. self.hud_scorePopup.glowColor = hudColor;
  528. self.hud_scorePopup.glowAlpha = glowAlpha;
  529.  
  530. self.hud_scorePopup setValue(self.xpUpdateTotal);
  531. self.hud_scorePopup.alpha = 0.85;
  532. self.hud_scorePopup thread maps\mp\gametypes\_hud::fontPulse( self );
  533.  
  534. increment = max( int( self.bonusUpdateTotal / 20 ), 1 );
  535.  
  536. if ( self.bonusUpdateTotal )
  537. {
  538. while ( self.bonusUpdateTotal > 0 )
  539. {
  540. self.xpUpdateTotal += min( self.bonusUpdateTotal, increment );
  541. self.bonusUpdateTotal -= min( self.bonusUpdateTotal, increment );
  542.  
  543. self.hud_scorePopup setValue( self.xpUpdateTotal );
  544.  
  545. wait ( 0.05 );
  546. }
  547. }
  548. else
  549. {
  550. wait ( 1.0 );
  551. }
  552.  
  553. self.hud_scorePopup fadeOverTime( 0.75 );
  554. self.hud_scorePopup.alpha = 0;
  555.  
  556. self.xpUpdateTotal = 0;
  557. }
  558.  
  559. removeRankHUD()
  560. {
  561. self.hud_scorePopup.alpha = 0;
  562. }
  563.  
  564. getRank()
  565. {
  566. rankXp = self.pers["rankxp"];
  567. rankId = self.pers["rank"];
  568.  
  569. if ( rankXp < (getRankInfoMinXP( rankId ) + getRankInfoXPAmt( rankId )) )
  570. return rankId;
  571. else
  572. return self getRankForXp( rankXp );
  573. }
  574.  
  575.  
  576. levelForExperience( experience )
  577. {
  578. return getRankForXP( experience );
  579. }
  580.  
  581.  
  582. getRankForXp( xpVal )
  583. {
  584. rankId = 0;
  585. rankName = level.rankTable[rankId][1];
  586. assert( isDefined( rankName ) );
  587.  
  588. while ( isDefined( rankName ) && rankName != "" )
  589. {
  590. if ( xpVal < getRankInfoMinXP( rankId ) + getRankInfoXPAmt( rankId ) )
  591. return rankId;
  592.  
  593. rankId++;
  594. if ( isDefined( level.rankTable[rankId] ) )
  595. rankName = level.rankTable[rankId][1];
  596. else
  597. rankName = undefined;
  598. }
  599.  
  600. rankId--;
  601. return rankId;
  602. }
  603.  
  604.  
  605. getSPM()
  606. {
  607. rankLevel = self getRank() + 1;
  608. return (3 + (rankLevel * 0.5))*10;
  609. }
  610.  
  611. getPrestigeLevel()
  612. {
  613. return self maps\mp\gametypes\_persistence::statGet( "prestige" );
  614. }
  615.  
  616. getRankXP()
  617. {
  618. return self.pers["rankxp"];
  619. }
  620.  
  621. incRankXP( amount )
  622. {
  623. if ( !self rankingEnabled() )
  624. return;
  625.  
  626. if ( isDefined( self.isCheater ) )
  627. return;
  628.  
  629. xp = self getRankXP();
  630. newXp = (int( min( xp, getRankInfoMaxXP( level.maxRank ) ) ) + amount);
  631.  
  632. if ( self.pers["rank"] == level.maxRank && newXp >= getRankInfoMaxXP( level.maxRank ) )
  633. newXp = getRankInfoMaxXP( level.maxRank );
  634.  
  635. self.pers["rankxp"] = newXp;
  636. }
  637.  
  638. getRestXPAward( baseXP )
  639. {
  640. if ( !getdvarint( "scr_restxp_enable" ) )
  641. return 0;
  642.  
  643. restXPAwardRate = getDvarFloat( "scr_restxp_restedAwardScale" ); // as a fraction of base xp
  644.  
  645. wantGiveRestXP = int(baseXP * restXPAwardRate);
  646. mayGiveRestXP = self getPlayerData( "restXPGoal" ) - self getRankXP();
  647.  
  648. if ( mayGiveRestXP <= 0 )
  649. return 0;
  650.  
  651. // we don't care about giving more rest XP than we have; we just want it to always be X2
  652. //if ( wantGiveRestXP > mayGiveRestXP )
  653. // return mayGiveRestXP;
  654.  
  655. return wantGiveRestXP;
  656. }
  657.  
  658.  
  659. isLastRestXPAward( baseXP )
  660. {
  661. if ( !getdvarint( "scr_restxp_enable" ) )
  662. return false;
  663.  
  664. restXPAwardRate = getDvarFloat( "scr_restxp_restedAwardScale" ); // as a fraction of base xp
  665.  
  666. wantGiveRestXP = int(baseXP * restXPAwardRate);
  667. mayGiveRestXP = self getPlayerData( "restXPGoal" ) - self getRankXP();
  668.  
  669. if ( mayGiveRestXP <= 0 )
  670. return false;
  671.  
  672. if ( wantGiveRestXP >= mayGiveRestXP )
  673. return true;
  674.  
  675. return false;
  676. }
  677.  
  678. syncXPStat()
  679. {
  680. if ( level.xpScale > 4 || level.xpScale <= 0)
  681. exitLevel( false );
  682.  
  683. xp = self getRankXP();
  684.  
  685. self maps\mp\gametypes\_persistence::statSet( "experience", xp );
  686. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement