Advertisement
Guest User

_rank.gsc

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