CSHARP 209
Ctf.gsc Guest on 18th April 2021 07:35:38 PM
  1. #include maps\mp\_utility;
  2. #include maps\mp\gametypes\_hud_util;
  3. #include maps\mp\gametypes\_globallogic;
  4. /*
  5.     CTF by Tally
  6.     12/17/2007
  7. */
  8.  
  9. main()
  10. {
  11.     if(getdvar("mapname") == "mp_background")
  12.         return;
  13.    
  14.     maps\mp\gametypes\_setupmaps::init();
  15.     maps\mp\gametypes\_globallogic::init();
  16.     maps\mp\gametypes\_callbacksetup::SetupCallbacks();
  17.     maps\mp\gametypes\_globallogic::SetupCallbacks();
  18.     if(level.ex_blackscreen) maps\mp\gametypes\_blackscreen::init();
  19.    
  20.     maps\mp\gametypes\_globallogic::registerTimeLimitDvar( "ctf", 2, 0, 1440 );
  21.     maps\mp\gametypes\_globallogic::registerScoreLimitDvar( "ctf", 500, 0, 5000 );
  22.     maps\mp\gametypes\_globallogic::registerRoundLimitDvar( "ctf", 1, 0, 99 );
  23.     maps\mp\gametypes\_globallogic::registerNumLivesDvar( "ctf", 0, 0, 10 );
  24.    
  25.     level.ex_heavyflag      = extreme\_ex_utils::dvardef("scr_ctf_heavyflag", 1, 0, 1, "int");
  26.     level.ex_flag_returndelay   = extreme\_ex_utils::dvardef("scr_ctf_returnflag_delay", 60, 0, 140, "int");
  27.     level.ex_pointsfor_flag     = extreme\_ex_utils::dvardef("scr_ctf_pointsfor_flag", 10, 0, 99, "int");
  28.  
  29.     level.teamBased = true;
  30.     level.overrideTeamScore = true;
  31.     level.onStartGameType = ::onStartGameType;
  32.     level.onSpawnPlayer = ::onSpawnPlayer;
  33.     level.onPlayerKilled = ::onPlayerKilled;
  34.     level.onPlayerDisconnect = ::onPlayerDisconnect;
  35.    
  36.     game["dialog"]["gametype"] = "Capture_the_Flag";
  37. }
  38.  
  39. GetSpawns()
  40. {
  41.     if(getDvar("mapname") == "mp_pk_harbor") return true;
  42.     if(getDvar("mapname") == "mp_qmx_matmata") return true;
  43.    
  44.     return false;
  45. }
  46.  
  47. onStartGameType()
  48. {
  49.     setClientNameMode("auto_change");
  50.    
  51.     level.spawnpoints_needed = GetSpawns();
  52.  
  53.     maps\mp\gametypes\_globallogic::setObjectiveText( "allies", &"MISC_CTF" );
  54.     maps\mp\gametypes\_globallogic::setObjectiveText( "axis", &"MISC_CTF" );
  55.     maps\mp\gametypes\_globallogic::setObjectiveScoreText( "allies", &"MISC_CTF_SCORE" );
  56.     maps\mp\gametypes\_globallogic::setObjectiveScoreText( "axis", &"MISC_CTF_SCORE" );
  57.     maps\mp\gametypes\_globallogic::setObjectiveHintText( "allies", &"MISC_CTF_HINT" );
  58.     maps\mp\gametypes\_globallogic::setObjectiveHintText( "axis", &"MISC_CTF_HINT" );
  59.  
  60.     level.spawnMins = ( 0, 0, 0 );
  61.     level.spawnMaxs = ( 0, 0, 0 );
  62.    
  63.     if(level.spawnpoints_needed)
  64.     {
  65.         level.custom_spawnpoints = true;
  66.        
  67.         maps\mp\gametypes\_spawnlogic::placeSpawnpoints( "mp_ctf_spawn_allies_start" );
  68.         maps\mp\gametypes\_spawnlogic::placeSpawnpoints( "mp_ctf_spawn_axis_start" );
  69.         maps\mp\gametypes\_spawnlogic::addSpawnPoints("allies", "mp_ctf_spawn_allies");
  70.         maps\mp\gametypes\_spawnlogic::addSpawnPoints("axis", "mp_ctf_spawn_axis");
  71.    
  72.     }
  73.     else
  74.     {
  75.         level.custom_spawnpoints = false;
  76.        
  77.         maps\mp\gametypes\_spawnlogic::placeSpawnPoints( "mp_sab_spawn_allies_start" );
  78.         maps\mp\gametypes\_spawnlogic::placeSpawnPoints( "mp_sab_spawn_axis_start" );
  79.         maps\mp\gametypes\_spawnlogic::addSpawnPoints( "allies", "mp_sab_spawn_allies" );
  80.         maps\mp\gametypes\_spawnlogic::addSpawnPoints( "axis", "mp_sab_spawn_axis" );
  81.     }
  82.    
  83.     level.mapCenter = maps\mp\gametypes\_spawnlogic::findBoxCenter( level.spawnMins, level.spawnMaxs );
  84.     setMapCenter( level.mapCenter );
  85.    
  86.     if(level.spawnpoints_needed)
  87.     {
  88.         level.spawn_axis            = getentarray("mp_ctf_spawn_axis", "targetname");
  89.         level.spawn_allies          = getentarray("mp_ctf_spawn_allies", "targetname");
  90.         level.spawn_axis_start      = getentarray("mp_ctf_spawn_axis_start", "targetname");
  91.         level.spawn_allies_start    = getentarray("mp_ctf_spawn_allies_start", "targetname");  
  92.     }
  93.     else
  94.     {
  95.         level.spawn_axis            = getentarray("mp_sab_spawn_axis", "classname");
  96.         level.spawn_allies          = getentarray("mp_sab_spawn_allies", "classname");
  97.         level.spawn_axis_start      = getentarray("mp_sab_spawn_axis_start", "classname");
  98.         level.spawn_allies_start    = getentarray("mp_sab_spawn_allies_start", "classname");
  99.     }
  100.    
  101.  
  102.     allowed[0] = "war";
  103.    
  104.     if ( getDvarInt( "scr_oldHardpoints" ) > 0 )
  105.         allowed[1] = "hardpoint";
  106.    
  107.     level.displayRoundEndText = false;
  108.     maps\mp\gametypes\_gameobjects::main(allowed);
  109.    
  110.     maps\mp\gametypes\_rank::registerScoreInfo( "kill", 5 );
  111.     maps\mp\gametypes\_rank::registerScoreInfo( "headshot", 6 );
  112.     maps\mp\gametypes\_rank::registerScoreInfo( "assist", 6 );
  113.     maps\mp\gametypes\_rank::registerScoreInfo( "capture", 8 );
  114.     maps\mp\gametypes\_rank::registerScoreInfo( "defend", 6 );
  115.     maps\mp\gametypes\_rank::registerScoreInfo( "return", 5 );
  116.    
  117.     if( game["allies"] == "marines" )
  118.     {
  119.         game["prop_flag_allies"] = "prop_flag_american";
  120.         game["prop_flag_carry_allies"] = "prop_flag_american_carry";
  121.     }
  122.     else
  123.     {
  124.         game["prop_flag_allies"] = "prop_flag_brit";
  125.         game["prop_flag_carry_allies"] = "prop_flag_brit_carry";
  126.     }
  127.    
  128.     if( game["axis"] == "russian" )
  129.     {
  130.         game["prop_flag_axis"] = "prop_flag_russian";
  131.         game["prop_flag_carry_axis"] = "prop_flag_russian_carry";
  132.     }
  133.     else
  134.     {
  135.         game["prop_flag_axis"] = "prop_flag_opfor";
  136.         game["prop_flag_carry_axis"] = "prop_flag_opfor_carry";
  137.     }
  138.    
  139.     game["prop_flag_base"] = "ch_industrial_lamp_off";
  140.  
  141.     if( game["allies"] == "marines" )
  142.     {
  143.         level.compassflag_allies = "compass_flag_marines";
  144.         level.objpointflag_allies = "objpoint_flag_american";
  145.         level.objpointflagmissing_allies = "objpoint_flag_x_american";
  146.         level.hudflag_allies = "compass_flag_american";
  147.         level.hudflagflash_allies = level.hudflag_allies;
  148.         level.hudflagflash2_allies = "faction_128_usmc";
  149.     }
  150.     else
  151.     {
  152.         level.compassflag_allies = "compass_flag_british";
  153.         level.objpointflag_allies = "objpoint_flag_british";
  154.         level.objpointflagmissing_allies = "objpoint_flag_x_british";
  155.         level.hudflag_allies = "compass_flag_british";
  156.         level.hudflagflash_allies = level.hudflag_allies;
  157.         level.hudflagflash2_allies = "faction_128_sas";
  158.     }
  159.    
  160.     if( game["axis"] == "russian" )
  161.     {
  162.         level.compassflag_axis = "compass_flag_russian";
  163.         level.objpointflag_axis = "objpoint_flag_russian";
  164.         level.objpointflagmissing_axis = "objpoint_flag_x_russian";
  165.         level.hudflag_axis = "compass_flag_russian";
  166.         level.hudflagflash_axis = level.hudflag_axis;
  167.         level.hudflagflash2_axis = "faction_128_ussr";
  168.     }
  169.     else
  170.     {
  171.         level.compassflag_axis = "compass_flag_opfor";
  172.         level.objpointflag_axis = "objpoint_flag_opfor";
  173.         level.objpointflagmissing_axis = "objpoint_flag_x_opfor";
  174.         level.hudflag_axis = "compass_flag_opfor";
  175.         level.hudflagflash_axis = level.hudflag_axis;
  176.         level.hudflagflash2_axis = "faction_128_arab";
  177.     }
  178.    
  179.     // elimination style
  180.     if( level.roundLimit != 1 && level.numLives )
  181.     {
  182.         level.overrideTeamScore = true;
  183.         level.displayRoundEndText = true;
  184.         level.onEndGame = ::onEndGame;
  185.     }
  186.    
  187.     onPrecacheGameType();
  188.     thread initFlags();
  189. }
  190.  
  191. onPrecacheGameType()
  192. {
  193.    
  194.     precacheModel( game["prop_flag_allies"] );
  195.     precacheModel( game["prop_flag_axis"] );
  196.     precacheModel( game["prop_flag_carry_allies"] );
  197.     precacheModel( game["prop_flag_carry_axis"] );
  198.    
  199.     precacheShader( level.compassflag_allies );
  200.     precacheShader( level.compassflag_axis );
  201.     precacheShader( level.objpointflag_axis );
  202.     precacheShader( level.objpointflag_allies );
  203.     precacheShader( level.objpointflagmissing_allies );
  204.     precacheShader( level.objpointflagmissing_axis );
  205.     precacheShader(level.hudflagflash_allies);
  206.     precacheShader(level.hudflagflash_axis);
  207.     precacheShader(level.hudflagflash2_allies);
  208.     precacheShader(level.hudflagflash2_axis);
  209.    
  210.     precacheStatusicon( level.hudflag_allies );
  211.     precacheStatusicon( level.hudflag_axis );
  212. }
  213.  
  214. onSpawnPlayer()
  215. {
  216.     self.usingObj = undefined;
  217.  
  218.     spawnteam = self.pers["team"];
  219.  
  220.     if( level.useStartSpawns )
  221.     {
  222.         if(spawnteam == "axis")
  223.             spawnpoint = maps\mp\gametypes\_spawnlogic::getSpawnpoint_Random(level.spawn_axis_start);
  224.         else
  225.             spawnpoint = maps\mp\gametypes\_spawnlogic::getSpawnpoint_Random(level.spawn_allies_start);
  226.     }  
  227.     else
  228.     {
  229.         if(spawnteam == "axis")
  230.             spawnpoint = maps\mp\gametypes\_spawnlogic::getSpawnpoint_NearTeam(level.spawn_axis);
  231.         else
  232.             spawnpoint = maps\mp\gametypes\_spawnlogic::getSpawnpoint_NearTeam(level.spawn_allies);
  233.     }
  234.    
  235.     self spawn( spawnPoint.origin, spawnPoint.angles );
  236. }
  237.  
  238. onPlayerDisconnect()
  239. {
  240.     self dropFlag();
  241. }
  242.  
  243. onPlayerKilled( eInflictor, attacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, psOffsetTime, deathAnimDuration )
  244. {
  245.  
  246.     self dropFlag();
  247.     self unset_sprint();
  248.    
  249.     if(isPlayer(attacker))
  250.     {
  251.         doKillcam = true;
  252.            
  253.         if(self.pers["team"] != attacker.pers["team"])
  254.         {  
  255.             gave_points = false;
  256.                    
  257.             // if the dead person was close to the flag then give the killer a defense bonus
  258.             if(self isnearFlag())
  259.             {
  260.                 // let everyone know
  261.                 if(attacker.pers["team"] == "axis" )
  262.                     iprintln(&"EXTREME_DEFENDED_AXIS", attacker.name);
  263.                 else
  264.                     iprintln(&"EXTREME_DEFENDED_ALLIES", attacker.name);
  265.                        
  266.                 attacker thread [[level.onXPEvent]]( "defend" );
  267.                 givePlayerScore( "defend", attacker );
  268.                
  269.                 gave_points = true;
  270.                 lpattacknum = attacker getEntityNumber();
  271.                 lpattackguid = attacker getGuid();
  272.  
  273.                 logPrint("A;" + lpattackguid + ";" + lpattacknum + ";" + attacker.pers["team"] + ";" + attacker.name + ";" + "ctf_defended" + "\n");
  274.             }
  275.                    
  276.             // if the dead person was close to the flag carrier then give the killer a assist bonus
  277.             if(self isnearCarrier(attacker))
  278.             {
  279.                 // let everyone know
  280.                 if(attacker.pers["team"] == "axis" )
  281.                     iprintln( &"EXTREME_ASSISTED_AXIS", attacker.name);
  282.                 else
  283.                     iprintln(&"EXTREME_ASSISTED_ALLIES", attacker.name);
  284.                        
  285.                 attacker thread [[level.onXPEvent]]( "assist" );
  286.                 givePlayerScore( "assist", attacker );
  287.                
  288.                 gave_points = true;
  289.                 lpattacknum = attacker getEntityNumber();
  290.                 lpattackguid = attacker getGuid();
  291.                 logPrint("A;" + lpattackguid + ";" + lpattacknum + ";" + attacker.pers["team"] + ";" + attacker.name + ";" + "ctf_assist" + "\n");
  292.             }
  293.         }
  294.     }
  295. }
  296.  
  297.  
  298. onEndGame( winningTeam )
  299. {
  300.     if ( isdefined( winningTeam ) && (winningTeam == "allies" || winningTeam == "axis") )
  301.         [[level._setTeamScore]]( winningTeam, [[level._getTeamScore]]( winningTeam ) + level.ex_pointsfor_flag );  
  302. }
  303.  
  304. initFlags()
  305. {
  306.  
  307.     maperrors = [];
  308.  
  309.     allied_flags = getentarray("allied_flag", "targetname");
  310.     if(allied_flags.size < 1)
  311.         maperrors[maperrors.size] = "^1No entities found with \"targetname\" \"allied_flag\"";
  312.     else if(allied_flags.size > 1)
  313.         maperrors[maperrors.size] = "^1More than 1 entity found with \"targetname\" \"allied_flag\"";
  314.  
  315.     axis_flags = getentarray("axis_flag", "targetname");
  316.     if(axis_flags.size < 1)
  317.         maperrors[maperrors.size] = "^1No entities found with \"targetname\" \"axis_flag\"";
  318.     else if(axis_flags.size > 1)
  319.         maperrors[maperrors.size] = "^1More than 1 entity found with \"targetname\" \"axis_flag\"";
  320.  
  321.     if(maperrors.size)
  322.     {
  323.         println("^1------------ Map Errors ------------");
  324.         for(i = 0; i < maperrors.size; i++)
  325.             println(maperrors[i]);
  326.         println("^1------------------------------------");
  327.  
  328.         return;
  329.     }
  330.  
  331.     allied_flag = getent("allied_flag", "targetname");
  332.     allied_flag.home_origin = allied_flag.origin;
  333.     allied_flag.home_angles = allied_flag.angles;
  334.     allied_flag.flagmodel = spawn("script_model", allied_flag.home_origin);
  335.     allied_flag.flagmodel.angles = allied_flag.home_angles;
  336.     allied_flag.flagmodel setmodel(game["prop_flag_allies"]);
  337.    
  338.     allied_flag.basemodel = spawn("script_model", allied_flag.home_origin + (-19, 0, 15));
  339.     allied_flag.basemodel.angles = allied_flag.home_angles ;
  340.     allied_flag.basemodel setmodel(game["prop_flag_base"]);
  341.  
  342.     allied_flag.team = "allies";
  343.     allied_flag.atbase = true;
  344.     allied_flag.objective = 0;
  345.     allied_flag.compassflag = level.compassflag_allies;
  346.     allied_flag.objpointflag = level.objpointflag_allies;
  347.     allied_flag.objpointflagmissing = level.objpointflagmissing_allies;
  348.     allied_flag thread flag();
  349.  
  350.     axis_flag = getent("axis_flag", "targetname");
  351.     axis_flag.home_origin = axis_flag.origin;
  352.     axis_flag.home_angles = axis_flag.angles;
  353.     axis_flag.flagmodel = spawn("script_model", axis_flag.home_origin);
  354.     axis_flag.flagmodel.angles = axis_flag.home_angles;
  355.     axis_flag.flagmodel setmodel(game["prop_flag_axis"]);
  356.    
  357.     axis_flag.basemodel = spawn("script_model", axis_flag.home_origin + (-19, 0, 15));
  358.     axis_flag.basemodel.angles = axis_flag.home_angles ;
  359.     axis_flag.basemodel setmodel(game["prop_flag_base"]);  
  360.    
  361.     axis_flag.team = "axis";
  362.     axis_flag.atbase = true;
  363.     axis_flag.objective = 1;
  364.     axis_flag.compassflag = level.compassflag_axis;
  365.     axis_flag.objpointflag = level.objpointflag_axis;
  366.     axis_flag.objpointflagmissing = level.objpointflagmissing_axis;
  367.     axis_flag thread flag();
  368.    
  369. }
  370.  
  371. flag()
  372. {
  373.     if(level.ex_objectivepoints)
  374.     {
  375.         objective_add(self.objective, "current", self.origin, self.compassflag);
  376.         self createFlagWaypoint();
  377.     }
  378.    
  379.     self.status = "home";
  380.    
  381.     for(;;)
  382.     {
  383.         self waittill("trigger", other);
  384.  
  385.         if(isPlayer(other) && isAlive(other) && (other.pers["team"] != "spectator"))
  386.         {
  387.             team = other.pers["team"];
  388.            
  389.             if(other.pers["team"] == self.team)
  390.             {
  391.                 if(self.atbase)
  392.                 {
  393.                     if(isdefined(other.flag))
  394.                     {
  395.                         if(self.team == "axis")
  396.                             iprintln( &"EXTREME_CAPTURED_AXIS", other.name );
  397.                         else
  398.                             iprintln( &"EXTREME_CAPTURED_ALLIES", other.name );
  399.  
  400.                         friendlyAlias = "plr_new_rank";
  401.                         enemyAlias = "mp_obj_taken";
  402.  
  403.                         if(self.team == "axis")
  404.                             enemy = "allies";
  405.                         else
  406.                             enemy = "axis";
  407.  
  408.                         thread playSoundOnPlayers(friendlyAlias, self.team);
  409.                         thread playSoundOnPlayers(enemyAlias, enemy);
  410.  
  411.                         other.flag returnFlag();
  412.                         other detachFlag(other.flag);
  413.                         other.flag = undefined;
  414.                         other.statusicon = "";
  415.                         other thread unset_sprint();
  416.                        
  417.                         other thread [[level.onXPEvent]]( "capture" );
  418.                         givePlayerScore( "capture", other );
  419.  
  420.                         if(other.pers["team"] == "allies")
  421.                             team = "allies";
  422.                         else
  423.                             team = "axis";
  424.                         [[level._setTeamScore]]( team, [[level._getTeamScore]]( team ) + level.ex_pointsfor_flag );
  425.                        
  426.                         level notify( "update_allhud_score" );
  427.                        
  428.                         lpselfnum = other getEntityNumber();
  429.                         lpselfguid = other getGuid();
  430.                         logPrint("A;" + lpselfguid + ";" + lpselfnum + ";" + other.name + ";" + "ctf_captured_flag" + "\n");
  431.                        
  432.                         checkScoreLimit();
  433.                     }
  434.                 }
  435.                 else // Returned flag
  436.                 {
  437.                     // Returned flag
  438.                     if(self.team == "axis")
  439.                         iprintln( &"EXTREME_RETURNED_AXIS", self.name );
  440.                     else
  441.                         iprintln( &"EXTREME_RETURNED_ALLIES", self.name );
  442.                        
  443.                     friendlyAlias = "mp_obj_returned";
  444.                     thread playSoundOnPlayers(friendlyAlias, self.team);
  445.                     self returnFlag();
  446.  
  447.                     lpselfnum = other getEntityNumber();
  448.                     lpselfguid = other getGuid();
  449.                     logPrint("A;" + lpselfguid + ";" + lpselfnum + ";" + other.name + ";" + "ctf_pickup_own" + "\n");
  450.                 }
  451.             }
  452.             else if(other.pers["team"] != self.team) // Pick Up Flag
  453.             {
  454.                 if(self.team == "axis")
  455.                     iprintln( &"EXTREME_STOLE_ALLIES", other.name );
  456.                 else
  457.                     iprintln( &"EXTREME_STOLE_AXIS", other.name );
  458.  
  459.                 friendlyAlias = "mp_war_objective_lost";
  460.                 enemyAlias = "mp_war_objective_taken";
  461.  
  462.                 if(self.team == "axis")
  463.                     enemy = "allies";
  464.                 else
  465.                     enemy = "axis";
  466.                
  467.                 thread playSoundOnPlayers( friendlyAlias, self.team );
  468.                 thread playSoundOnPlayers( enemyAlias, enemy );
  469.  
  470.                 other pickupFlag( self ); // Stolen flag
  471.                 other thread set_sprint();
  472.                
  473.                 lpselfnum = other getEntityNumber();
  474.                 lpselfguid = other getGuid();
  475.                 logPrint("A;" + lpselfguid + ";" + lpselfnum + ";" + other.name + ";" + "ctf_pickedup_flag" + "\n");
  476.             }
  477.         }
  478.         wait 0.05;
  479.     }
  480. }
  481.  
  482. set_sprint()
  483. {
  484.     if( !level.ex_heavyflag ) return;
  485.    
  486.     while(isdefined(self.flagAttached))
  487.     {
  488.         if(!isdefined(self.flagAttached)) return;
  489.         self AllowSprint(false);
  490.         wait 1;
  491.     }
  492.        
  493. }
  494.  
  495. unset_sprint()
  496. {
  497.     if( !level.ex_heavyflag ) return;
  498.    
  499.     if(!isdefined(self.flagAttached))
  500.         self AllowSprint(true);
  501. }
  502.  
  503. pickupFlag(flag)
  504. {
  505.     flag notify("end_autoreturn");
  506.  
  507.     flag.origin = flag.origin + (0, 0, -10000);
  508.     flag.flagmodel hide();
  509.     self.flag = flag;
  510.    
  511.     if(self.pers["team"] == "allies")
  512.         self.statusicon = level.hudflag_axis;
  513.     else
  514.         self.statusicon = level.hudflag_allies;
  515.  
  516.     self.dont_auto_balance = true;
  517.    
  518.     if(level.ex_objectivepoints)
  519.     {
  520.         flag deleteFlagWaypoint();
  521.         flag createFlagMissingWaypoint();
  522.  
  523.         objective_onEntity(self.flag.objective, self);
  524.         objective_team(self.flag.objective, self.pers["team"]);
  525.     }
  526.  
  527.     self attachFlag();
  528. }
  529.  
  530. attachFlag()
  531. {
  532.     if(isdefined(self.flagAttached))
  533.         return;
  534.  
  535.     if(self.pers["team"] == "allies")
  536.         flagModel = game["prop_flag_carry_axis"];
  537.     else
  538.         flagModel = game["prop_flag_carry_allies"];
  539.    
  540.     self attach(flagModel, "J_Spine4", true);
  541.     self.flagAttached = true;
  542.    
  543.     self thread createHudIcon();
  544. }
  545.  
  546.  
  547. dropFlag()
  548. {
  549.     if(isdefined(self.flag))
  550.     {
  551.         start = self.origin + (0, 0, 10);
  552.         end = start + (0, 0, -2000);
  553.         trace = bulletTrace(start, end, false, undefined);
  554.  
  555.         self.flag.origin = trace["position"];
  556.         self.flag.flagmodel.origin = self.flag.origin;
  557.         self.flag.flagmodel show();
  558.         self.flag.atbase = false;
  559.         self.statusicon = "";
  560.    
  561.         if(level.ex_objectivepoints)
  562.         {
  563.             objective_position(self.flag.objective, self.flag.origin);
  564.             objective_team(self.flag.objective, "none");
  565.             self.flag createFlagWaypoint();
  566.         }
  567.  
  568.         self.flag thread autoReturn();
  569.         self detachFlag(self.flag);
  570.  
  571.         self.flag = undefined;
  572.         self.dont_auto_balance = undefined;
  573.     }
  574. }
  575.  
  576. returnFlag()
  577. {
  578.     self notify("end_autoreturn");
  579.    
  580.     self.status = "home";
  581.  
  582.     self.origin = self.home_origin;
  583.     self.flagmodel.origin = self.home_origin;
  584.     self.flagmodel.angles = self.home_angles;
  585.     self.flagmodel show();
  586.     self.atbase = true;
  587.    
  588.     if(level.ex_objectivepoints)
  589.     {
  590.         objective_position(self.objective, self.origin);
  591.         objective_team(self.objective, "none");
  592.         self createFlagWaypoint();
  593.         self deleteFlagMissingWaypoint();
  594.     }
  595. }
  596.  
  597. autoReturn()
  598. {
  599.     self endon("end_autoreturn");
  600.  
  601.     wait level.ex_flag_returndelay;
  602.     self thread returnFlag();
  603.     level.announce_return = true;
  604.     self thread announce();
  605. }
  606.  
  607. announce()
  608. {
  609.     self notify("end_autoreturn");
  610.  
  611.     if(level.announce_return)
  612.     {
  613.         if(self.team == "axis")
  614.             iprintln(&"EXTREME_RETURNED_BASE_AXIS");
  615.         else
  616.             iprintln(&"EXTREME_RETURNED_BASE_ALLIES");
  617.     }
  618.    
  619.     self thread returnFlag();
  620.     self notify("flag returned");
  621. }
  622.  
  623. detachFlag(flag)
  624. {
  625.     if(!isdefined(self.flagAttached))
  626.         return;
  627.  
  628.     if(flag.team == "allies")
  629.         flagModel = game["prop_flag_carry_allies"];
  630.     else
  631.         flagModel = game["prop_flag_carry_axis"];
  632.        
  633.     self detach(flagModel, "J_Spine4");
  634.     self.flagAttached = undefined;
  635.    
  636.     self.statusicon = "";
  637.    
  638.     self thread deleteHudIcon();
  639. }
  640.  
  641. createHudIcon()
  642. {
  643.     if( !level.ex_objectivepoints ) return;
  644.    
  645.     iconSize = 40;
  646.     icon2Size = 30;
  647.    
  648.     X   = 50;
  649.     Y   = 150;
  650.     X2  = 52;
  651.     Y2  = 148;
  652.    
  653.     if( level.hardcoreMode && !level.ex_hardcore_minimap )
  654.     {
  655.         X   = 30;
  656.         Y   = 30;
  657.         X2  = 32;
  658.         Y2  = 28;
  659.     }
  660.     else if( level.hardcoreMode && level.ex_hardcore_minimap )
  661.     {
  662.         X   = 50;
  663.         Y   = 150;
  664.         X2  = 52;
  665.         Y2  = 148;
  666.     }
  667.  
  668.     self.hud_flagflash = newClientHudElem(self);
  669.     self.hud_flagflash.x = X;
  670.     self.hud_flagflash.y = Y;
  671.     self.hud_flagflash.alignX = "center";
  672.     self.hud_flagflash.alignY = "middle";
  673.     self.hud_flagflash.horzAlign = "left";
  674.     self.hud_flagflash.vertAlign = "top";
  675.     self.hud_flagflash.hideWhenInMenu = true;
  676.     self.hud_flagflash.alpha = 0;
  677.     self.hud_flagflash.sort = 1;
  678.    
  679.     self.hud_flagflash2 = newClientHudElem(self);
  680.     self.hud_flagflash2.x = X2;
  681.     self.hud_flagflash2.y = Y2;
  682.     self.hud_flagflash2.alignX = "center";
  683.     self.hud_flagflash2.alignY = "middle";
  684.     self.hud_flagflash2.horzAlign = "left";
  685.     self.hud_flagflash2.vertAlign = "top";
  686.     self.hud_flagflash2.hideWhenInMenu = true;
  687.     self.hud_flagflash2.alpha = 0;
  688.     self.hud_flagflash2.sort = 2;
  689.  
  690.     if(self.pers["team"] == "allies")
  691.     {
  692.         self.hud_flagflash setShader(level.hudflagflash_axis, iconSize, iconSize);
  693.         self.hud_flagflash2 setShader(level.hudflagflash2_axis, icon2Size, icon2Size);
  694.     }
  695.     else
  696.     {
  697.         assert(self.pers["team"] == "axis");
  698.         self.hud_flagflash setShader(level.hudflagflash_allies, iconSize, iconSize);
  699.         self.hud_flagflash2 setShader(level.hudflagflash2_allies, icon2Size, icon2Size);
  700.     }
  701.    
  702.     self.hud_flagflash fadeOverTime(.2);
  703.     self.hud_flagflash2 fadeOverTime(.2);
  704.     self.hud_flagflash.alpha = 1;
  705.     self.hud_flagflash2.alpha = 1;
  706.  
  707.     wait 180;
  708.    
  709.     if(isdefined(self.hud_flagflash))
  710.     {
  711.         self.hud_flagflash fadeOverTime(1);
  712.         self.hud_flagflash2 fadeOverTime(1);
  713.         self.hud_flagflash.alpha = 0;
  714.         self.hud_flagflash2.alpha = 0;
  715.     }
  716. }
  717.  
  718. deleteHudIcon()
  719. {
  720.     if(isdefined(self.hud_flagflash))
  721.         self.hud_flagflash destroy();
  722.        
  723.     if(isdefined(self.hud_flagflash2))
  724.         self.hud_flagflash2 destroy();
  725. }
  726.  
  727. createFlagWaypoint()
  728. {
  729.     self deleteFlagWaypoint();
  730.  
  731.     waypoint = newHudElem();
  732.     waypoint.x = self.origin[0];
  733.     waypoint.y = self.origin[1];
  734.     waypoint.z = self.origin[2] + 100;
  735.     waypoint.alpha = .71;
  736.     waypoint.isShown = true;
  737.    
  738.     waypoint setShader(self.objpointflag, 8, 8);
  739.  
  740.     waypoint setwaypoint(true);
  741.     self.waypoint_flag = waypoint;
  742. }
  743.  
  744. deleteFlagWaypoint()
  745. {
  746.     if(isdefined(self.waypoint_flag))
  747.         self.waypoint_flag destroy();
  748. }
  749.  
  750. createFlagMissingWaypoint()
  751. {
  752.     self deleteFlagMissingWaypoint();
  753.  
  754.     waypoint = newHudElem();
  755.     waypoint.x = self.home_origin[0];
  756.     waypoint.y = self.home_origin[1];
  757.     waypoint.z = self.home_origin[2] + 100;
  758.     waypoint.alpha = .71;
  759.     waypoint.isShown = true;
  760.  
  761.     waypoint setShader(self.objpointflagmissing, 8, 8);
  762.  
  763.     waypoint setwaypoint(true);
  764.     self.waypoint_base = waypoint;
  765. }
  766.  
  767. deleteFlagMissingWaypoint()
  768. {
  769.     if(isdefined(self.waypoint_base))
  770.         self.waypoint_base destroy();
  771. }
  772.  
  773. isnearFlag()
  774. {
  775.     // determine the opposite teams flag
  776.     if(self.pers["team"] == "allies" )
  777.         myflag = getent("axis_flag", "targetname");
  778.     else
  779.         myflag = getent("allied_flag", "targetname");
  780.  
  781.     // if the flag is not at the base then return false
  782.     if(myflag.home_origin != myflag.origin)
  783.         return false;
  784.        
  785.     dist = distance(myflag.home_origin, self.origin);
  786.    
  787.     // if they were close to the flag then return true
  788.     if(dist < 850)
  789.         return true;
  790.        
  791.     return false;
  792. }
  793.  
  794. isnearCarrier(attacker)
  795. {
  796.     // determine the teams flag
  797.     if(self.pers["team"] == "allies" )
  798.         myflag = getent("allied_flag", "targetname");
  799.     else
  800.         myflag = getent("axis_flag", "targetname");
  801.        
  802.     // if the flag is at the base then return false
  803.     if(myflag.status == "home")
  804.         return false;
  805.    
  806.     // if the attacker is the carrier then return false
  807.     if(isdefined(attacker.flag))
  808.         return false;
  809.        
  810.     // Find the player with the flag
  811.     dist = 9999;
  812.     players = getentarray("player", "classname");
  813.     for(i = 0; i < players.size; i++)
  814.     {
  815.         player = players[i];
  816.  
  817.         if(!isdefined(player.flag))
  818.             continue;
  819.  
  820.         if(player.pers["team"] != attacker.pers["team"])
  821.             continue;
  822.  
  823.         dist = distance(self.origin, player.origin);
  824.     }
  825.    
  826.     // if they were close to the flag carrier then return true
  827.     if(dist < 850)
  828.         return true;
  829.        
  830.     return false;
  831. }

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.