CSHARP 201
Htf.gsc Guest on 18th April 2021 07:31:29 PM
  1. #include maps\mp\_utility;
  2. #include maps\mp\gametypes\_hud_util;
  3. #include maps\mp\gametypes\_globallogic;
  4. /*
  5.     HTF 4 COD4 by Tally
  6.     12/26/2007
  7.     Hold the Flag - X4 mod compatible version
  8.     Author : La Truffe
  9.     Credits : Bell (AWE mod, HTF 1.0)
  10.    
  11. */
  12.  
  13. main()
  14. {
  15.     if(getdvar("mapname") == "mp_background")
  16.         return;
  17.    
  18.     maps\mp\gametypes\_setupmaps::init();
  19.     maps\mp\gametypes\_globallogic::init();
  20.     maps\mp\gametypes\_callbacksetup::SetupCallbacks();
  21.     maps\mp\gametypes\_globallogic::SetupCallbacks();
  22.     if(level.ex_blackscreen) maps\mp\gametypes\_blackscreen::init();
  23.    
  24.     maps\mp\gametypes\_globallogic::registerRoundSwitchDvar( "htf", 2, 0, 99);
  25.     maps\mp\gametypes\_globallogic::registerTimeLimitDvar( "htf", 5, 0, 1440 );
  26.     maps\mp\gametypes\_globallogic::registerScoreLimitDvar( "htf", 500, 0, 5000 );
  27.     maps\mp\gametypes\_globallogic::registerRoundLimitDvar( "htf", 1, 0, 99 );
  28.     maps\mp\gametypes\_globallogic::registerNumLivesDvar( "htf", 0, 0, 99 );
  29.    
  30.     level.mode                          = extreme\_ex_utils::dvardef("scr_htf_mode", 2, 0, 3, "int");
  31.     level.holdtime                      = extreme\_ex_utils::dvardef("scr_htf_holdtime", 90, 1, 99999, "int");
  32.     level.heavyflag                     = extreme\_ex_utils::dvardef("scr_htf_heavyflag", 1, 0, 1, "int");
  33.     level.flagrecovertime               = extreme\_ex_utils::dvardef("scr_htf_returnflag_delay", 60, 0, 140, "int");
  34.     level.randomflagspawns              = extreme\_ex_utils::dvardef("scr_htf_randomflagspawns", 2, 0, 2, "int");
  35.     level.flagspawndelay                = extreme\_ex_utils::dvardef("scr_htf_flagspawndelay", 15, 0, 9999, "int");
  36.     level.spawndistance                 = extreme\_ex_utils::dvardef("scr_htf_spawndistance", 1000, 1, 999999, "int");
  37.     level.spawndistancemax              = extreme\_ex_utils::dvardef("scr_htf_spawndistance_max", 3000, level.spawndistance, 99999, "int");
  38.     level.flagprotectiondistance        = extreme\_ex_utils::dvardef("scr_htf_flagprotectiondistance", 800, 1, 999999, "int");
  39.     level.PointsForKillingFlagCarrier   = extreme\_ex_utils::dvardef ("scr_htf_pointsforkillingflagcarrier", 2, 0, 100, "int");
  40.     level.PointsForAssistingFlagCarrier = extreme\_ex_utils::dvardef ("scr_htf_pointsforassistingflagcarrier", 1, 0, 100, "int");
  41.     level.PointsForHoldingFlag          = extreme\_ex_utils::dvardef ("scr_htf_pointsforholdingflag", 2, 0, 100, "int");
  42.     level.PointsForStealingFlag         = extreme\_ex_utils::dvardef ("scr_htf_pointsforstealingflag", 3, 0, 100, "int");
  43.  
  44.     level.teamBased = true;
  45.     level.overrideTeamScore = true;
  46.     level.onStartGameType = ::onStartGameType;
  47.     level.onSpawnPlayer = ::onSpawnPlayer;
  48.     level.onPlayerKilled = ::onPlayerKilled;
  49.     level.onPlayerDisconnect = ::onPlayerDisconnect;
  50.    
  51.     level.team["allies"] = 0;
  52.     level.team["axis"] = 0;
  53.     level.hasspawned["axis"] = false;
  54.     level.hasspawned["allies"] = false;
  55.     level.hasspawned["flag"] = false;
  56.     level.teamholdtime["axis"] = 0;
  57.     level.teamholdtime["allies"] = 0;
  58.     level.oldteamholdtime["allies"] = level.teamholdtime["allies"];
  59.     level.oldteamholdtime["axis"] = level.teamholdtime["axis"];
  60.     level.allies_cap_count = 0;
  61.     level.axis_cap_count =0;
  62.    
  63.     game["dialog"]["gametype"] = "Hold_the_Flag";
  64. }
  65.  
  66. GetSpawns()
  67. {
  68.     if(getDvar("mapname") == "mp_pk_harbor") return true;
  69.     if(getDvar("mapname") == "mp_qmx_matmata") return true;
  70.    
  71.     return false;
  72. }
  73.  
  74. onStartGameType()
  75. {
  76.     setClientNameMode("auto_change");
  77.    
  78.     level.spawnpoints_needed = GetSpawns();
  79.  
  80.     maps\mp\gametypes\_globallogic::setObjectiveText( "allies", &"EXTREME_OBJ_TEXT_NOSCORE" );
  81.     maps\mp\gametypes\_globallogic::setObjectiveText( "axis", &"EXTREME_OBJ_TEXT_NOSCORE" );
  82.     maps\mp\gametypes\_globallogic::setObjectiveScoreText( "allies", &"EXTREME_OBJ_TEXT" );
  83.     maps\mp\gametypes\_globallogic::setObjectiveScoreText( "axis", &"EXTREME_OBJ_TEXT" );
  84.     maps\mp\gametypes\_globallogic::setObjectiveHintText( "allies", &"MISC_HTF_HINT" );
  85.     maps\mp\gametypes\_globallogic::setObjectiveHintText( "axis", &"MISC_HTF_HINT" );
  86.            
  87.     level.spawnMins = ( 0, 0, 0 );
  88.     level.spawnMaxs = ( 0, 0, 0 ); 
  89.  
  90.     if(level.spawnpoints_needed)
  91.     {
  92.         level.custom_spawnpoints = true;
  93.        
  94.         maps\mp\gametypes\_spawnlogic::placeSpawnpoints( "mp_ctf_spawn_allies_start" );
  95.         maps\mp\gametypes\_spawnlogic::placeSpawnpoints( "mp_ctf_spawn_axis_start" );
  96.         maps\mp\gametypes\_spawnlogic::addSpawnPoints("allies", "mp_ctf_spawn_allies");
  97.         maps\mp\gametypes\_spawnlogic::addSpawnPoints("axis", "mp_ctf_spawn_axis");
  98.        
  99.         level.custom_spawnpoints = false;
  100.         maps\mp\gametypes\_spawnlogic::addSpawnPoints( "allies", "mp_tdm_spawn" );
  101.         maps\mp\gametypes\_spawnlogic::addSpawnPoints( "axis", "mp_tdm_spawn" );
  102.  
  103.     }
  104.     else
  105.     {
  106.         level.custom_spawnpoints = false;
  107.        
  108.         maps\mp\gametypes\_spawnlogic::placeSpawnPoints( "mp_sab_spawn_allies_start" );
  109.         maps\mp\gametypes\_spawnlogic::placeSpawnPoints( "mp_sab_spawn_axis_start" );
  110.         maps\mp\gametypes\_spawnlogic::addSpawnPoints( "allies", "mp_sab_spawn_allies" );
  111.         maps\mp\gametypes\_spawnlogic::addSpawnPoints( "axis", "mp_sab_spawn_axis" );
  112.        
  113.         maps\mp\gametypes\_spawnlogic::addSpawnPoints( "allies", "mp_tdm_spawn" );
  114.         maps\mp\gametypes\_spawnlogic::addSpawnPoints( "axis", "mp_tdm_spawn" );
  115.     }
  116.  
  117.     level.mapCenter = maps\mp\gametypes\_spawnlogic::findBoxCenter( level.spawnMins, level.spawnMaxs );
  118.     setMapCenter( level.mapCenter );
  119.    
  120.     if(level.spawnpoints_needed)
  121.     {
  122.         level.custom_spawnpoints = true;
  123.        
  124.         level.spawn_axis            = getentarray("mp_ctf_spawn_axis", "targetname");
  125.         level.spawn_allies          = getentarray("mp_ctf_spawn_allies", "targetname");
  126.         level.spawn_axis_start      = getentarray("mp_ctf_spawn_axis_start", "targetname");
  127.         level.spawn_allies_start    = getentarray("mp_ctf_spawn_allies_start", "targetname");
  128.  
  129.     }
  130.     else
  131.     {
  132.         level.custom_spawnpoints = false;
  133.        
  134.         level.spawn_axis            = getentarray("mp_sab_spawn_axis", "classname");
  135.         level.spawn_allies          = getentarray("mp_sab_spawn_allies", "classname");
  136.         level.spawn_axis_start      = getentarray("mp_sab_spawn_axis_start", "classname");
  137.         level.spawn_allies_start    = getentarray("mp_sab_spawn_allies_start", "classname");
  138.     }
  139.    
  140.    
  141.     allowed[0] = "htf";
  142.    
  143.     if ( getDvarInt( "scr_oldHardpoints" ) > 0 )
  144.         allowed[1] = "hardpoint";
  145.    
  146.     level.displayRoundEndText = false;
  147.     maps\mp\gametypes\_gameobjects::main(allowed);
  148.    
  149.     maps\mp\gametypes\_rank::registerScoreInfo( "kill", 5 );
  150.     maps\mp\gametypes\_rank::registerScoreInfo( "headshot", 6 );
  151.     maps\mp\gametypes\_rank::registerScoreInfo( "assist", level.PointsForAssistingFlagCarrier );
  152.     maps\mp\gametypes\_rank::registerScoreInfo( "defend", level.PointsForKillingFlagCarrier );
  153.     maps\mp\gametypes\_rank::registerScoreInfo( "steal", level.PointsForStealingFlag );
  154.     maps\mp\gametypes\_rank::registerScoreInfo( "holding", level.PointsForHoldingFlag );
  155.     maps\mp\gametypes\_rank::registerScoreInfo( "capture_team_complete", 1 );
  156.    
  157.     switch( game["allies"] )
  158.     {
  159.         case "marines":
  160.             game["hudicon_allies"] = "faction_128_usmc";
  161.             break;
  162.         case "sas":
  163.             game["hudicon_allies"] = "faction_128_sas";
  164.             break;
  165.         default:
  166.             game["hudicon_allies"] = "faction_128_usmc";
  167.             break;
  168.     }
  169.     switch( game["axis"] )
  170.     {
  171.         case "russian":
  172.             game["hudicon_axis"] = "faction_128_ussr";
  173.             break;
  174.         case "arab":
  175.         case "opfor":
  176.             game["hudicon_axis"] = "faction_128_arab";
  177.             break;
  178.         default:
  179.             game["hudicon_axis"] = "faction_128_arab";
  180.             break;
  181.     }
  182.  
  183.     game["prop_flag_neutral"] = "prop_flag_neutral";
  184.     level.compassflag_neutral = "compass_waypoint_neutral";
  185.     level.objectpoint_neutral = "objpoint_default";
  186.    
  187.     if( game["allies"] == "marines" )
  188.     {
  189.         game["prop_flag_allies"] = "prop_flag_american";
  190.         game["prop_flag_carry_allies"] = "prop_flag_american_carry";
  191.     }
  192.     else
  193.     {
  194.         game["prop_flag_allies"] = "prop_flag_brit";
  195.         game["prop_flag_carry_allies"] = "prop_flag_brit_carry";
  196.     }
  197.    
  198.     if( game["axis"] == "russian" )
  199.     {
  200.         game["prop_flag_axis"] = "prop_flag_russian";
  201.         game["prop_flag_carry_axis"] = "prop_flag_russian_carry";
  202.     }
  203.     else
  204.     {
  205.         game["prop_flag_axis"] = "prop_flag_opfor";
  206.         game["prop_flag_carry_axis"] = "prop_flag_opfor_carry";
  207.     }
  208.  
  209.     if( game["allies"] == "marines" )
  210.     {
  211.         level.compassflag_allies = "compass_flag_marines";
  212.         level.objpointflag_allies = "objpoint_flag_american";
  213.         level.hudflag_allies = "compass_flag_american";
  214.         level.hudflagflash_allies = level.hudflag_allies;
  215.         level.hudflagflash2_allies = "faction_128_usmc";
  216.     }
  217.     else
  218.     {
  219.         level.compassflag_allies = "compass_flag_british";
  220.         level.objpointflag_allies = "objpoint_flag_british";
  221.         level.hudflag_allies = "compass_flag_british";
  222.         level.hudflagflash_allies = level.hudflag_allies;
  223.         level.hudflagflash2_allies = "faction_128_sas";
  224.     }
  225.    
  226.     if( game["axis"] == "russian" )
  227.     {
  228.         level.compassflag_axis = "compass_flag_russian";
  229.         level.objpointflag_axis = "objpoint_flag_russian";
  230.         level.hudflag_axis = "compass_flag_russian";
  231.         level.hudflagflash_axis = level.hudflag_axis;
  232.         level.hudflagflash2_axis = "faction_128_ussr";
  233.     }
  234.     else
  235.     {
  236.         level.compassflag_axis = "compass_flag_opfor";
  237.         level.objpointflag_axis = "objpoint_flag_opfor";
  238.         level.hudflag_axis = "compass_flag_opfor";
  239.         level.hudflagflash_axis = level.hudflag_axis;
  240.         level.hudflagflash2_axis = "faction_128_arab";
  241.     }
  242.    
  243.     // elimination style
  244.     if( level.roundLimit != 1 && level.numLives )
  245.     {
  246.         level.overrideTeamScore = true;
  247.         level.displayRoundEndText = true;
  248.         level.onEndGame = ::onEndGame;
  249.     }
  250.    
  251.     onPrecacheGameType();
  252.     FindTeamSides();
  253.     thread InitFlag(); 
  254. }
  255.  
  256. onPrecacheGameType()
  257. {
  258.    
  259.     precacheModel( game["prop_flag_neutral"] );
  260.     precacheModel( game["prop_flag_allies"] );
  261.     precacheModel( game["prop_flag_axis"] );
  262.     precacheModel( game["prop_flag_carry_allies"] );
  263.     precacheModel( game["prop_flag_carry_axis"] );
  264.    
  265.     precacheShader( game["hudicon_allies"] );
  266.     precacheShader( game["hudicon_axis"] );
  267.    
  268.     precacheShader( level.compassflag_allies );
  269.     precacheShader( level.compassflag_axis );
  270.     precacheShader( level.objpointflag_axis );
  271.     precacheShader( level.objpointflag_allies );
  272.    
  273.     precacheShader( level.objectpoint_neutral );
  274.     precacheShader( level.compassflag_neutral );
  275.    
  276.     precacheShader(level.hudflagflash_allies);
  277.     precacheShader(level.hudflagflash_axis);
  278.     precacheShader(level.hudflagflash2_allies);
  279.     precacheShader(level.hudflagflash2_axis);
  280.    
  281.     precacheStatusicon( level.hudflag_allies );
  282.     precacheStatusicon( level.hudflag_axis );
  283. }
  284.  
  285. onSpawnPlayer()
  286. {
  287.     self.usingObj = undefined;
  288.  
  289.     spawnteam = self.pers["team"];
  290.  
  291.     if( level.useStartSpawns )
  292.     {
  293.         if(spawnteam == "axis")
  294.             spawnpoint = maps\mp\gametypes\_spawnlogic::getSpawnpoint_Random(level.spawn_axis_start);
  295.         else
  296.             spawnpoint = maps\mp\gametypes\_spawnlogic::getSpawnpoint_Random(level.spawn_allies_start);
  297.     }  
  298.     else
  299.     {
  300.         if(spawnteam == "axis")
  301.             spawnpoint = maps\mp\gametypes\_spawnlogic::getSpawnpoint_NearTeam(level.spawn_axis);
  302.         else
  303.             spawnpoint = maps\mp\gametypes\_spawnlogic::getSpawnpoint_NearTeam(level.spawn_allies);
  304.     }
  305.    
  306.     self spawn( spawnPoint.origin, spawnPoint.angles );
  307.    
  308.     thread CheckForFlag();
  309. }
  310.  
  311. onPlayerDisconnect()
  312. {
  313.     self dropFlag();
  314. }
  315.  
  316. onPlayerKilled( eInflictor, attacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, psOffsetTime, deathAnimDuration )
  317. {
  318.  
  319.     if(isdefined(self.flag))
  320.         flagcarrier = true;
  321.     else
  322.         flagcarrier = undefined;
  323.  
  324.     self dropFlag();
  325.     self unset_sprint();
  326.    
  327.     if(isPlayer(attacker))
  328.     {
  329.         doKillcam = true;
  330.            
  331.         if(self.pers["team"] == attacker.pers["team"]) // killed by a friendly
  332.         {
  333.             // Was the flagcarrier killed?
  334.             if(isdefined(flagcarrier) && attacker != self)
  335.             {
  336.                 attacker iprintlnbold(&"EXTREME_YOU_TEAMKILLED_FLAG_CARRIER");
  337.                 _setPlayerScore( attacker, _getPlayerScore( attacker ) - level.PointsForKillingFlagCarrier );
  338.             }
  339.         }
  340.         else
  341.         {
  342.             // Was the flagcarrier killed?
  343.             if(isdefined(flagcarrier))
  344.             {
  345.                 attacker iprintlnbold (&"EXTREME_YOU_KILLED_FLAG_CARRIER");
  346.                 attacker thread [[level.onXPEvent]]( "defend" );
  347.                 givePlayerScore( "defend", attacker );
  348.             }
  349.             else
  350.             {
  351.                 if(attacker AssistedFlagCarrier(self.origin))
  352.                 {
  353.                     attacker iprintlnbold (&"EXTREME_YOU_ASSISTED_FLAG_CARRIER");
  354.                     attacker thread [[level.onXPEvent]]( "assist" );
  355.                     givePlayerScore( "assist", attacker );
  356.                 }
  357.             }
  358.         }
  359.     }
  360. }
  361.  
  362. onEndGame( winningTeam )
  363. {
  364.     if ( isdefined( winningTeam ) && (winningTeam == "allies" || winningTeam == "axis") )
  365.         [[level._setTeamScore]]( winningTeam, [[level._getTeamScore]]( winningTeam ) + 20 );   
  366. }
  367.  
  368. InitFlag()
  369. {
  370.  
  371.     flagpoint = GetFlagPoint();
  372.     position = flagpoint.origin;
  373.     angles = flagpoint.angles;
  374.     origin = FindGround( position );
  375.  
  376.     // Spawn a script origin
  377.     level.flag = spawn("script_origin", origin);
  378.     level.flag.targetname = "htf_flaghome";
  379.     level.flag.origin = origin;
  380.     level.flag.angles = angles;
  381.     level.flag.home_origin = origin;
  382.     level.flag.home_angles = angles;
  383.     level.flag.last_origin = origin;
  384.    
  385.     // Spawn the Neutral Flag to Start
  386.     level.flag.flagmodel = spawn("script_model", level.flag.home_origin);
  387.     level.flag.flagmodel.angles = level.flag.home_angles;
  388.     level.flag.flagmodel setmodel(game["prop_flag_neutral"]);
  389.     level.flag.flagmodel hide();
  390.  
  391.     // Set flag properties
  392.     level.flag.team = "none";
  393.     level.flag.atbase = false;
  394.     level.flag.stolen = false;
  395.     level.flag.lastteam = "none";
  396.     level.flag.objective = 0;
  397.     level.flag.compassflag = level.compassflag_neutral;
  398.     level.flag.objpointflag = level.objectpoint_neutral;
  399.  
  400.     wait 0.05;
  401.  
  402.     SetupHud();
  403.  
  404.     level.flag returnFlag();
  405. }
  406.  
  407. GetFlagPoint()
  408. {
  409.     p1 = level.teamside["axis"];
  410.     p2 = level.teamside["allies"];
  411.  
  412.     // Find center
  413.     x = p1[0] + (p2[0] - p1[0]) / 2;
  414.     y = p1[1] + (p2[1] - p1[1]) / 2;
  415.     z = p1[2] + (p2[2] - p1[2]) / 2;
  416.  
  417.     // Get nearest spawn
  418.     spawnpointname = "mp_tdm_spawn";
  419.     spawnpoints = getentarray(spawnpointname, "classname");
  420.     flagpoint = maps\mp\gametypes\_spawnlogic::NearestSpawnpoint(spawnpoints, (x,y,z));
  421.  
  422.     return flagpoint;
  423. }
  424.  
  425. pickupFlag(flag)
  426. {
  427.     flag notify("end_autoreturn");
  428.  
  429.     // What is my team?
  430.     myteam = self.sessionteam;
  431.     if(myteam == "allies")
  432.         otherteam = "axis";
  433.     else
  434.         otherteam = "allies";
  435.  
  436.     flag.origin = flag.origin + (0, 0, -10000);
  437.     flag.flagmodel hide();
  438.    
  439.     if(myteam == "allies")
  440.         flag.flagmodel setmodel(game["prop_flag_allies"]);
  441.     else
  442.         flag.flagmodel setmodel(game["prop_flag_axis"]);
  443.    
  444.     self.flag = flag;
  445.     self.dont_auto_balance = true;
  446.  
  447.     if(myteam == "allies")
  448.         self.statusicon = level.hudflag_allies;
  449.     else
  450.         self.statusicon = level.hudflag_axis;
  451.  
  452.     flag.carrier = self;
  453.  
  454.     flag.team = self.sessionteam;
  455.     flag.atbase = false;
  456.  
  457.     if(myteam == "allies")
  458.     {
  459.         flag.compassflag = level.compassflag_allies;
  460.         flag.objpointflag = level.objpointflag_allies;
  461.     }
  462.     else
  463.     {
  464.         flag.compassflag = level.compassflag_axis;
  465.         flag.objpointflag = level.objpointflag_axis;
  466.     }
  467.  
  468.     if( level.ex_objectivepoints )
  469.     {
  470.         flag deleteFlagWaypoint();
  471.    
  472.         objective_icon( self.flag.objective, flag.compassflag );
  473.         objective_state( self.flag.objective, "current" );
  474.     }
  475.  
  476.     thread playSoundOnPlayers( "mp_war_objective_lost", myteam );
  477.     thread playSoundOnPlayers( "mp_war_objective_taken", otherteam );
  478.    
  479.     self attachFlag();
  480.     self thread Start_Scoring();
  481.     self thread set_sprint();
  482.  
  483. }
  484.  
  485. set_sprint()
  486. {
  487.     if( !level.heavyflag ) return;
  488.    
  489.     while(isdefined(self.flagAttached))
  490.     {
  491.         if(!isdefined(self.flagAttached)) return;
  492.         self AllowSprint(false);
  493.         wait 1;
  494.     }
  495.        
  496. }
  497.  
  498. unset_sprint()
  499. {
  500.     if( !level.heavyflag ) return;
  501.    
  502.     if(!isdefined(self.flagAttached))
  503.         self AllowSprint(true);
  504. }
  505.  
  506. dropFlag()
  507. {
  508.  
  509.     if(isdefined(self.flag))
  510.     {
  511.         start = self.origin + (0, 0, 10);
  512.         end = start + (0, 0, -2000);
  513.         trace = bulletTrace(start, end, false, undefined);
  514.  
  515.         self.flag.origin = trace["position"];
  516.         self.flag.flagmodel.origin = self.flag.origin;
  517.         self.flag.flagmodel show();
  518.         self.flag.atbase = false;
  519.         self.flag.stolen = false;
  520.  
  521.         self.flag.carrier = undefined;
  522.        
  523.         if( level.ex_objectivepoints )
  524.         {
  525.             // set compass flag position on player
  526.             objective_position(self.flag.objective, self.flag.origin);
  527.             objective_state(self.flag.objective, "current");
  528.            
  529.             self.flag createFlagWaypoint();
  530.         }
  531.  
  532.         self.flag thread autoReturn();
  533.         self detachFlag(self.flag);
  534.  
  535.         self.flag = undefined;
  536.         self.dont_auto_balance = undefined;
  537.         thread playSoundOnPlayers("mp_war_objective_lost");
  538.     }
  539. }
  540.  
  541. returnFlag()
  542. {
  543.     self notify("end_autoreturn");
  544.  
  545.     self deleteFlagWaypoint();
  546.     objective_delete(self.objective);
  547.     objective_delete(self.objective + 1);
  548.  
  549.     // Wait delay before spawning flag
  550.     wait level.flagspawndelay + 0.05;
  551.  
  552.     // Do not spawn flag unless there are alive players in both teams
  553.     while( !(alivePlayers("allies") && alivePlayers("axis")) )
  554.         wait 1;
  555.  
  556.     if(!level.hasspawned["flag"])
  557.     {
  558.         self.origin = self.home_origin;
  559.         self.flagmodel.origin = self.home_origin;
  560.         self.flagmodel.angles = self.home_angles;
  561.         if(level.randomflagspawns)  level.hasspawned["flag"] = true;
  562.     }
  563.     else
  564.     {
  565.         if(level.randomflagspawns == 2)
  566.             spawnpoint = GetSpawnPointAwayFromPlayers();
  567.         else
  568.         {
  569.             spawnpointname = "mp_tdm_spawn";
  570.             spawnpoints = getentarray(spawnpointname, "classname");
  571.             spawnpoint = maps\mp\gametypes\_spawnlogic::getSpawnpoint_Random(spawnpoints);
  572.         }
  573.  
  574.         self.origin = spawnpoint.origin;
  575.         self.flagmodel.origin = spawnpoint.origin;
  576.         self.flagmodel.angles = spawnpoint.angles;
  577.     }
  578.  
  579.     self.flagmodel show();
  580.     self.atbase = true;
  581.     self.stolen = false;
  582.     self.lastteam = "none";
  583.  
  584.     self.carrier = undefined;
  585.    
  586.     if( level.ex_objectivepoints )
  587.     {
  588.         // set compass flag position on player
  589.         objective_add(self.objective, "current", self.origin, self.compassflag);
  590.         objective_position(self.objective, self.origin);
  591.         objective_state(self.objective, "current");
  592.    
  593.         self createFlagWaypoint();
  594.     }
  595.  
  596.     if(level.randomflagspawns)
  597.         self thread autoReturn();
  598. }
  599.  
  600. autoReturn()
  601. {
  602.     if(!level.flagrecovertime)
  603.         return;
  604.  
  605.     self endon("end_autoreturn");
  606.  
  607.     wait level.flagrecovertime;
  608.  
  609.     iprintln(&"EXTREME_FLAG_TIMEOUT", level.flagrecovertime);
  610.  
  611.     // Hide the flag
  612.     self.flagmodel hide();
  613.     self.compassflag = level.compassflag_neutral;
  614.     self.objpointflag = level.objectpoint_neutral;
  615.  
  616.     // Prevent players from stealing it until it respawns
  617.     self.stolen = true;
  618.  
  619.     self thread returnFlag();
  620. }
  621.  
  622. attachFlag()
  623. {
  624.     if(isdefined(self.flagAttached))
  625.         return;
  626.  
  627.     if(self.pers["team"] == "allies")
  628.         flagModel = game["prop_flag_carry_allies"];
  629.     else
  630.         flagModel = game["prop_flag_carry_axis"];
  631.    
  632.     self attach(flagModel, "J_Spine4", true);
  633.     self.flagAttached = true;
  634.    
  635.     self thread createOwnHudIcon();
  636. }
  637.  
  638. detachFlag(flag)
  639. {
  640.     if(!isdefined(self.flagAttached))
  641.         return;
  642.  
  643.     if(flag.team == "allies")
  644.         flagModel = game["prop_flag_carry_allies"];
  645.     else
  646.         flagModel = game["prop_flag_carry_axis"];
  647.        
  648.     self detach(flagModel, "J_Spine4");
  649.     self.flagAttached = undefined;
  650.    
  651.     self.statusicon = "";
  652.    
  653.     self thread deleteOwnHudIcon();
  654. }
  655.  
  656. createFlagWaypoint()
  657. {
  658.     self deleteFlagWaypoint();
  659.  
  660.     waypoint = newHudElem();
  661.     waypoint.x = self.origin[0];
  662.     waypoint.y = self.origin[1];
  663.     waypoint.z = self.origin[2] + 100;
  664.     waypoint.alpha = .71;
  665.     waypoint.isShown = true;
  666.    
  667.     waypoint setShader(self.objpointflag, 8, 8);
  668.  
  669.     waypoint setwaypoint(true);
  670.     self.waypoint_flag = waypoint;
  671. }
  672.  
  673. deleteFlagWaypoint()
  674. {
  675.     if(isdefined(self.waypoint_flag))
  676.         self.waypoint_flag destroy();
  677. }
  678.  
  679. createOwnHudIcon()
  680. {
  681.     if( !level.ex_objectivepoints ) return;
  682.    
  683.     iconSize = 40;
  684.     icon2Size = 30;
  685.    
  686.     X   = 50;
  687.     Y   = 150;
  688.     X2  = 52;
  689.     Y2  = 148;
  690.    
  691.     if( level.hardcoreMode && !level.ex_hardcore_minimap )
  692.     {
  693.         X   = 30;
  694.         Y   = 30;
  695.         X2  = 32;
  696.         Y2  = 28;
  697.     }
  698.     else if( level.hardcoreMode && level.ex_hardcore_minimap )
  699.     {
  700.         X   = 50;
  701.         Y   = 150;
  702.         X2  = 52;
  703.         Y2  = 148;
  704.     }
  705.  
  706.     self.hud_flagflashOwn = newClientHudElem(self);
  707.     self.hud_flagflashOwn.x = X;
  708.     self.hud_flagflashOwn.y = Y;
  709.     self.hud_flagflashOwn.alignX = "center";
  710.     self.hud_flagflashOwn.alignY = "middle";
  711.     self.hud_flagflashOwn.horzAlign = "left";
  712.     self.hud_flagflashOwn.vertAlign = "top";
  713.     self.hud_flagflashOwn.hideWhenInMenu = true;
  714.     self.hud_flagflashOwn.alpha = 0;
  715.     self.hud_flagflashOwn.sort = 1;
  716.    
  717.     self.hud_flagflashOwn2 = newClientHudElem(self);
  718.     self.hud_flagflashOwn2.x = X2;
  719.     self.hud_flagflashOwn2.y = Y2;
  720.     self.hud_flagflashOwn2.alignX = "center";
  721.     self.hud_flagflashOwn2.alignY = "middle";
  722.     self.hud_flagflashOwn2.horzAlign = "left";
  723.     self.hud_flagflashOwn2.vertAlign = "top";
  724.     self.hud_flagflashOwn2.hideWhenInMenu = true;
  725.     self.hud_flagflashOwn2.alpha = 0;
  726.     self.hud_flagflashOwn2.sort = 2;
  727.  
  728.     if(self.pers["team"] == "allies")
  729.     {
  730.         self.hud_flagflashOwn setShader(level.hudflagflash_allies, iconSize, iconSize);
  731.         self.hud_flagflashOwn2 setShader(level.hudflagflash2_allies, icon2Size, icon2Size);
  732.     }
  733.     else
  734.     {
  735.         assert(self.pers["team"] == "axis");
  736.         self.hud_flagflashOwn setShader(level.hudflagflash_axis, iconSize, iconSize);
  737.         self.hud_flagflashOwn2 setShader(level.hudflagflash2_axis, icon2Size, icon2Size);
  738.     }
  739.    
  740.     self.hud_flagflashOwn fadeOverTime(.2);
  741.     self.hud_flagflashOwn2 fadeOverTime(.2);
  742.     self.hud_flagflashOwn.alpha = 1;
  743.     self.hud_flagflashOwn2.alpha = 1;
  744.  
  745.     wait 180;
  746.    
  747.     if(isdefined(self.hud_flagflashOwn))
  748.     {
  749.         self.hud_flagflashOwn fadeOverTime(1);
  750.         self.hud_flagflashOwn2 fadeOverTime(1);
  751.         self.hud_flagflashOwn.alpha = 0;
  752.         self.hud_flagflashOwn2.alpha = 0;
  753.     }
  754. }
  755.  
  756. deleteOwnHudIcon()
  757. {
  758.     if(isdefined(self.hud_flagflashOwn))
  759.         self.hud_flagflashOwn destroy();
  760.        
  761.     if(isdefined(self.hud_flagflashOwn2))
  762.         self.hud_flagflashOwn2 destroy();
  763. }
  764.  
  765. FindTeamSides()
  766. {
  767.     spawnpointname = "mp_tdm_spawn";
  768.     spawnpoints = getentarray(spawnpointname, "classname");
  769.     maxdist = 0;
  770.     p1 = spawnpoints[0];
  771.     p2 = spawnpoints[0];
  772.     for(i=0;i<spawnpoints.size;i++)
  773.     {
  774.         for(j=0;j<spawnpoints.size;j++)
  775.         {
  776.             if(i==j) continue;
  777.             dist = distance(spawnpoints[i].origin,spawnpoints[j].origin);
  778.             if(dist>maxdist)
  779.             {
  780.                 maxdist = dist;
  781.                 p1 = spawnpoints[i];
  782.                 p2 = spawnpoints[j];
  783.             }
  784.         }
  785.     }
  786.  
  787.     // Save teamsides for initial spawning
  788.     if(randomInt(2))
  789.     {
  790.         level.teamside["axis"] = p1.origin;
  791.         level.teamside["allies"] = p2.origin;
  792.     }
  793.     else
  794.     {
  795.         level.teamside["axis"] = p2.origin;
  796.         level.teamside["allies"] = p1.origin;
  797.     }
  798. }
  799.  
  800. FindGround(position)
  801. {
  802.     return (physicstrace (position + (0, 0, 20), position + (0, 0, -20)));
  803. }
  804.  
  805. CheckForFlag()
  806. {
  807.     level endon("intermission");
  808.  
  809.     self.flag = undefined;
  810.     count=0;
  811.     oldorigin = self.origin;
  812.  
  813.     // What is my team?
  814.     myteam = self.sessionteam;
  815.     if(myteam == "allies")
  816.         otherteam = "axis";
  817.     else
  818.         otherteam = "allies";
  819.    
  820.     while (isAlive(self) && self.sessionstate == "playing" && myteam == self.sessionteam)
  821.     {
  822.         // Does the flag exist and is not currently being stolen?
  823.         if(!level.flag.stolen)
  824.         {
  825.             // Am I touching it and it is not currently being stolen?
  826.             if(self isTouchingFlag() && !level.flag.stolen)
  827.             {
  828.                 level.flag.stolen = true;
  829.        
  830.                 // Steal flag
  831.                 self pickupFlag(level.flag);
  832.  
  833.                 oldorigin = self.origin;
  834.  
  835.                 if(self.flag.lastteam != myteam)
  836.                 {
  837.                     iprintlnbold(&"EXTREME_STOLE_FLAG", self.name);
  838.  
  839.                     // Get personal score
  840.                     self thread [[level.onXPEvent]]( "steal" );
  841.                     givePlayerScore( "steal", self );
  842.  
  843.                     if(level.mode == 2)
  844.                         level.teamholdtime[otherteam] = 0;
  845.  
  846.                     lpselfnum = self getEntityNumber();
  847.                     lpselfguid = self getGuid();
  848.                     logPrint("A;" + lpselfguid + ";" + lpselfnum + ";" + myteam + ";" + self.name + ";" + "htf_stole" + "\n");
  849.                 }
  850.                 else
  851.                 {
  852.                     iprintlnbold( &"EXTREME_STOLE_FLAG", self.name );
  853.                 }
  854.                
  855.                 self.flag.lastteam = self.flag.team;
  856.  
  857.                 if(myteam == "axis")
  858.                     level.iconaxis scaleOverTime(1, 22, 22);
  859.                 else
  860.                     level.iconallies scaleOverTime(1, 22, 22);
  861.                
  862.                 count = 0;
  863.             }
  864.         }
  865.  
  866.         // Update objective on compass
  867.         if(isdefined(self.flag))
  868.         {
  869.             // Update the objective for my team
  870.             objective_position(self.flag.objective, self.origin);      
  871.  
  872.             wait 0.05;
  873.  
  874.             // Make sure flag still exist
  875.             if(isdefined(self.flag))
  876.             {
  877.                 count++;
  878.                 if(count>=20)
  879.                 {
  880.                     count = 0;
  881.                    
  882.                     // Update the other teams objective (lags 1 second behind)
  883.                     objective_position(self.flag.objective+1, oldorigin);      
  884.                     oldorigin = self.origin;
  885.    
  886.                     if(level.mode == 1 && level.teamholdtime[otherteam])
  887.                         level.teamholdtime[otherteam]--;
  888.                     else
  889.                         level.teamholdtime[myteam]++;
  890.  
  891.                     if(level.teamholdtime[myteam] >= level.holdtime)
  892.                     {
  893.                         if(myteam == "allies")
  894.                         {
  895.                             iprintlnbold (&"EXTREME_ALLIED_SCORED", level.holdtime);
  896.                             thread allies_flag_count();
  897.                         }
  898.                         else
  899.                         {
  900.                             iprintlnbold (&"EXTREME_AXIS_SCORED", level.holdtime);
  901.                             thread axis_flag_count();
  902.                         }
  903.  
  904.                         thread playSoundOnPlayers("plr_new_rank", myteam);
  905.                         thread playSoundOnPlayers("mp_obj_taken", otherteam);
  906.  
  907.                         level.teamholdtime[myteam] = 0;
  908.                         if(level.mode == 3)
  909.                             level.teamholdtime[otherteam] = 0;
  910.  
  911.                         // Get personal score
  912.                         self thread [[level.onXPEvent]]( "holding" );
  913.                         givePlayerScore( "holding", self );
  914.  
  915.                         // Give all other team members 1 point
  916.                         players = getentarray("player", "classname");
  917.                         for(i = 0; i < players.size; i++)
  918.                         {
  919.                             player = players[i];
  920.                    
  921.                             if(!isDefined(player.pers["team"]) || player.pers["team"] != myteam || player == self)
  922.                                 continue;
  923.                            
  924.                             player thread [[level.onXPEvent]]( "capture_team_complete" );  
  925.                             givePlayerScore( "capture_team_complete", player );
  926.                         }
  927.  
  928.                         lpselfnum = self getEntityNumber();
  929.                         lpselfguid = self getGuid();
  930.                         logPrint("A;" + lpselfguid + ";" + lpselfnum + ";" + myteam + ";" + self.name + ";" + "htf_scored" + "\n");
  931.                        
  932.                         level notify("update_allhud_score");
  933.  
  934.                         if(myteam == "allies")
  935.                             level.numallies setValue(level.allies_cap_count);
  936.                         else
  937.                             level.numaxis setValue(level.axis_cap_count);
  938.  
  939.                         checkScoreLimit();
  940.  
  941.                         self detachFlag(self.flag);
  942.                         self thread unset_sprint();
  943.  
  944.                         // Return flag
  945.                         self.flag thread ReturnFlag();
  946.  
  947.                         // Clear flags
  948.                         self.flag = undefined; 
  949.  
  950.                         if(myteam == "axis")
  951.                             level.iconaxis scaleOverTime(1, 18, 18);
  952.                         else
  953.                             level.iconallies scaleOverTime(1, 18, 18);
  954.                     }
  955.  
  956.                     UpdateHud();
  957.                 }
  958.             }
  959.         }
  960.         else
  961.             wait 0.2;      
  962.     }
  963.  
  964.     //player died or went spectator
  965.     self dropFlag();
  966. }
  967.  
  968. //score 1 every second
  969. Start_Scoring()
  970. {
  971.     myteam = self.sessionteam;
  972.     if( self.pers["team"] == "allies" )
  973.         myteam = "allies";
  974.     else
  975.         myteam = "axis";
  976.    
  977.     count = 0;
  978.    
  979.     while( 1 )
  980.     {
  981.         if( count == level.holdtime || !isdefined(self.flagAttached) )
  982.             break;
  983.            
  984.         count++;
  985.        
  986.         [[level._setTeamScore]]( myteam, _getTeamScore(myteam) + 1 );
  987.         level notify("update_allhud_score");
  988.         wait 1;
  989.     }
  990. }
  991.  
  992. axis_flag_count()
  993. {
  994.     level endon("intermission");
  995.  
  996.     level.axis_cap_count++;
  997. }
  998.  
  999. allies_flag_count()
  1000. {
  1001.     self endon("intermission");
  1002.    
  1003.     level.allies_cap_count++;
  1004. }
  1005.  
  1006. isTouchingFlag()
  1007. {
  1008.     if(distance(self.origin, level.flag.origin) < 50)
  1009.         return true;
  1010.     else
  1011.         return false;
  1012. }
  1013.  
  1014. SetupHud()
  1015. {
  1016.     level endon("awe_killthreads");
  1017.    
  1018.     X = undefined;
  1019.     y = undefined;
  1020.    
  1021.     if( level.hardcoreMode && level.ex_hardcore_minimap )
  1022.     {
  1023.         X = 370;
  1024.         y = 30;
  1025.     }
  1026.     else if( level.hardcoreMode && !level.ex_hardcore_minimap )
  1027.     {
  1028.         X = 320;
  1029.         y = 15;
  1030.     }
  1031.     else
  1032.     {
  1033.         X = 370;
  1034.         y = 30;
  1035.     }
  1036.        
  1037.     barsize = 200;
  1038.    
  1039.  
  1040.     level.scoreback = newHudElem();
  1041.     level.scoreback.x = X;
  1042.     level.scoreback.y = y;
  1043.     level.scoreback.alignX = "center";
  1044.     level.scoreback.alignY = "middle";
  1045.     level.scoreback.alpha = 0.3;
  1046.     level.scoreback.color = (0.2,0.2,0.2);
  1047.     level.scoreback setShader("white", barsize*2+4, 12);
  1048.  
  1049.     level.scoreallies = newHudElem();
  1050.     level.scoreallies.x = X;
  1051.     level.scoreallies.y = y;
  1052.     level.scoreallies.alignX = "right";
  1053.     level.scoreallies.alignY = "middle";
  1054.     level.scoreallies.color = (1,0,0);
  1055.     level.scoreallies.alpha = 0.5;
  1056.     level.scoreallies setShader("white", 1, 10);
  1057.  
  1058.     level.scoreaxis = newHudElem();
  1059.     level.scoreaxis.x = X;
  1060.     level.scoreaxis.y = y;
  1061.     level.scoreaxis.alignX = "left";
  1062.     level.scoreaxis.alignY = "middle";
  1063.     level.scoreaxis.color = (0,0,1);
  1064.     level.scoreaxis.alpha = 0.5;
  1065.     level.scoreaxis setShader("white", 1, 10);
  1066.  
  1067.     level.iconallies = newHudElem();
  1068.     level.iconallies.x = X - barsize - 3;
  1069.     level.iconallies.y = y;
  1070.     level.iconallies.alignX = "right";
  1071.     level.iconallies.alignY = "middle";
  1072.     level.iconallies.color = (1,1,1);
  1073.     level.iconallies.alpha = 1;
  1074.     level.iconallies setShader(game["hudicon_allies"], 20, 20);
  1075.  
  1076.     level.iconaxis = newHudElem();
  1077.     level.iconaxis.x = X + barsize + 3;
  1078.     level.iconaxis.y = y;
  1079.     level.iconaxis.alignX = "left";
  1080.     level.iconaxis.alignY = "middle";
  1081.     level.iconaxis.color = (1,1,1);
  1082.     level.iconaxis.alpha = 1;
  1083.     level.iconaxis setShader(game["hudicon_axis"], 20, 20);
  1084.  
  1085.     level.numallies = newHudElem();
  1086.     level.numallies.x = X - barsize - 30;
  1087.     level.numallies.y = y-2;
  1088.     level.numallies.alignX = "right";
  1089.     level.numallies.alignY = "middle";
  1090.     level.numallies.color = (1,1,0);
  1091.     level.numallies.alpha = 1;
  1092.     level.numallies.fontscale = 1.4;
  1093.     level.numallies setValue(0);
  1094.  
  1095.     level.numaxis = newHudElem();
  1096.     level.numaxis.x = X + barsize + 35;
  1097.     level.numaxis.y = y-2;
  1098.     level.numaxis.alignX = "right";
  1099.     level.numaxis.alignY = "middle";
  1100.     level.numaxis.color = (1,1,0);
  1101.     level.numaxis.alpha = 1;
  1102.     level.numaxis.fontscale = 1.4;
  1103.     level.numaxis setValue(0);
  1104. }
  1105.  
  1106. CleanUp()
  1107. {
  1108.     level.numaxis.alpha = 0;
  1109.     level.numallies.alpha = 0;
  1110.     level.iconaxis.alpha = 0;
  1111.     level.iconallies.alpha = 0;
  1112.     level.scoreaxis.alpha = 0;
  1113.     level.scoreallies.alpha = 0;
  1114.     level.scoreback.alpha = 0;
  1115. }
  1116.  
  1117. UpdateHud()
  1118. {
  1119.     y = 10;
  1120.     barsize = 200;
  1121.  
  1122.     axis = int(level.teamholdtime["axis"] * barsize / (level.holdtime - 1) + 1);
  1123.     allies = int(level.teamholdtime["allies"] * barsize / (level.holdtime - 1) + 1);
  1124.  
  1125.     if(level.teamholdtime["allies"] != level.oldteamholdtime["allies"])
  1126.         level.scoreallies scaleOverTime(1,allies,10);
  1127.     if(level.teamholdtime["axis"] != level.oldteamholdtime["axis"])
  1128.         level.scoreaxis scaleOverTime(1,axis,10);
  1129.  
  1130.     level.oldteamholdtime["allies"] = level.teamholdtime["allies"];
  1131.     level.oldteamholdtime["axis"] = level.teamholdtime["axis"];
  1132. }
  1133.  
  1134. AssistedFlagCarrier(victim_origin)
  1135. {
  1136.     flag = level.flag;
  1137.  
  1138.     if (! isdefined (flag.carrier))
  1139.         // No carrier for the flag
  1140.         return (false);
  1141.  
  1142.     if (flag.carrier == self)
  1143.         // No "self-assistance"
  1144.         return (false);
  1145.            
  1146.     if (flag.carrier.pers["team"] != self.pers["team"])
  1147.         // No assistance for ennemy carrier
  1148.         return (false);
  1149.  
  1150.     dist = distance (victim_origin, flag.carrier.origin);
  1151.        
  1152.     return (dist < level.flagprotectiondistance);
  1153. }
  1154.  
  1155. GetSpawnPointAwayFromPlayers()
  1156. {
  1157.     // Determine the center position of all players
  1158.     x = 0;
  1159.     y = 0;
  1160.     z = 0;
  1161.     numplayers = 0;
  1162.     players = getentarray ("player", "classname");
  1163.     for (i = 0; i < players.size; i ++)
  1164.     {
  1165.         player = players[i];
  1166.         if (isDefined (player.pers["team"]) && (player.sessionstate == "playing") && isAlive(player))
  1167.         {
  1168.             x += player.origin[0];
  1169.             y += player.origin[1];
  1170.             z += player.origin[2];
  1171.             numplayers ++;
  1172.         }
  1173.     }
  1174.     centerpoint = (x / numplayers, y / numplayers, z / numplayers);
  1175.  
  1176.     // Find the farthest spawn point from the center
  1177.     spawnpointname = "mp_tdm_spawn";
  1178.     spawnpoints = getentarray(spawnpointname, "classname");
  1179.  
  1180.     spawnpoint = FarthestSpawnpoint(spawnpoints, centerpoint);
  1181.     level.flag.last_origin = spawnpoint.origin;
  1182.     return (spawnpoint);
  1183. }
  1184.  
  1185. FarthestSpawnpoint(aeSpawnpoints, vPosition)
  1186. {
  1187.     eFarthestSpot = aeSpawnpoints[0];
  1188.     fFarthestDist = distance(vPosition, aeSpawnpoints[0].origin);
  1189.     for(i = 1; i < aeSpawnpoints.size; i++)
  1190.     {
  1191.         fDist = distance(vPosition, aeSpawnpoints[i].origin);
  1192.         if ((fDist > fFarthestDist) && (aeSpawnpoints[i].origin != level.flag.last_origin))
  1193.         {
  1194.             eFarthestSpot = aeSpawnpoints[i];
  1195.             fFarthstDist = fDist;
  1196.         }
  1197.     }
  1198.    
  1199.     return eFarthestSpot;
  1200. }
  1201.  
  1202. IsAwayFromFlag()
  1203. {
  1204.     dist = distance (self.origin, level.flag.origin);
  1205.     return ((dist >= level.spawndistance) && (dist <= level.spawndistancemax));
  1206. }
  1207.  
  1208. alivePlayers(team)
  1209. {
  1210.     allplayers = getentarray("player", "classname");
  1211.     alive = [];
  1212.     for(i = 0; i < allplayers.size; i++)
  1213.     {
  1214.         if(allplayers[i].sessionstate == "playing" && allplayers[i].sessionteam == team)
  1215.             alive[alive.size] = allplayers[i];
  1216.     }
  1217.     return alive.size;
  1218. }

Paste-bin is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.