CSHARP 200
Ctfb.gsc Guest on 18th April 2021 07:34:30 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.     Based on COD2 CTFb by Matthias - admiral mod.
  7.     12/17/2007
  8. */
  9.  
  10. main()
  11. {
  12.     if(getdvar("mapname") == "mp_background")
  13.         return;
  14.    
  15.     maps\mp\gametypes\_setupmaps::init();
  16.     maps\mp\gametypes\_globallogic::init();
  17.     maps\mp\gametypes\_callbacksetup::SetupCallbacks();
  18.     maps\mp\gametypes\_globallogic::SetupCallbacks();
  19.     if(level.ex_blackscreen) maps\mp\gametypes\_blackscreen::init();
  20.    
  21.     maps\mp\gametypes\_globallogic::registerTimeLimitDvar( "ctfb", 2, 0, 1440 );
  22.     maps\mp\gametypes\_globallogic::registerScoreLimitDvar( "ctfb", 500, 0, 5000 );
  23.     maps\mp\gametypes\_globallogic::registerRoundLimitDvar( "ctfb", 1, 0, 99 );
  24.     maps\mp\gametypes\_globallogic::registerNumLivesDvar( "ctfb", 0, 0, 99 );
  25.    
  26.     level.ex_heavyflag      = extreme\_ex_utils::dvardef("scr_ctfb_heavyflag", 1, 0, 1, "int");
  27.     level.ex_flag_returndelay   = extreme\_ex_utils::dvardef("scr_ctfb_returnflag_delay", 60, 0, 200, "int");
  28.     level.ex_pointsfor_flag     = extreme\_ex_utils::dvardef("scr_ctfb_pointsfor_flag", 10, 0, 99, "int");
  29.  
  30.     level.teamBased = true;
  31.     level.overrideTeamScore = true;
  32.     level.onStartGameType = ::onStartGameType;
  33.     level.onSpawnPlayer = ::onSpawnPlayer;
  34.     level.onPlayerKilled = ::onPlayerKilled;
  35.     level.onPlayerDisconnect = ::onPlayerDisconnect;
  36.    
  37.     game["dialog"]["gametype"] = "Capture_the_Flag_back";
  38. }
  39.  
  40. GetSpawns()
  41. {
  42.     if(getDvar("mapname") == "mp_pk_harbor") return true;
  43.     if(getDvar("mapname") == "mp_qmx_matmata") return true;
  44.    
  45.     return false;
  46. }
  47.  
  48. onStartGameType()
  49. {
  50.     setClientNameMode("auto_change");
  51.    
  52.     level.spawnpoints_needed = GetSpawns();
  53.  
  54.     maps\mp\gametypes\_globallogic::setObjectiveText( "allies", &"MISC_CTF" );
  55.     maps\mp\gametypes\_globallogic::setObjectiveText( "axis", &"MISC_CTF" );
  56.     maps\mp\gametypes\_globallogic::setObjectiveScoreText( "allies", &"MISC_CTF_SCORE" );
  57.     maps\mp\gametypes\_globallogic::setObjectiveScoreText( "axis", &"MISC_CTF_SCORE" );
  58.     maps\mp\gametypes\_globallogic::setObjectiveHintText( "allies", &"MISC_CTF_HINT" );
  59.     maps\mp\gametypes\_globallogic::setObjectiveHintText( "axis", &"MISC_CTF_HINT" );
  60.    
  61.     level.spawnMins = ( 0, 0, 0 );
  62.     level.spawnMaxs = ( 0, 0, 0 ); 
  63.  
  64.     if(level.spawnpoints_needed)
  65.     {
  66.         level.custom_spawnpoints = true;
  67.        
  68.         maps\mp\gametypes\_spawnlogic::placeSpawnpoints( "mp_ctf_spawn_allies_start" );
  69.         maps\mp\gametypes\_spawnlogic::placeSpawnpoints( "mp_ctf_spawn_axis_start" );
  70.         maps\mp\gametypes\_spawnlogic::addSpawnPoints("allies", "mp_ctf_spawn_allies");
  71.         maps\mp\gametypes\_spawnlogic::addSpawnPoints("axis", "mp_ctf_spawn_axis");
  72.    
  73.     }
  74.     else
  75.     {
  76.         level.custom_spawnpoints = false;
  77.        
  78.         maps\mp\gametypes\_spawnlogic::placeSpawnPoints( "mp_sab_spawn_allies_start" );
  79.         maps\mp\gametypes\_spawnlogic::placeSpawnPoints( "mp_sab_spawn_axis_start" );
  80.         maps\mp\gametypes\_spawnlogic::addSpawnPoints( "allies", "mp_sab_spawn_allies" );
  81.         maps\mp\gametypes\_spawnlogic::addSpawnPoints( "axis", "mp_sab_spawn_axis" );
  82.     }
  83.    
  84.     level.mapCenter = maps\mp\gametypes\_spawnlogic::findBoxCenter( level.spawnMins, level.spawnMaxs );
  85.     setMapCenter( level.mapCenter );
  86.  
  87.     if(level.spawnpoints_needed)
  88.     {
  89.         level.spawn_axis            = getentarray("mp_ctf_spawn_axis", "targetname");
  90.         level.spawn_allies          = getentarray("mp_ctf_spawn_allies", "targetname");
  91.         level.spawn_axis_start      = getentarray("mp_ctf_spawn_axis_start", "targetname");
  92.         level.spawn_allies_start    = getentarray("mp_ctf_spawn_allies_start", "targetname");  
  93.     }
  94.     else
  95.     {
  96.         level.spawn_axis            = getentarray("mp_sab_spawn_axis", "classname");
  97.         level.spawn_allies          = getentarray("mp_sab_spawn_allies", "classname");
  98.         level.spawn_axis_start      = getentarray("mp_sab_spawn_axis_start", "classname");
  99.         level.spawn_allies_start    = getentarray("mp_sab_spawn_allies_start", "classname");
  100.     }
  101.    
  102.     allowed[0] = "ctfb";
  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.     self dropOwnFlag();
  242. }
  243.  
  244. onPlayerKilled( eInflictor, attacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, psOffsetTime, deathAnimDuration )
  245. {
  246.     if(isdefined(self.ownflagAttached))
  247.         self dropOwnFlag();
  248.     else
  249.         self dropFlag();
  250.        
  251.     self unset_sprint();
  252.    
  253.     if(isPlayer(attacker))
  254.     {
  255.         doKillcam = true;
  256.            
  257.         if(self.pers["team"] != attacker.pers["team"])
  258.         {  
  259.             gave_points = false;
  260.                    
  261.             // if the dead person was close to the flag then give the killer a defense bonus
  262.             if(self isnearFlag())
  263.             {
  264.                 // let everyone know
  265.                 if(attacker.pers["team"] == "axis" )
  266.                     iprintln(&"EXTREME_DEFENDED_AXIS", attacker.name);
  267.                 else
  268.                     iprintln(&"EXTREME_DEFENDED_ALLIES", attacker.name);
  269.                        
  270.                 attacker thread [[level.onXPEvent]]( "defend" );
  271.                 givePlayerScore( "defend", attacker );
  272.                
  273.                 gave_points = true;
  274.                 lpattacknum = attacker getEntityNumber();
  275.                 lpattackguid = attacker getGuid();
  276.  
  277.                 logPrint("A;" + lpattackguid + ";" + lpattacknum + ";" + attacker.pers["team"] + ";" + attacker.name + ";" + "ctf_defended" + "\n");
  278.             }
  279.                    
  280.             // if the dead person was close to the flag carrier then give the killer a assist bonus
  281.             if(self isnearCarrier(attacker))
  282.             {
  283.                 // let everyone know
  284.                 if(attacker.pers["team"] == "axis" )
  285.                     iprintln( &"EXTREME_ASSISTED_AXIS", attacker.name);
  286.                 else
  287.                     iprintln(&"EXTREME_ASSISTED_ALLIES", attacker.name);
  288.                        
  289.                 attacker thread [[level.onXPEvent]]( "assist" );
  290.                 givePlayerScore( "assist", attacker );
  291.                
  292.                 gave_points = true;
  293.                 lpattacknum = attacker getEntityNumber();
  294.                 lpattackguid = attacker getGuid();
  295.                 logPrint("A;" + lpattackguid + ";" + lpattacknum + ";" + attacker.pers["team"] + ";" + attacker.name + ";" + "ctf_assist" + "\n");
  296.             }
  297.         }
  298.     }
  299. }
  300.  
  301.  
  302. onEndGame( winningTeam )
  303. {
  304.     if ( isdefined( winningTeam ) && (winningTeam == "allies" || winningTeam == "axis") )
  305.         [[level._setTeamScore]]( winningTeam, [[level._getTeamScore]]( winningTeam ) + level.ex_pointsfor_flag );  
  306. }
  307.  
  308. initFlags()
  309. {
  310.  
  311.     maperrors = [];
  312.  
  313.     allied_flags = getentarray("allied_flag", "targetname");
  314.     if(allied_flags.size < 1)
  315.         maperrors[maperrors.size] = "^1No entities found with \"targetname\" \"allied_flag\"";
  316.     else if(allied_flags.size > 1)
  317.         maperrors[maperrors.size] = "^1More than 1 entity found with \"targetname\" \"allied_flag\"";
  318.  
  319.     axis_flags = getentarray("axis_flag", "targetname");
  320.     if(axis_flags.size < 1)
  321.         maperrors[maperrors.size] = "^1No entities found with \"targetname\" \"axis_flag\"";
  322.     else if(axis_flags.size > 1)
  323.         maperrors[maperrors.size] = "^1More than 1 entity found with \"targetname\" \"axis_flag\"";
  324.  
  325.     if(maperrors.size)
  326.     {
  327.         println("^1------------ Map Errors ------------");
  328.         for(i = 0; i < maperrors.size; i++)
  329.             println(maperrors[i]);
  330.         println("^1------------------------------------");
  331.  
  332.         return;
  333.     }
  334.  
  335.     allied_flag = getent("allied_flag", "targetname");
  336.     allied_flag.home_origin = allied_flag.origin;
  337.     allied_flag.home_angles = allied_flag.angles;
  338.     allied_flag.flagmodel = spawn("script_model", allied_flag.home_origin);
  339.     allied_flag.flagmodel.angles = allied_flag.home_angles;
  340.     allied_flag.flagmodel setmodel(game["prop_flag_allies"]);
  341.    
  342.     allied_flag.basemodel = spawn("script_model", allied_flag.home_origin + (-19, 0, 15));
  343.     allied_flag.basemodel.angles = allied_flag.home_angles ;
  344.     allied_flag.basemodel setmodel(game["prop_flag_base"]);
  345.    
  346.     allied_flag.team = "allies";
  347.     allied_flag.atbase = true;
  348.     allied_flag.objective = 0;
  349.     allied_flag.compassflag = level.compassflag_allies;
  350.     allied_flag.objpointflag = level.objpointflag_allies;
  351.     allied_flag.objpointflagmissing = level.objpointflagmissing_allies;
  352.     allied_flag thread flag();
  353.  
  354.     axis_flag = getent("axis_flag", "targetname");
  355.     axis_flag.home_origin = axis_flag.origin;
  356.     axis_flag.home_angles = axis_flag.angles;
  357.     axis_flag.flagmodel = spawn("script_model", axis_flag.home_origin);
  358.     axis_flag.flagmodel.angles = axis_flag.home_angles;
  359.     axis_flag.flagmodel setmodel(game["prop_flag_axis"]);
  360.    
  361.     axis_flag.basemodel = spawn("script_model", axis_flag.home_origin + (-19, 0, 15));
  362.     axis_flag.basemodel.angles = axis_flag.home_angles ;
  363.     axis_flag.basemodel setmodel(game["prop_flag_base"]);  
  364.    
  365.     axis_flag.team = "axis";
  366.     axis_flag.atbase = true;
  367.     axis_flag.objective = 1;
  368.     axis_flag.compassflag = level.compassflag_axis;
  369.     axis_flag.objpointflag = level.objpointflag_axis;
  370.     axis_flag.objpointflagmissing = level.objpointflagmissing_axis;
  371.     axis_flag thread flag();
  372.    
  373. }
  374.  
  375. flag()
  376. {
  377.     if(level.ex_objectivepoints)
  378.     {
  379.         objective_add(self.objective, "current", self.origin, self.compassflag);
  380.         self createFlagWaypoint();
  381.     }
  382.    
  383.     self.status = "home";
  384.    
  385.     for(;;)
  386.     {
  387.         self waittill("trigger", other);
  388.  
  389.         if(isPlayer(other) && isAlive(other) && (other.pers["team"] != "spectator"))
  390.         {
  391.             team = other.pers["team"];
  392.            
  393.             if(other.pers["team"] == self.team)
  394.             {
  395.                 if(self.atbase)
  396.                 {
  397.                     if(isdefined(other.flag))
  398.                     {
  399.                         if(self.team == "axis")
  400.                             iprintln( &"EXTREME_CAPTURED_AXIS", other.name );
  401.                         else
  402.                             iprintln( &"EXTREME_CAPTURED_ALLIES", other.name );
  403.  
  404.                         friendlyAlias = "plr_new_rank";
  405.                         enemyAlias = "mp_obj_taken";
  406.  
  407.                         if(self.team == "axis")
  408.                             enemy = "allies";
  409.                         else
  410.                             enemy = "axis";
  411.  
  412.                         thread playSoundOnPlayers(friendlyAlias, self.team);
  413.                         thread playSoundOnPlayers(enemyAlias, enemy);
  414.  
  415.                         other.flag returnFlag();
  416.                         other detachFlag(other.flag);
  417.                         other.flag = undefined;
  418.                         other.statusicon = "";
  419.                         other thread unset_sprint();
  420.                        
  421.                         other thread [[level.onXPEvent]]( "capture" );
  422.                         givePlayerScore( "capture", other );
  423.  
  424.                         if(other.pers["team"] == "allies")
  425.                             team = "allies";
  426.                         else
  427.                             team = "axis";
  428.                         [[level._setTeamScore]]( team, [[level._getTeamScore]]( team ) + level.ex_pointsfor_flag );
  429.                        
  430.                         level notify( "update_allhud_score" );
  431.                        
  432.                         lpselfnum = other getEntityNumber();
  433.                         lpselfguid = other getGuid();
  434.                         logPrint("A;" + lpselfguid + ";" + lpselfnum + ";" + other.name + ";" + "ctfb_captured_flag" + "\n");
  435.                        
  436.                         checkScoreLimit();
  437.                     }
  438.                 }
  439.                 else // Returned flag
  440.                 {
  441.                    
  442.                     if(!isdefined(other.enemyflagAttached))
  443.                     {
  444.                         friendlyAlias = "mp_obj_returned";
  445.                         thread playSoundOnPlayers(friendlyAlias, self.team);
  446.                        
  447.                         other pickupOwnFlag(self);
  448.                         other thread checkBaseHomeOwnFlag(self);
  449.                     }
  450.                    
  451.                     lpselfnum = other getEntityNumber();
  452.                     lpselfguid = other getGuid();
  453.                     logPrint("A;" + lpselfguid + ";" + lpselfnum + ";" + other.name + ";" + "ctfb_pickup_own" + "\n");
  454.                 }
  455.             }
  456.             else if(other.pers["team"] != self.team) // Pick Up Flag
  457.             {
  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.                 if(!isdefined(other.ownflagAttached))
  468.                 {
  469.                     if(self.team == "axis")
  470.                         iprintln( &"EXTREME_STOLE_ALLIES", other.name );
  471.                     else
  472.                         iprintln( &"EXTREME_STOLE_AXIS", other.name );
  473.                    
  474.                     thread playSoundOnPlayers( friendlyAlias, self.team );
  475.                     thread playSoundOnPlayers( enemyAlias, enemy );
  476.  
  477.                     other pickupFlag( self ); // Stolen flag
  478.                     other thread set_sprint();
  479.                 }
  480.                
  481.                 lpselfnum = other getEntityNumber();
  482.                 lpselfguid = other getGuid();
  483.                 logPrint("A;" + lpselfguid + ";" + lpselfnum + ";" + other.name + ";" + "ctfb_pickedup_flag" + "\n");
  484.             }
  485.         }
  486.         wait 0.05;
  487.     }
  488. }
  489.  
  490. set_sprint()
  491. {
  492.     if( !level.ex_heavyflag ) return;
  493.    
  494.     while(1)
  495.     {
  496.         if(!isdefined(self.flagAttached)) return;
  497.         self AllowSprint(false);
  498.         wait 1;
  499.     }
  500.        
  501. }
  502.  
  503. unset_sprint()
  504. {
  505.     if( !level.ex_heavyflag ) return;
  506.    
  507.     if(!isdefined(self.flagAttached))
  508.         self AllowSprint(true);
  509. }
  510.  
  511. checkBaseHomeOwnFlag(flag)
  512. {
  513.     self endon("disconnect");
  514.     self endon("killed_player");
  515.    
  516.     self notify("checkBase");
  517.     self endon("checkBase");
  518.  
  519.     while(isDefined(flag))
  520.     {
  521.         wait 0.3;
  522.        
  523.         if(isDefined(flag) && (self.sessionstate == "playing") && (distance(flag.home_origin, self.origin) < 50))
  524.         {
  525.         //  if(!isdefined(self.ownflagAttached)) break;
  526.        
  527.             // Returned flag
  528.             if(self.pers["team"] == "axis")
  529.                 iprintln( &"EXTREME_RETURNED_AXIS", self.name );
  530.             else
  531.                 iprintln( &"EXTREME_RETURNED_ALLIES", self.name );
  532.                
  533.             friendlyAlias = "mp_capture_flag";
  534.             self PlaySoundToPlayer( friendlyAlias, self );
  535.  
  536.             flag returnFlag();
  537.             self detachOwnFlag(flag);
  538.             self.ownflag = undefined;
  539.             self.statusicon = "";
  540.            
  541.             self thread unset_sprint();
  542.             self thread [[level.onXPEvent]]( "return" );
  543.             givePlayerScore( "return", self );
  544.             level notify( "update_allhud_score" );
  545.  
  546.             lpselfnum = self getEntityNumber();
  547.             lpselfguid = self getGuid ();
  548.             logPrint("A;" + lpselfguid + ";" + lpselfnum + ";" + self.name + ";" + "ctf_returned_flag" + "\n");
  549.            
  550.             break;
  551.         }
  552.     }  
  553. }
  554.  
  555. pickupFlag(flag)
  556. {
  557.     flag notify("end_autoreturn");
  558.  
  559.     flag.origin = flag.origin + (0, 0, -10000);
  560.     flag.flagmodel hide();
  561.     self.flag = flag;
  562.    
  563.     flag.carrier = self;
  564.    
  565.     if(self.pers["team"] == "allies")
  566.         self.statusicon = level.hudflag_axis;
  567.     else
  568.         self.statusicon = level.hudflag_allies;
  569.  
  570.     self.dont_auto_balance = true;
  571.    
  572.     if(level.ex_objectivepoints)
  573.     {
  574.         flag deleteFlagWaypoint();
  575.         flag createFlagMissingWaypoint();
  576.  
  577.         objective_onEntity(self.flag.objective, self);
  578.         objective_team(self.flag.objective, self.pers["team"]);
  579.     }
  580.  
  581.     self attachFlag();
  582. }
  583.  
  584. pickupOwnFlag(flag)
  585. {
  586.     self endon("disconnect");
  587.  
  588.     flag notify("end_autoreturn");
  589.  
  590.     flag.origin = flag.origin + (0, 0, -10000);
  591.     flag.flagmodel hide();
  592.     self.ownflag = flag;
  593.    
  594.     flag.carrier = self;
  595.  
  596.     if(!isdefined(self.flag))
  597.     {
  598.         if(self.pers["team"] == "allies")
  599.             self.statusicon = level.hudflag_allies;
  600.         else
  601.             self.statusicon = level.hudflag_axis;
  602.     }
  603.  
  604.     if(self.ownflag.team == "axis")
  605.         self iprintln( &"EXTREME_TAKEN_BACK_AXIS", self.name );
  606.     else
  607.         self iprintln( &"EXTREME_TAKEN_BACK_ALLIES", self.name );
  608.  
  609.     self.dont_auto_balance = true;
  610.    
  611.     if(level.ex_objectivepoints)
  612.     {
  613.         flag deleteFlagWaypoint();
  614.         objective_onEntity(flag.objective, self);
  615.         objective_team(flag.objective, self.pers["team"]);
  616.     }
  617.  
  618.     self attachOwnFlag();
  619. }
  620.  
  621. attachFlag()
  622. {
  623.     self endon ("disconnect");
  624.    
  625.     if(isdefined(self.enemyflagAttached))
  626.         return;
  627.    
  628.     if(self.pers["team"] == "allies")
  629.         flagModel = game["prop_flag_carry_axis"];
  630.     else
  631.         flagModel = game["prop_flag_carry_allies"];
  632.        
  633.     self attach(flagModel, "J_Spine4", true);
  634.    
  635.     self.enemyflagAttached = true;
  636.     self.flagAttached = true;
  637.    
  638.     self thread createHudIcon();
  639. }
  640.  
  641. attachOwnFlag()
  642. {
  643.     self endon("disconnect");
  644.  
  645.     if(isdefined(self.ownflagAttached))
  646.         return;
  647.  
  648.     if(self.pers["team"] == "axis")
  649.         flagModel = game["prop_flag_carry_axis"];
  650.     else
  651.         flagModel = game["prop_flag_carry_allies"];
  652.        
  653.     self attach(flagModel, "J_Spine4", true);
  654.    
  655.     self.ownflagAttached = true;
  656.     self.flagAttached = true;
  657.    
  658.     self thread createOwnHudIcon();
  659. }
  660.  
  661. dropFlag()
  662. {
  663.     if(isdefined(self.flag))
  664.     {
  665.         start = self.origin + (0, 0, 10);
  666.         end = start + (0, 0, -2000);
  667.         trace = bulletTrace(start, end, false, undefined);
  668.  
  669.         self.flag.origin = trace["position"];
  670.         self.flag.flagmodel.origin = self.flag.origin;
  671.         self.flag.flagmodel show();
  672.         self.flag.atbase = false;
  673.         self.statusicon = "";
  674.        
  675.         self.flag.carrier = undefined;
  676.    
  677.         if(level.ex_objectivepoints)
  678.         {
  679.             objective_position(self.flag.objective, self.flag.origin);
  680.             objective_team(self.flag.objective, "none");
  681.             self.flag createFlagWaypoint();
  682.         }
  683.  
  684.         self.flag thread autoReturn();
  685.         self detachFlag(self.flag);
  686.  
  687.         self.flag = undefined;
  688.         self.dont_auto_balance = undefined;
  689.     }
  690. }
  691.  
  692. dropOwnFlag()
  693. {
  694.        
  695.     if(isdefined(self.ownflag))
  696.     {
  697.         start = self.origin + (0, 0, 10);
  698.         end = start + (0, 0, -2000);
  699.         trace = bulletTrace(start, end, false, undefined);
  700.  
  701.         self.ownflag.origin = trace["position"] + (randomint(20),randomint(20),0);
  702.         self.ownflag.flagmodel.origin = self.ownflag.origin;
  703.         self.ownflag.flagmodel show();
  704.         self.ownflag.atbase = false;
  705.         self.statusicon = "";
  706.  
  707.         self.ownflag.carrier = undefined;
  708.    
  709.         if(level.ex_objectivepoints)
  710.         {
  711.             objective_position(self.ownflag.objective, self.ownflag.origin);
  712.             objective_team(self.ownflag.objective, "none");
  713.             self.ownflag createFlagWaypoint();
  714.            
  715.         }
  716.        
  717.         self detachOwnFlag(self.ownflag);
  718.         self.ownflag thread autoReturn();
  719.  
  720.         if(self.ownflag.team == "axis")
  721.             iprintln( &"EXTREME_DROPPED_AXIS" );
  722.         else   
  723.             iprintln( &"EXTREME_DROPPED_ALLIES" );
  724.  
  725.         self.ownflag = undefined;
  726.         self.dont_auto_balance = undefined;
  727.     }
  728. }
  729.  
  730. returnFlag()
  731. {
  732.     self notify("end_autoreturn");
  733.    
  734.     self.status = "home";
  735.  
  736.     self.origin = self.home_origin;
  737.     self.flagmodel.origin = self.home_origin;
  738.     self.flagmodel.angles = self.home_angles;
  739.     self.flagmodel show();
  740.     self.atbase = true;
  741.    
  742.     self.carrier = undefined;
  743.    
  744.     if(level.ex_objectivepoints)
  745.     {
  746.         objective_position(self.objective, self.origin);
  747.         objective_team(self.objective, "none");
  748.         self createFlagWaypoint();
  749.         self deleteFlagMissingWaypoint();
  750.     }
  751. }
  752.  
  753. autoReturn()
  754. {
  755.     self endon("end_autoreturn");
  756.  
  757.     wait level.ex_flag_returndelay;
  758.     self thread returnFlag();
  759.     level.announce_return = true;
  760.     self thread announce();
  761. }
  762.  
  763. announce()
  764. {
  765.     self notify("end_autoreturn");
  766.  
  767.     if(level.announce_return)
  768.     {
  769.         if(self.team == "axis")
  770.             iprintln(&"EXTREME_RETURNED_BASE_AXIS");
  771.         else
  772.             iprintln(&"EXTREME_RETURNED_BASE_ALLIES");
  773.     }
  774.    
  775.     self thread returnFlag();
  776.     self notify("flag returned");
  777. }
  778.  
  779. detachFlag(flag)
  780. {
  781.     self endon ("disconnect");
  782.    
  783.     if(!isdefined(self.enemyflagAttached))
  784.         return;
  785.  
  786.     if(flag.team == "allies")
  787.         flagModel = game["prop_flag_carry_allies"];
  788.     else
  789.         flagModel = game["prop_flag_carry_axis"];
  790.        
  791.     self detach(flagModel, "J_Spine4");
  792.     self.enemyflagAttached = undefined;
  793.    
  794.     if(!isdefined(self.ownflagAttached))
  795.         self.flagAttached = undefined;
  796.    
  797.     self.statusicon = "";
  798.    
  799.     self thread deleteHudIcon();
  800. }
  801.  
  802. detachOwnFlag(flag)
  803. {
  804.     self endon ("disconnect");
  805.  
  806.     if(!isdefined(self.ownflagAttached))
  807.         return;
  808.  
  809.     if(self.pers["team"] == "axis")
  810.         flagModel = game["prop_flag_carry_axis"];
  811.     else
  812.         flagModel = game["prop_flag_carry_allies"];
  813.        
  814.     self detach(flagModel, "J_Spine4");
  815.     self.ownflagAttached = undefined;
  816.  
  817.     if(!isdefined(self.enemyflagAttached))
  818.         self.flagAttached = undefined;
  819.    
  820.     self.statusicon = "";
  821.    
  822.     self thread deleteOwnHudIcon();
  823. }
  824.  
  825. createHudIcon()
  826. {
  827.     if( !level.ex_objectivepoints ) return;
  828.    
  829.     iconSize = 40;
  830.     icon2Size = 30;
  831.    
  832.     X   = 50;
  833.     Y   = 150;
  834.     X2  = 52;
  835.     Y2  = 148;
  836.    
  837.     if( level.hardcoreMode && !level.ex_hardcore_minimap )
  838.     {
  839.         X   = 30;
  840.         Y   = 30;
  841.         X2  = 32;
  842.         Y2  = 28;
  843.     }
  844.     else if( level.hardcoreMode && level.ex_hardcore_minimap )
  845.     {
  846.         X   = 50;
  847.         Y   = 150;
  848.         X2  = 52;
  849.         Y2  = 148;
  850.     }
  851.  
  852.     self.hud_flagflash = newClientHudElem(self);
  853.     self.hud_flagflash.x = X;
  854.     self.hud_flagflash.y = Y;
  855.     self.hud_flagflash.alignX = "center";
  856.     self.hud_flagflash.alignY = "middle";
  857.     self.hud_flagflash.horzAlign = "left";
  858.     self.hud_flagflash.vertAlign = "top";
  859.     self.hud_flagflash.hideWhenInMenu = true;
  860.     self.hud_flagflash.alpha = 0;
  861.     self.hud_flagflash.sort = 1;
  862.    
  863.     self.hud_flagflash2 = newClientHudElem(self);
  864.     self.hud_flagflash2.x = X2;
  865.     self.hud_flagflash2.y = Y2;
  866.     self.hud_flagflash2.alignX = "center";
  867.     self.hud_flagflash2.alignY = "middle";
  868.     self.hud_flagflash2.horzAlign = "left";
  869.     self.hud_flagflash2.vertAlign = "top";
  870.     self.hud_flagflash2.hideWhenInMenu = true;
  871.     self.hud_flagflash2.alpha = 0;
  872.     self.hud_flagflash2.sort = 2;
  873.  
  874.     if(self.pers["team"] == "allies")
  875.     {
  876.         self.hud_flagflash setShader(level.hudflagflash_axis, iconSize, iconSize);
  877.         self.hud_flagflash2 setShader(level.hudflagflash2_axis, icon2Size, icon2Size);
  878.     }
  879.     else
  880.     {
  881.         assert(self.pers["team"] == "axis");
  882.         self.hud_flagflash setShader(level.hudflagflash_allies, iconSize, iconSize);
  883.         self.hud_flagflash2 setShader(level.hudflagflash2_allies, icon2Size, icon2Size);
  884.     }
  885.    
  886.     self.hud_flagflash fadeOverTime(.2);
  887.     self.hud_flagflash2 fadeOverTime(.2);
  888.     self.hud_flagflash.alpha = 1;
  889.     self.hud_flagflash2.alpha = 1;
  890.  
  891.     wait 180;
  892.    
  893.     if(isdefined(self.hud_flagflash))
  894.     {
  895.         self.hud_flagflash fadeOverTime(1);
  896.         self.hud_flagflash2 fadeOverTime(1);
  897.         self.hud_flagflash.alpha = 0;
  898.         self.hud_flagflash2.alpha = 0;
  899.     }
  900. }
  901.  
  902. createOwnHudIcon()
  903. {
  904.     if( !level.ex_objectivepoints ) return;
  905.    
  906.     iconSize = 40;
  907.     icon2Size = 30;
  908.    
  909.     X   = 50;
  910.     Y   = 150;
  911.     X2  = 52;
  912.     Y2  = 148;
  913.    
  914.     if( level.hardcoreMode && !level.ex_hardcore_minimap )
  915.     {
  916.         X   = 30;
  917.         Y   = 30;
  918.         X2  = 32;
  919.         Y2  = 28;
  920.     }
  921.     else if( level.hardcoreMode && level.ex_hardcore_minimap )
  922.     {
  923.         X   = 50;
  924.         Y   = 150;
  925.         X2  = 52;
  926.         Y2  = 148;
  927.     }
  928.  
  929.     self.hud_flagflashOwn = newClientHudElem(self);
  930.     self.hud_flagflashOwn.x = X;
  931.     self.hud_flagflashOwn.y = Y;
  932.     self.hud_flagflashOwn.alignX = "center";
  933.     self.hud_flagflashOwn.alignY = "middle";
  934.     self.hud_flagflashOwn.horzAlign = "left";
  935.     self.hud_flagflashOwn.vertAlign = "top";
  936.     self.hud_flagflashOwn.hideWhenInMenu = true;
  937.     self.hud_flagflashOwn.alpha = 0;
  938.     self.hud_flagflashOwn.sort = 1;
  939.    
  940.     self.hud_flagflashOwn2 = newClientHudElem(self);
  941.     self.hud_flagflashOwn2.x = X2;
  942.     self.hud_flagflashOwn2.y = Y2;
  943.     self.hud_flagflashOwn2.alignX = "center";
  944.     self.hud_flagflashOwn2.alignY = "middle";
  945.     self.hud_flagflashOwn2.horzAlign = "left";
  946.     self.hud_flagflashOwn2.vertAlign = "top";
  947.     self.hud_flagflashOwn2.hideWhenInMenu = true;
  948.     self.hud_flagflashOwn2.alpha = 0;
  949.     self.hud_flagflashOwn2.sort = 2;
  950.  
  951.     if(self.pers["team"] == "allies")
  952.     {
  953.         self.hud_flagflashOwn setShader(level.hudflagflash_allies, iconSize, iconSize);
  954.         self.hud_flagflashOwn2 setShader(level.hudflagflash2_allies, icon2Size, icon2Size);
  955.     }
  956.     else
  957.     {
  958.         assert(self.pers["team"] == "axis");
  959.         self.hud_flagflashOwn setShader(level.hudflagflash_axis, iconSize, iconSize);
  960.         self.hud_flagflashOwn2 setShader(level.hudflagflash2_axis, icon2Size, icon2Size);
  961.     }
  962.    
  963.     self.hud_flagflashOwn fadeOverTime(.2);
  964.     self.hud_flagflashOwn2 fadeOverTime(.2);
  965.     self.hud_flagflashOwn.alpha = 1;
  966.     self.hud_flagflashOwn2.alpha = 1;
  967.  
  968.     wait 180;
  969.    
  970.     if(isdefined(self.hud_flagflashOwn))
  971.     {
  972.         self.hud_flagflashOwn fadeOverTime(1);
  973.         self.hud_flagflashOwn2 fadeOverTime(1);
  974.         self.hud_flagflashOwn.alpha = 0;
  975.         self.hud_flagflashOwn2.alpha = 0;
  976.     }
  977. }
  978.  
  979. deleteHudIcon()
  980. {
  981.     if(isdefined(self.hud_flagflash))
  982.         self.hud_flagflash destroy();
  983.        
  984.     if(isdefined(self.hud_flagflash2))
  985.         self.hud_flagflash2 destroy();
  986. }
  987.  
  988. deleteOwnHudIcon()
  989. {
  990.     if(isdefined(self.hud_flagflashOwn))
  991.         self.hud_flagflashOwn destroy();
  992.        
  993.     if(isdefined(self.hud_flagflashOwn2))
  994.         self.hud_flagflashOwn2 destroy();
  995. }
  996.  
  997. createFlagWaypoint()
  998. {
  999.     self deleteFlagWaypoint();
  1000.  
  1001.     waypoint = newHudElem();
  1002.     waypoint.x = self.origin[0];
  1003.     waypoint.y = self.origin[1];
  1004.     waypoint.z = self.origin[2] + 100;
  1005.     waypoint.alpha = .71;
  1006.     waypoint.isShown = true;
  1007.    
  1008.     waypoint setShader(self.objpointflag, 8, 8);
  1009.  
  1010.     waypoint setwaypoint(true);
  1011.     self.waypoint_flag = waypoint;
  1012. }
  1013.  
  1014. deleteFlagWaypoint()
  1015. {
  1016.     if(isdefined(self.waypoint_flag))
  1017.         self.waypoint_flag destroy();
  1018. }
  1019.  
  1020. createFlagMissingWaypoint()
  1021. {
  1022.     self deleteFlagMissingWaypoint();
  1023.  
  1024.     waypoint = newHudElem();
  1025.     waypoint.x = self.home_origin[0];
  1026.     waypoint.y = self.home_origin[1];
  1027.     waypoint.z = self.home_origin[2] + 100;
  1028.     waypoint.alpha = .71;
  1029.     waypoint.isShown = true;
  1030.  
  1031.     waypoint setShader(self.objpointflagmissing, 8, 8);
  1032.  
  1033.     waypoint setwaypoint(true);
  1034.     self.waypoint_base = waypoint;
  1035. }
  1036.  
  1037. deleteFlagMissingWaypoint()
  1038. {
  1039.     if(isdefined(self.waypoint_base))
  1040.         self.waypoint_base destroy();
  1041. }
  1042.  
  1043. isnearFlag()
  1044. {
  1045.     // determine the opposite teams flag
  1046.     if(self.pers["team"] == "allies" )
  1047.         myflag = getent("axis_flag", "targetname");
  1048.     else
  1049.         myflag = getent("allied_flag", "targetname");
  1050.  
  1051.     // if the flag is not at the base then return false
  1052.     if(myflag.home_origin != myflag.origin)
  1053.         return false;
  1054.        
  1055.     dist = distance(myflag.home_origin, self.origin);
  1056.    
  1057.     // if they were close to the flag then return true
  1058.     if(dist < 850)
  1059.         return true;
  1060.        
  1061.     return false;
  1062. }
  1063.  
  1064. isnearCarrier(attacker)
  1065. {
  1066.     // determine the teams flag
  1067.     if(self.pers["team"] == "allies" )
  1068.         myflag = getent("allied_flag", "targetname");
  1069.     else
  1070.         myflag = getent("axis_flag", "targetname");
  1071.        
  1072.     // if the flag is at the base then return false
  1073.     if(myflag.status == "home")
  1074.         return false;
  1075.    
  1076.     // if the attacker is the carrier then return false
  1077.     if(isdefined(attacker.flag))
  1078.         return false;
  1079.        
  1080.     // Find the player with the flag
  1081.     dist = 9999;
  1082.     players = getentarray("player", "classname");
  1083.     for(i = 0; i < players.size; i++)
  1084.     {
  1085.         player = players[i];
  1086.  
  1087.         if(!isdefined(player.flag))
  1088.             continue;
  1089.  
  1090.         if(player.pers["team"] != attacker.pers["team"])
  1091.             continue;
  1092.  
  1093.         dist = distance(self.origin, player.origin);
  1094.     }
  1095.    
  1096.     // if they were close to the flag carrier then return true
  1097.     if(dist < 850)
  1098.         return true;
  1099.        
  1100.     return false;
  1101. }

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.