JoBoz

_rank.gsc

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