JoBoz

Mod

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