Advertisement
JoBoz

_rank.gsc

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