JoBoz

Untitled

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