CSHARP 203
Koth.gsc Guest on 18th April 2021 07:26:37 PM
  1. #include maps\mp\_utility;
  2. #include maps\mp\gametypes\_hud_util;
  3.  
  4.  
  5. main()
  6. {
  7.     if ( getdvar("mapname") == "mp_background" )
  8.         return;
  9.  
  10.     maps\mp\gametypes\_globallogic::init();
  11.     maps\mp\gametypes\_callbacksetup::SetupCallbacks();
  12.     maps\mp\gametypes\_globallogic::SetupCallbacks();
  13.     if(level.ex_blackscreen) maps\mp\gametypes\_blackscreen::init();
  14.  
  15.     maps\mp\gametypes\_globallogic::registerTimeLimitDvar( level.gameType, 30, 0, 1440 );
  16.     maps\mp\gametypes\_globallogic::registerScoreLimitDvar( level.gameType, 300, 0, 1000 );
  17.     maps\mp\gametypes\_globallogic::registerNumLivesDvar( level.gameType, 0, 0, 10 );
  18.    
  19.     level.teamBased = true;
  20.     level.doPrematch = true;
  21.     level.overrideTeamScore = true;
  22.     level.onStartGameType = ::onStartGameType;
  23.     level.onSpawnPlayer = ::onSpawnPlayer;
  24.     level.onPlayerKilled = ::onPlayerKilled;
  25.  
  26.     precacheShader( "compass_waypoint_captureneutral" );
  27.     precacheShader( "compass_waypoint_capture" );
  28.     precacheShader( "compass_waypoint_defend" );
  29.  
  30.     precacheShader( "waypoint_targetneutral" );
  31.     precacheShader( "waypoint_captureneutral" );
  32.     precacheShader( "waypoint_capture" );
  33.     precacheShader( "waypoint_defend" );
  34.    
  35.     if ( getdvar("koth_autodestroytime") == "" )
  36.         setdvar("koth_autodestroytime", "60");
  37.     level.hqAutoDestroyTime = getdvarint("koth_autodestroytime");
  38.    
  39.     if ( getdvar("koth_spawntime") == "" )
  40.         setdvar("koth_spawntime", "0");
  41.     level.hqSpawnTime = getdvarint("koth_spawntime");
  42.    
  43.     if ( getdvar("koth_kothmode") == "" )
  44.         setdvar("koth_kothmode", "1");
  45.     level.kothMode = getdvarint("koth_kothmode");
  46.  
  47.     if ( getdvar("koth_captureTime") == "" )
  48.         setdvar("koth_captureTime", "20");
  49.     level.captureTime = getdvarint("koth_captureTime");
  50.  
  51.     if ( getdvar("koth_destroyTime") == "" )
  52.         setdvar("koth_destroyTime", "10");
  53.     level.destroyTime = getdvarint("koth_destroyTime");
  54.    
  55.     if ( getdvar("koth_delayPlayer") == "" )
  56.         setdvar("koth_delayPlayer", 1);
  57.     level.delayPlayer = getdvarint("koth_delayPlayer");
  58.  
  59.     if ( getdvar("koth_spawnDelay") == "" )
  60.         setdvar("koth_spawnDelay", 0);
  61.     level.spawnDelay = getdvarint("koth_spawnDelay");
  62.        
  63.     level.iconoffset = (0,0,32);
  64.    
  65.     level.onRespawnDelay = ::getRespawnDelay;
  66.  
  67.     game["dialog"]["gametype"] = "headquarters";
  68. }
  69.  
  70.  
  71. updateObjectiveHintMessages( alliesObjective, axisObjective )
  72. {
  73.     game["strings"]["objective_hint_allies"] = alliesObjective;
  74.     game["strings"]["objective_hint_axis"  ] = axisObjective;
  75.    
  76.     for ( i = 0; i < level.players.size; i++ )
  77.     {
  78.         player = level.players[i];
  79.         if ( isDefined( player.pers["team"] ) && player.pers["team"] != "spectator" )
  80.         {
  81.             hintText = maps\mp\gametypes\_globallogic::getObjectiveHintText( player.pers["team"] );
  82.             player thread maps\mp\gametypes\_hud_message::hintMessage( hintText );
  83.         }
  84.     }
  85. }
  86.  
  87.  
  88. getRespawnDelay()
  89. {
  90.     self.lowerMessageOverride = undefined;
  91.  
  92.     if ( !isDefined( level.radioObject ) )
  93.         return undefined;
  94.    
  95.     hqOwningTeam = level.radioObject maps\mp\gametypes\_gameobjects::getOwnerTeam();
  96.     if ( self.pers["team"] == hqOwningTeam )
  97.     {
  98.         if ( !isDefined( level.hqDestroyTime ) )
  99.             return undefined;
  100.        
  101.         timeRemaining = (level.hqDestroyTime - gettime()) / 1000;
  102.  
  103.         if (!level.spawnDelay )
  104.             return undefined;
  105.  
  106.         if ( level.spawnDelay >= level.hqAutoDestroyTime )
  107.             self.lowerMessageOverride = &"MP_WAITING_FOR_HQ";              
  108.            
  109.         if ( level.delayPlayer )
  110.         {
  111.             return min( level.spawnDelay, timeRemaining );
  112.         }
  113.         else
  114.         {
  115.             return (int(timeRemaining) % level.spawnDelay);
  116.         }
  117.     }
  118. }
  119.  
  120.  
  121. onStartGameType()
  122. {
  123.     // TODO: HQ objective text
  124.     maps\mp\gametypes\_globallogic::setObjectiveText( "allies", &"OBJECTIVES_KOTH" );
  125.     maps\mp\gametypes\_globallogic::setObjectiveText( "axis", &"OBJECTIVES_KOTH" );
  126.    
  127.     if ( level.splitscreen )
  128.     {
  129.         maps\mp\gametypes\_globallogic::setObjectiveScoreText( "allies", &"OBJECTIVES_KOTH" );
  130.         maps\mp\gametypes\_globallogic::setObjectiveScoreText( "axis", &"OBJECTIVES_KOTH" );
  131.     }
  132.     else
  133.     {
  134.         maps\mp\gametypes\_globallogic::setObjectiveScoreText( "allies", &"OBJECTIVES_KOTH_SCORE" );
  135.         maps\mp\gametypes\_globallogic::setObjectiveScoreText( "axis", &"OBJECTIVES_KOTH_SCORE" );
  136.     }
  137.    
  138.     level.objectiveHintPrepareHQ = &"MP_CONTROL_HQ";
  139.     level.objectiveHintCaptureHQ = &"MP_CAPTURE_HQ";
  140.     level.objectiveHintDestroyHQ = &"MP_DESTROY_HQ";
  141.     level.objectiveHintDefendHQ = &"MP_DEFEND_HQ";
  142.     precacheString( level.objectiveHintPrepareHQ );
  143.     precacheString( level.objectiveHintCaptureHQ );
  144.     precacheString( level.objectiveHintDestroyHQ );
  145.     precacheString( level.objectiveHintDefendHQ );
  146.    
  147.     if ( level.kothmode )
  148.         level.objectiveHintDestroyHQ = level.objectiveHintCaptureHQ;
  149.    
  150.     if ( level.hqSpawnTime )
  151.         updateObjectiveHintMessages( level.objectiveHintPrepareHQ, level.objectiveHintPrepareHQ );
  152.     else
  153.         updateObjectiveHintMessages( level.objectiveHintCaptureHQ, level.objectiveHintCaptureHQ );
  154.    
  155.     setClientNameMode("auto_change");
  156.    
  157.     // TODO: HQ spawnpoints
  158.     level.spawnMins = ( 0, 0, 0 );
  159.     level.spawnMaxs = ( 0, 0, 0 );
  160.     maps\mp\gametypes\_spawnlogic::addSpawnPoints( "allies", "mp_tdm_spawn" );
  161.     maps\mp\gametypes\_spawnlogic::addSpawnPoints( "axis", "mp_tdm_spawn" );
  162.    
  163.     level.mapCenter = maps\mp\gametypes\_spawnlogic::findBoxCenter( level.spawnMins, level.spawnMaxs );
  164.     setMapCenter( level.mapCenter );
  165.    
  166.     level.spawn_all = getentarray( "mp_tdm_spawn", "classname" );
  167.     if ( !level.spawn_all.size )
  168.     {
  169.         println("^1No mp_tdm_spawn spawnpoints in level!");
  170.         maps\mp\gametypes\_callbacksetup::AbortLevel();
  171.         return;
  172.     }
  173.    
  174.    
  175.     allowed[0] = "hq";
  176.     maps\mp\gametypes\_gameobjects::main(allowed);
  177.    
  178.     thread SetupRadios();
  179.  
  180.     maps\mp\gametypes\_rank::registerScoreInfo( "kill", 5 );
  181.     maps\mp\gametypes\_rank::registerScoreInfo( "headshot", 5 );
  182.     maps\mp\gametypes\_rank::registerScoreInfo( "assist", 1 );
  183.     maps\mp\gametypes\_rank::registerScoreInfo( "defend", 5 );
  184.     maps\mp\gametypes\_rank::registerScoreInfo( "assault", 5 );
  185.     maps\mp\gametypes\_rank::registerScoreInfo( "capture", 15 );
  186.    
  187.     thread HQMainLoop();
  188. }
  189.  
  190.  
  191. HQMainLoop()
  192. {
  193.     level endon("game_ended");
  194.    
  195.     level.hqRevealTime = -100000;
  196.    
  197.     hqSpawningInStr = &"MP_HQ_AVAILABLE_IN";
  198.     if ( level.kothmode )
  199.     {
  200.         hqDestroyedInFriendlyStr = &"MP_HQ_DESPAWN_IN";
  201.         hqDestroyedInEnemyStr = &"MP_HQ_DESPAWN_IN";
  202.     }
  203.     else
  204.     {
  205.         hqDestroyedInFriendlyStr = &"MP_HQ_REINFORCEMENTS_IN";
  206.         hqDestroyedInEnemyStr = &"MP_HQ_DESPAWN_IN";
  207.     }
  208.    
  209.     precacheString( hqSpawningInStr );
  210.     precacheString( hqDestroyedInFriendlyStr );
  211.     precacheString( hqDestroyedInEnemyStr );
  212.    
  213.     while ( level.inPrematchPeriod )
  214.         wait ( 0.05 * level.fps_multiplier );
  215.    
  216.     wait (5 * level.fps_multiplier );
  217.        
  218.     timerDisplay = [];
  219.     timerDisplay["allies"] = createServerTimer( "objective", 1.4, "allies" );
  220.     timerDisplay["allies"] setPoint( "TOPRIGHT", "TOPRIGHT", 0, 0 );
  221.     timerDisplay["allies"].label = hqSpawningInStr;
  222.     timerDisplay["allies"].alpha = 0;
  223.     timerDisplay["allies"].archived = false;
  224.     timerDisplay["allies"].hideWhenInMenu = true;
  225.    
  226.     timerDisplay["axis"  ] = createServerTimer( "objective", 1.4, "axis" );
  227.     timerDisplay["axis"  ] setPoint( "TOPRIGHT", "TOPRIGHT", 0, 0 );
  228.     timerDisplay["axis"  ].label = hqSpawningInStr;
  229.     timerDisplay["axis"  ].alpha = 0;
  230.     timerDisplay["axis"  ].archived = false;
  231.     timerDisplay["axis"  ].hideWhenInMenu = true;
  232.    
  233.     thread hideTimerDisplayOnGameEnd( timerDisplay["allies"] );
  234.     thread hideTimerDisplayOnGameEnd( timerDisplay["axis"  ] );
  235.    
  236.     locationObjID = maps\mp\gametypes\_gameobjects::getNextObjID();
  237.    
  238.     objective_add( locationObjID, "invisible", (0,0,0) );
  239.    
  240.     while( 1 )
  241.     {
  242.         radio = PickRadioToSpawn();
  243.        
  244.         iPrintLn( &"MP_HQ_REVEALED" );
  245.         playSoundOnPlayers( "mp_suitcase_pickup" );
  246.         maps\mp\gametypes\_globallogic::leaderDialog( "hq_located" );
  247. //      maps\mp\gametypes\_globallogic::leaderDialog( "move_to_new" );
  248.        
  249.         radioObject = radio.gameobject;
  250.         level.radioObject = radioObject;
  251.         logString( "radio spawned: " + radio.trigOrigin[0] + " " + radio.trigOrigin[1] + " " + radio.trigOrigin[2] );
  252.        
  253.         radioObject maps\mp\gametypes\_gameobjects::setModelVisibility( true );
  254.        
  255.         level.hqRevealTime = gettime();
  256.        
  257.         if ( level.hqSpawnTime )
  258.         {
  259.             nextObjPoint = maps\mp\gametypes\_objpoints::createTeamObjpoint( "objpoint_next_hq", radio.origin + level.iconoffset, "all", "waypoint_targetneutral" );
  260.             nextObjPoint setWayPoint( true, "waypoint_targetneutral" );
  261.             objective_position( locationObjID, radio.trigorigin );
  262.             objective_icon( locationObjID, "compass_waypoint_captureneutral" );
  263.             objective_state( locationObjID, "active" );
  264.  
  265.             updateObjectiveHintMessages( level.objectiveHintPrepareHQ, level.objectiveHintPrepareHQ );
  266.            
  267.             timerDisplay["allies"].label = hqSpawningInStr;
  268.             timerDisplay["allies"] setTimer( level.hqSpawnTime );
  269.             if ( !level.splitscreen )
  270.                 timerDisplay["allies"].alpha = 1;
  271.             timerDisplay["axis"  ].label = hqSpawningInStr;
  272.             timerDisplay["axis"  ] setTimer( level.hqSpawnTime );
  273.             if ( !level.splitscreen )
  274.                 timerDisplay["axis"  ].alpha = 1;
  275.  
  276.             wait (level.hqSpawnTime * level.fps_multiplier );
  277.  
  278.             maps\mp\gametypes\_objpoints::deleteObjPoint( nextObjPoint );
  279.             objective_state( locationObjID, "invisible" );
  280.             maps\mp\gametypes\_globallogic::leaderDialog( "hq_online" );
  281.         }
  282.  
  283.         timerDisplay["allies"].alpha = 0;
  284.         timerDisplay["axis"  ].alpha = 0;
  285.        
  286.         waittillframeend;
  287.        
  288.         maps\mp\gametypes\_globallogic::leaderDialog( "obj_capture" );
  289.         updateObjectiveHintMessages( level.objectiveHintCaptureHQ, level.objectiveHintCaptureHQ );
  290.         playSoundOnPlayers( "mp_killstreak_radar" );
  291.  
  292.         radioObject maps\mp\gametypes\_gameobjects::enableObject();
  293.        
  294.         radioObject maps\mp\gametypes\_gameobjects::allowUse( "any" );
  295.         radioObject maps\mp\gametypes\_gameobjects::setUseTime( level.captureTime * level.fps_multiplier );
  296.         radioObject maps\mp\gametypes\_gameobjects::setUseText( &"MP_CAPTURING_HQ" );
  297.        
  298.         radioObject maps\mp\gametypes\_gameobjects::set2DIcon( "enemy", "compass_waypoint_captureneutral" );
  299.         radioObject maps\mp\gametypes\_gameobjects::set3DIcon( "enemy", "waypoint_captureneutral" );
  300.         radioObject maps\mp\gametypes\_gameobjects::setVisibleTeam( "any" );
  301.         radioObject maps\mp\gametypes\_gameobjects::setModelVisibility( true );
  302.        
  303.         radioObject.onUse = ::onRadioCapture;
  304.         radioObject.onBeginUse = ::onBeginUse;
  305.         radioObject.onEndUse = ::onEndUse;
  306.        
  307.         level waittill( "hq_captured" );
  308.        
  309.         ownerTeam = radioObject maps\mp\gametypes\_gameobjects::getOwnerTeam();
  310.         otherTeam = getOtherTeam( ownerTeam );
  311.        
  312.         if ( level.hqAutoDestroyTime )
  313.         {
  314.             thread DestroyHQAfterTime( level.hqAutoDestroyTime );
  315.             timerDisplay[ownerTeam] setTimer( level.hqAutoDestroyTime );
  316.             timerDisplay[otherTeam] setTimer( level.hqAutoDestroyTime );
  317.         }
  318.         else
  319.         {
  320.             level.hqDestroyedByTimer = false;
  321.         }
  322.        
  323.         /#
  324.         thread scriptDestroyHQ();
  325.         #/
  326.        
  327.         while( 1 )
  328.         {
  329.             ownerTeam = radioObject maps\mp\gametypes\_gameobjects::getOwnerTeam();
  330.             otherTeam = getOtherTeam( ownerTeam );
  331.    
  332.             if ( ownerTeam == "allies" )
  333.             {
  334.                 updateObjectiveHintMessages( level.objectiveHintDefendHQ, level.objectiveHintDestroyHQ );
  335.             }
  336.             else
  337.             {
  338.                 updateObjectiveHintMessages( level.objectiveHintDestroyHQ, level.objectiveHintDefendHQ );
  339.             }
  340.    
  341.             radioObject maps\mp\gametypes\_gameobjects::allowUse( "enemy" );
  342.             radioObject maps\mp\gametypes\_gameobjects::set2DIcon( "friendly", "compass_waypoint_defend" );
  343.             radioObject maps\mp\gametypes\_gameobjects::set3DIcon( "friendly", "waypoint_defend" );
  344.             radioObject maps\mp\gametypes\_gameobjects::set2DIcon( "enemy", "compass_waypoint_capture" );
  345.             radioObject maps\mp\gametypes\_gameobjects::set3DIcon( "enemy", "waypoint_capture" );
  346.  
  347.             if ( !level.kothMode )
  348.                 radioObject maps\mp\gametypes\_gameobjects::setUseText( &"MP_DESTROYING_HQ" );
  349.            
  350.             radioObject.onUse = ::onRadioDestroy;
  351.            
  352.             if ( level.hqAutoDestroyTime )
  353.             {
  354.                 timerDisplay[ownerTeam].label = hqDestroyedInFriendlyStr;
  355.                 if ( !level.splitscreen )
  356.                     timerDisplay[ownerTeam].alpha = 1;
  357.                 timerDisplay[otherTeam].label = hqDestroyedInEnemyStr;
  358.                 if ( !level.splitscreen )
  359.                     timerDisplay[otherTeam].alpha = 1;
  360.             }
  361.            
  362.             level waittill( "hq_destroyed" );
  363.            
  364.             if ( !level.kothmode || level.hqDestroyedByTimer )
  365.                 break;
  366.            
  367.             thread forceSpawnTeam( ownerTeam );
  368.            
  369.             radioObject maps\mp\gametypes\_gameobjects::setOwnerTeam( getOtherTeam( ownerTeam ) );
  370.         }
  371.        
  372.         level notify("hq_reset");
  373.        
  374.         radioObject maps\mp\gametypes\_gameobjects::disableObject();
  375.         radioObject maps\mp\gametypes\_gameobjects::allowUse( "none" );
  376.         radioObject maps\mp\gametypes\_gameobjects::setOwnerTeam( "neutral" );
  377.         radioObject maps\mp\gametypes\_gameobjects::setModelVisibility( false );
  378.        
  379.         timerDisplay["allies"].alpha = 0;
  380.         timerDisplay["axis"  ].alpha = 0;
  381.        
  382.         level.radioObject = undefined;
  383.        
  384.         wait (.05 * level.fps_multiplier );
  385.        
  386.         thread forceSpawnTeam( ownerTeam );
  387.        
  388.         wait (3.0 * level.fps_multiplier );
  389.     }
  390. }
  391.  
  392.  
  393. hideTimerDisplayOnGameEnd( timerDisplay )
  394. {
  395.     level waittill("game_ended");
  396.     timerDisplay.alpha = 0;
  397. }
  398.  
  399.  
  400. forceSpawnTeam( team )
  401. {
  402.     players = level.players;
  403.     for ( i = 0; i < players.size; i++ )
  404.     {
  405.         player = players[i];
  406.         if ( !isdefined( player ) )
  407.             continue;
  408.        
  409.         if ( player.pers["team"] == team )
  410.         {
  411.             player.lowerMessageOverride = undefined;
  412.             player notify( "force_spawn" );
  413.             wait (.1 * level.fps_multiplier );
  414.         }
  415.     }
  416. }
  417.  
  418.  
  419. onBeginUse( player )
  420. {
  421.     ownerTeam = self maps\mp\gametypes\_gameobjects::getOwnerTeam();
  422.  
  423.     if ( ownerTeam == "neutral" )
  424.     {
  425.         self.objPoints[player.pers["team"]] thread maps\mp\gametypes\_objpoints::startFlashing();
  426.     }
  427.     else
  428.     {
  429.         self.objPoints["allies"] thread maps\mp\gametypes\_objpoints::startFlashing();
  430.         self.objPoints["axis"] thread maps\mp\gametypes\_objpoints::startFlashing();
  431.     }
  432. }
  433.  
  434.  
  435. onEndUse( team, player, success )
  436. {
  437.     self.objPoints["allies"] thread maps\mp\gametypes\_objpoints::stopFlashing();
  438.     self.objPoints["axis"] thread maps\mp\gametypes\_objpoints::stopFlashing();
  439. }
  440.  
  441.  
  442. onRadioCapture( player )
  443. {
  444.     team = player.pers["team"];
  445.  
  446.     player logString( "radio captured" );
  447.     player thread [[level.onXPEvent]]( "capture" );
  448.     maps\mp\gametypes\_globallogic::givePlayerScore( "capture", player );
  449.  
  450.     oldTeam = maps\mp\gametypes\_gameobjects::getOwnerTeam();
  451.     self maps\mp\gametypes\_gameobjects::setOwnerTeam( team );
  452.     if ( !level.kothMode )
  453.         self maps\mp\gametypes\_gameobjects::setUseTime( level.destroyTime * level.fps_multiplier );
  454.    
  455.     otherTeam = "axis";
  456.     if ( team == "axis" )
  457.         otherTeam = "allies";
  458.    
  459.     thread printOnTeamArg( &"MP_HQ_CAPTURED_BY", team, player );
  460.     thread printOnTeam( &"MP_HQ_CAPTURED_BY_ENEMY", otherTeam );
  461.     maps\mp\gametypes\_globallogic::leaderDialog( "hq_secured", team );
  462.     maps\mp\gametypes\_globallogic::leaderDialog( "hq_enemy_captured", oldTeam );
  463.     thread playSoundOnPlayers( "mp_war_objective_taken", team );
  464.     thread playSoundOnPlayers( "mp_war_objective_lost", otherTeam );
  465.    
  466.     level thread awardHQPoints( team );
  467.    
  468.     level notify( "hq_captured" );
  469. }
  470.  
  471. /#
  472. scriptDestroyHQ()
  473. {
  474.     level endon("hq_destroyed");
  475.     while(1)
  476.     {
  477.         if ( getdvar("scr_destroyhq") != "1" )
  478.         {
  479.             wait (.1 * level.fps_multiplier );
  480.             continue;
  481.         }
  482.         setdvar("scr_destroyhq","0");
  483.        
  484.         hqOwningTeam = level.radioObject maps\mp\gametypes\_gameobjects::getOwnerTeam();
  485.         for ( i = 0; i < level.players.size; i++ )
  486.         {
  487.             if ( level.players[i].team != hqOwningTeam )
  488.             {
  489.                 onRadioDestroy( level.players[i] );
  490.                 break;
  491.             }
  492.         }
  493.     }
  494. }
  495. #/
  496.  
  497. onRadioDestroy( player )
  498. {
  499.     team = player.pers["team"];
  500.     otherTeam = "axis";
  501.     if ( team == "axis" )
  502.         otherTeam = "allies";
  503.  
  504.     player logString( "radio destroyed" );
  505.     player thread [[level.onXPEvent]]( "capture" );
  506.     maps\mp\gametypes\_globallogic::givePlayerScore( "capture", player );  
  507.    
  508.     if ( level.kothmode )
  509.     {
  510.         thread printOnTeamArg( &"MP_HQ_CAPTURED_BY", team, player );
  511.         thread printOnTeam( &"MP_HQ_CAPTURED_BY_ENEMY", otherTeam );
  512.         maps\mp\gametypes\_globallogic::leaderDialog( "hq_secured", team );
  513.         maps\mp\gametypes\_globallogic::leaderDialog( "hq_enemy_captured", otherTeam );
  514.     }
  515.     else
  516.     {
  517.         thread printOnTeamArg( &"MP_HQ_DESTROYED_BY", team, player );
  518.         thread printOnTeam( &"MP_HQ_DESTROYED_BY_ENEMY", otherTeam );
  519.         maps\mp\gametypes\_globallogic::leaderDialog( "hq_secured", team );
  520.         maps\mp\gametypes\_globallogic::leaderDialog( "hq_enemy_destroyed", otherTeam );
  521.     }
  522.     thread playSoundOnPlayers( "mp_war_objective_taken", team );
  523.     thread playSoundOnPlayers( "mp_war_objective_lost", otherTeam );
  524.    
  525.     level notify( "hq_destroyed" );
  526.    
  527.     if ( level.kothmode )
  528.         level thread awardHQPoints( team );
  529. }
  530.  
  531.  
  532. DestroyHQAfterTime( time )
  533. {
  534.     level endon( "game_ended" );
  535.     level endon( "hq_reset" );
  536.    
  537.     level.hqDestroyTime = gettime() + time * 1000;
  538.     level.hqDestroyedByTimer = false;
  539.    
  540.     wait (time * level.fps_multiplier );
  541.    
  542.     level.hqDestroyedByTimer = true;
  543.     level notify( "hq_destroyed" );
  544. }
  545.  
  546.  
  547. awardHQPoints( team )
  548. {
  549.     level endon( "game_ended" );
  550.     level endon( "hq_destroyed" );
  551.    
  552.     level notify("awardHQPointsRunning");
  553.     level endon("awardHQPointsRunning");
  554.    
  555.     seconds = 5;
  556.    
  557.     while ( !level.gameEnded )
  558.     {
  559.         [[level._setTeamScore]]( team, [[level._getTeamScore]]( team ) + seconds );
  560.         for ( index = 0; index < level.players.size; index++ )
  561.         {
  562.             player = level.players[index];
  563.            
  564.             if ( player.pers["team"] == team )
  565.             {
  566.                 player thread [[level.onXPEvent]]( "defend" );
  567.                 maps\mp\gametypes\_globallogic::givePlayerScore( "defend", player );   
  568.             }
  569.         }
  570.        
  571.         wait (seconds * level.fps_multiplier );
  572.     }
  573. }
  574.  
  575.  
  576. onSpawnPlayer()
  577. {
  578.     spawnpoint = undefined;
  579.    
  580.     if ( isdefined( level.radioObject ) )
  581.     {
  582.         hqOwningTeam = level.radioObject maps\mp\gametypes\_gameobjects::getOwnerTeam();
  583.         if ( self.pers["team"] == hqOwningTeam )
  584.             spawnpoint = maps\mp\gametypes\_spawnlogic::getSpawnpoint_NearTeam( level.spawn_all, level.radioObject.nearSpawns );
  585.         else if ( level.spawnDelay >= level.hqAutoDestroyTime && gettime() > level.hqRevealTime + 10000 )
  586.             spawnpoint = maps\mp\gametypes\_spawnlogic::getSpawnpoint_NearTeam( level.spawn_all );
  587.         else
  588.             spawnpoint = maps\mp\gametypes\_spawnlogic::getSpawnpoint_NearTeam( level.spawn_all, level.radioObject.outerSpawns );
  589.     }
  590.    
  591.     if ( !isDefined( spawnpoint ) )
  592.         spawnpoint = maps\mp\gametypes\_spawnlogic::getSpawnpoint_NearTeam( level.spawn_all );
  593.    
  594.     assert( isDefined(spawnpoint) );
  595.  
  596.     self.lowerMessageOverride = undefined;
  597.    
  598.     self spawn( spawnpoint.origin, spawnpoint.angles );
  599. }
  600.  
  601.  
  602. SetupRadios()
  603. {
  604.     maperrors = [];
  605.  
  606.     radios = getentarray( "hq_hardpoint", "targetname" );
  607.    
  608.     if ( radios.size < 2 )
  609.     {
  610.         maperrors[maperrors.size] = "There are not at least 2 entities with targetname \"radio\"";
  611.     }
  612.    
  613.     trigs = getentarray("radiotrigger", "targetname");
  614.     for ( i = 0; i < radios.size; i++ )
  615.     {
  616.         errored = false;
  617.        
  618.         radio = radios[i];
  619.         radio.trig = undefined;
  620.         for ( j = 0; j < trigs.size; j++ )
  621.         {
  622.             if ( radio istouching( trigs[j] ) )
  623.             {
  624.                 if ( isdefined( radio.trig ) )
  625.                 {
  626.                     maperrors[maperrors.size] = "Radio at " + radio.origin + " is touching more than one \"radiotrigger\" trigger";
  627.                     errored = true;
  628.                     break;
  629.                 }
  630.                 radio.trig = trigs[j];
  631.                 break;
  632.             }
  633.         }
  634.        
  635.         if ( !isdefined( radio.trig ) )
  636.         {
  637.             if ( !errored )
  638.             {
  639.                 maperrors[maperrors.size] = "Radio at " + radio.origin + " is not inside any \"radiotrigger\" trigger";
  640.                 continue;
  641.             }
  642.            
  643.             // possible fallback (has been tested)
  644.             //radio.trig = spawn( "trigger_radius", radio.origin, 0, 128, 128 );
  645.             //errored = false;
  646.         }
  647.        
  648.         assert( !errored );
  649.        
  650.         radio.trigorigin = radio.trig.origin;
  651.        
  652.         visuals = [];
  653.         visuals[0] = radio;
  654.        
  655.         otherVisuals = getEntArray( radio.target, "targetname" );
  656.         for ( j = 0; j < otherVisuals.size; j++ )
  657.         {
  658.             visuals[visuals.size] = otherVisuals[j];
  659.         }
  660.        
  661.         radio.gameObject = maps\mp\gametypes\_gameobjects::createUseObject( "neutral", radio.trig, visuals, (radio.origin - radio.trigorigin) + level.iconoffset );
  662.         radio.gameObject maps\mp\gametypes\_gameobjects::disableObject();
  663.         radio.gameObject maps\mp\gametypes\_gameobjects::setModelVisibility( false );
  664.         radio.trig.useObj = radio.gameObject;
  665.        
  666.         radio setUpNearbySpawns();
  667.     }
  668.    
  669.     if (maperrors.size > 0)
  670.     {
  671.         println("^1------------ Map Errors ------------");
  672.         for(i = 0; i < maperrors.size; i++)
  673.             println(maperrors[i]);
  674.         println("^1------------------------------------");
  675.        
  676.         maps\mp\_utility::error("Map errors. See above");
  677.         maps\mp\gametypes\_callbacksetup::AbortLevel();
  678.        
  679.         return;
  680.     }
  681.    
  682.     level.radios = radios;
  683.    
  684.     level.prevradio = undefined;
  685.     level.prevradio2 = undefined;
  686.    
  687.     return true;
  688. }
  689.  
  690. setUpNearbySpawns()
  691. {
  692.     spawns = level.spawn_all;
  693.    
  694.     for ( i = 0; i < spawns.size; i++ )
  695.     {
  696.         spawns[i].distsq = distanceSquared( spawns[i].origin, self.origin );
  697.     }
  698.    
  699.     // sort by distsq
  700.     for ( i = 1; i < spawns.size; i++ )
  701.     {
  702.         thespawn = spawns[i];
  703.         for ( j = i - 1; j >= 0 && thespawn.distsq < spawns[j].distsq; j-- )
  704.             spawns[j + 1] = spawns[j];
  705.         spawns[j + 1] = thespawn;
  706.     }
  707.    
  708.     first = [];
  709.     second = [];
  710.     third = [];
  711.     outer = [];
  712.    
  713.     thirdSize = spawns.size / 3;
  714.     for ( i = 0; i <= thirdSize; i++ )
  715.     {
  716.         first[ first.size ] = spawns[i];
  717.     }
  718.     for ( ; i < spawns.size; i++ )
  719.     {
  720.         outer[ outer.size ] = spawns[i];
  721.         if ( i <= (thirdSize*2) )
  722.             second[ second.size ] = spawns[i];
  723.         else           
  724.             third[ third.size ] = spawns[i];
  725.     }
  726.    
  727.     self.gameObject.nearSpawns = first;
  728.     self.gameObject.midSpawns = second;
  729.     self.gameObject.farSpawns = third;
  730.     self.gameObject.outerSpawns = outer;
  731. }
  732.  
  733. PickRadioToSpawn()
  734. {
  735.     // find average of positions of each team
  736.     // (medians would be better, to get rid of outliers...)
  737.     // and find the radio which has the least difference in distance from those two averages
  738.    
  739.     avgpos["allies"] = (0,0,0);
  740.     avgpos["axis"] = (0,0,0);
  741.     num["allies"] = 0;
  742.     num["axis"] = 0;
  743.    
  744.     for ( i = 0; i < level.players.size; i++ )
  745.     {
  746.         player = level.players[i];
  747.         if ( isalive( player ) )
  748.         {
  749.             avgpos[ player.pers["team"] ] += player.origin;
  750.             num[ player.pers["team"] ]++;
  751.         }
  752.     }
  753.    
  754.     if ( num["allies"] == 0 || num["axis"] == 0 )
  755.     {
  756.         radio = level.radios[ randomint( level.radios.size) ];
  757.         while ( isDefined( level.prevradio ) && radio == level.prevradio ) // so lazy
  758.             radio = level.radios[ randomint( level.radios.size) ];
  759.        
  760.         level.prevradio2 = level.prevradio;
  761.         level.prevradio = radio;
  762.        
  763.         return radio;
  764.     }
  765.    
  766.     avgpos["allies"] = avgpos["allies"] / num["allies"];
  767.     avgpos["axis"  ] = avgpos["axis"  ] / num["axis"  ];
  768.    
  769.     bestradio = undefined;
  770.     lowestcost = undefined;
  771.     for ( i = 0; i < level.radios.size; i++ )
  772.     {
  773.         radio = level.radios[i];
  774.        
  775.         // (purposefully using distance instead of distanceSquared)
  776.         cost = abs( distance( radio.origin, avgpos["allies"] ) - distance( radio.origin, avgpos["axis"] ) );
  777.        
  778.         if ( isdefined( level.prevradio ) && radio == level.prevradio )
  779.         {
  780.             continue;
  781.         }
  782.         if ( isdefined( level.prevradio2 ) && radio == level.prevradio2 )
  783.         {
  784.             if ( level.radios.size > 2 )
  785.                 continue;
  786.             else
  787.                 cost += 512;
  788.         }
  789.        
  790.         if ( !isdefined( lowestcost ) || cost < lowestcost )
  791.         {
  792.             lowestcost = cost;
  793.             bestradio = radio;
  794.         }
  795.     }
  796.     assert( isdefined( bestradio ) );
  797.    
  798.     level.prevradio2 = level.prevradio;
  799.     level.prevradio = bestradio;
  800.    
  801.     return bestradio;
  802. }
  803.  
  804.  
  805.  
  806. onPlayerKilled( eInflictor, attacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, psOffsetTime, deathAnimDuration )
  807. {
  808.     if ( !isPlayer( attacker ) || (!self.touchTriggers.size && !attacker.touchTriggers.size) || attacker.pers["team"] == self.pers["team"] )
  809.         return;
  810.  
  811.     if ( self.touchTriggers.size )
  812.     {
  813.         triggerIds = getArrayKeys( self.touchTriggers );
  814.         ownerTeam = self.touchTriggers[triggerIds[0]].useObj.ownerTeam;
  815.        
  816.         if ( ownerTeam != "neutral" )
  817.         {
  818.             team = self.pers["team"];
  819.             if ( team == ownerTeam )
  820.             {
  821.                 attacker thread [[level.onXPEvent]]( "assault" );
  822.                 maps\mp\gametypes\_globallogic::givePlayerScore( "assault", attacker );
  823.             }
  824.             else
  825.             {
  826.                 attacker thread [[level.onXPEvent]]( "defend" );
  827.                 maps\mp\gametypes\_globallogic::givePlayerScore( "defend", attacker );
  828.             }
  829.         }      
  830.     }  
  831.    
  832.     if ( attacker.touchTriggers.size )
  833.     {
  834.         triggerIds = getArrayKeys( attacker.touchTriggers );
  835.         ownerTeam = attacker.touchTriggers[triggerIds[0]].useObj.ownerTeam;
  836.        
  837.         if ( ownerTeam != "neutral" )
  838.         {
  839.             team = attacker.pers["team"];
  840.             if ( team == ownerTeam )
  841.             {
  842.                 attacker thread [[level.onXPEvent]]( "defend" );
  843.                 maps\mp\gametypes\_globallogic::givePlayerScore( "defend", attacker );
  844.             }
  845.             else
  846.             {
  847.                 attacker thread [[level.onXPEvent]]( "assault" );
  848.                 maps\mp\gametypes\_globallogic::givePlayerScore( "assault", attacker );
  849.             }      
  850.         }
  851.     }
  852. }

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.