JoBoz

So learn GSC....

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