Advertisement
Guest User

Anti-Camp

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