home *** CD-ROM | disk | FTP | other *** search
/ Hacker 9 / HACKER09.ISO / Games / StarSiege.exe / Starsiege / Missions.vol / SWARM_Mai_Lay_Dan.cs < prev    next >
Text File  |  1998-07-27  |  14KB  |  588 lines

  1. //
  2. // tagStdlib.cs
  3. //
  4.  
  5.  
  6. $snuffValue           = 0;
  7. $chokeValue            = 0;
  8. $sackValue            = 0;
  9. $winScore            = 50;
  10. $tagWon                = 0;
  11. $healTriggerReady    = true;
  12. $ammoTriggerReady    = true;
  13.  
  14.  
  15. //----------------------------------------------
  16.  
  17.  
  18.  
  19. function setDefaultMissionOptions()
  20. {
  21.    $server::AllowTeamRed = true;
  22.    $server::AllowTeamBlue = false;
  23.    $server::AllowTeamYellow = true;
  24.    $server::AllowTeamPurple = false;
  25.  
  26.    $server::TeamPlay = true;
  27.    $server::AllowDeathmatch = false;
  28.    $server::AllowTeamPlay = true;    
  29. }
  30.  
  31. function onMissionStart(%playerNum)
  32. {
  33.     setKillValues();
  34.     displayKillValues();
  35.  
  36.     //reinitialize scores of players who were in previous game
  37.     
  38.     %count = playerManager::getPlayerCount();
  39.     for(%i = 0; %i < %count; %i = %i + 1)
  40.     {
  41.         %curPlayerNum = playerManager::getPlayerNum(%i);
  42.         initStats(%curPlayerNum);
  43.     }
  44.  
  45.     //Make first person to enter sim IT
  46.     
  47.     dataStore(0, strcat(%playerNum, "isIt"), "Yes");
  48.     wallDim(strcat(getName(%playerNum), " is now IT!"));
  49.     boundryCheck();
  50.     
  51. }        
  52.         
  53. //-------------------------------------------------------------
  54. function player::onAdd(%playerNum)
  55. {
  56.    setKillValues();
  57.    displayKillValues();
  58.    initStats(%playerNum);
  59.  
  60.    chat(%playerNum,0, strcat("Welcome to Starsiege SWARM, ", getName(%playerNum), ". Here are the rules: "));
  61.    chat(%playerNum,0, strcat("- You get " , $sackValue, " point(s) for SACKING 'IT'."));
  62.    chat(%playerNum,0, strcat("- You get ", $snuffValue, " points for SNUFFING someone while you are 'IT'."));
  63.    chat(%playerNum,0, strcat("- You CHOKE if 'IT' kills you and you lose ", $chokeValue, " point(s)."));
  64.    chat(%playerNum,0, "- You become 'IT' by sacking 'IT'.");
  65.    chat(%playerNum,0, strcat("- The first player to reach ", $winScore, " points wins the game."));
  66.    
  67. }
  68.  
  69. //-------------------------------------------------------------
  70. function player::onRemove(%playerNum)
  71. {
  72.       setKillValues();
  73.     displayKillValues();
  74.       
  75.       
  76.       if(%playerNum == getItNum())
  77.        {
  78.          %newItNum = getHighScorePlayerNum(%playerNum);
  79.  
  80.            if(%newItNum != "" && %newItNum != 0)
  81.         {
  82.               dataStore(0, strcat(%newItNum, "isIt"), "Yes" );
  83.               wall(strcat(getName(%newItNum), " is now IT!"));
  84.             
  85.             %vehicleId = playerManager::playerNumToVehicleId(%newItNum);
  86.             setTeam(%vehicleId, RED);
  87.             setVehicleSpecialIdentity(%vehicleId, true, RED);
  88.  
  89.             resetAmmoTrigger(%newItNum);
  90.             resetHealTrigger(%newItNum);
  91.            }
  92.     }
  93.     
  94.     cleanUp(%playerNum);
  95.     
  96.     
  97. }
  98.  
  99. //-------------------------------------------------------------
  100. function vehicle::onAdd(%vehicleId)
  101. {
  102.     setTeam(%vehicleId, YELLOW);
  103.     
  104.     if(playerManager::vehicleIdToPlayerNum(%vehicleId) == getItNum())
  105.     {
  106.         setTeam(%vehicleId, RED);
  107.         setVehicleSpecialIdentity(%vehicleId, true, RED);
  108.     }
  109. }
  110.  
  111. //----------------------------------------------
  112.  
  113. function vehicle::onDestroyed(%destroyedId, %destroyerId)
  114. {
  115.     %destroyerNum = playerManager::vehicleIdToPlayerNum(%destroyerId);
  116.     %destroyedNum = playerManager::vehicleIdToPlayerNum(%destroyedId);      
  117.     
  118.     if($tagWon == 1)
  119.     {
  120.         return;
  121.     }
  122.         
  123.     if(itKilledSelf(%destroyedNum, %destroyerNum))
  124.     {
  125.         return;
  126.     }
  127.     
  128.     if(itKilledPlayer(%destroyedNum, %destroyerNum))
  129.     {
  130.         return;
  131.     }
  132.     
  133.     if(playerKilledIt(%destroyedNum, %destroyerNum))
  134.     {
  135.         
  136.         echo("playerKilledIt");
  137.         
  138.         echo(getName(%destroyedNum));
  139.         echo(getTeam(%destroyedId));
  140.         
  141.         echo(getName(%destroyerNum));
  142.         echo(getTeam(%destroyerId));
  143.         setTeam(%destroyerId, RED);
  144.         echo(getTeam(%destroyerId));
  145.  
  146.         setVehicleSpecialIdentity(%destroyedId, false);
  147.         setVehicleSpecialIdentity(%destroyerId, true, RED);
  148.         return;
  149.     }
  150.     
  151. //     if we got here, a not-it player must have killed another not-it player
  152. //     which is ignored
  153. }
  154.  
  155. //--------------------------------------------------------
  156. function itKilledSelf(%destroyedNum, %destroyerNum)
  157. {
  158.     // if there is only one player, keep that player IT
  159.     
  160.     if(playerManager::getPlayerCount() == 1)
  161.        {
  162.         return true;
  163.     }
  164.  
  165.  
  166.     if(%destroyerNum == getItNum() && %destroyedNum == getItNum())
  167.     {
  168.         %newItNum = getHighScorePlayerNum(%playerNum);
  169.         
  170.            if(%newItNum != "" && %newItNum != 0)
  171.         {
  172.               dataStore(0, strcat(%destroyedNum, "isIt"), "No" );
  173.               dataStore(0, strcat(%newItNum, "isIt"), "Yes" );
  174.               
  175.               wall(strcat(getName(%newItNum), " is now IT!"));
  176.  
  177.             %vehicleId = playerManager::playerNumToVehicleId(%newItNum);
  178.             
  179.             setTeam(%vehicleId, RED);
  180.             setVehicleSpecialIdentity(%vehicleId, true, RED);
  181.         
  182.             resetAmmoTrigger(%newItNum);
  183.             resetHealTrigger(%newItNum);
  184.            }
  185.  
  186.         return true;
  187.     }
  188.     return false;
  189. }
  190.  
  191. //---------------------------------------------------------
  192. function itKilledPlayer(%destroyedNum, %destroyerNum)
  193. {
  194.     
  195.     if(%destroyerNum == getItNum())
  196.     {
  197.         %snuffKey    = strcat(%destroyerNum, "snuff");
  198.         %chokeKey     = strcat(%destroyedNum, "choke");
  199.         
  200.         dataStore(0, %snuffKey, 1 + dataRetrieve(0, %snuffKey));
  201.         dataStore(0, %chokeKey, 1 + dataRetrieve(0, %chokeKey));
  202.  
  203.         if(playerWonGame(%destroyerNum))
  204.         {
  205.             return true;
  206.         }
  207.         
  208.         else
  209.         {
  210.             wallDim(strcat(getName(%destroyedNum), " was Snuffed by IT!"));
  211.             %object = playerManager::playerNumToVehicleId(%destroyedNum);
  212.             chat(%object, 0, strcat(getName(%destroyedNum), " you CHOKED!"));
  213.         }
  214.         return true;
  215.     }
  216.     return false;
  217. }
  218.  
  219. //-------------------------------------------------------
  220. function playerKilledIt(%destroyedNum, %destroyerNum)
  221. {
  222.     
  223.     if(%destroyedNum == getItNum())
  224.     {    
  225.         %newItKey = strcat(%destroyerNum, "isIt");
  226.         %oldItKey = strcat(%destroyedNum, "isIt");
  227.         %sackKey  = strcat(%destroyerNum, "sack");
  228.  
  229.         dataStore(0, %oldItKey, "No");
  230.         dataStore(0, %newItkey, "Yes");
  231.         dataStore(0, %sackKey, 1 + dataRetrieve(0, %sackKey));
  232.         
  233.         if(playerWonGame(%destroyerNum))
  234.         {
  235.             return true;
  236.         }
  237.         
  238.         else
  239.         {    
  240.             wallDim(strcat(getName(%destroyerNum), " Sacked IT!"));
  241.               wall(strcat(getName(%destroyerNum), " is now IT!"));
  242.         }
  243.         
  244.         resetAmmoTrigger(%destroyerNum);
  245.         resetHealTrigger(%destroyerNum);
  246.  
  247.         
  248.         return true;
  249.     }
  250.     return false;
  251. }
  252.  
  253. //--------------------------------------------------------
  254. function getItNum()
  255. {
  256.     %count = playerManager::getPlayerCount();
  257.     for(%i = 0; %i < %count; %i = %i + 1)
  258.     {
  259.         %curPlayerNum = playerManager::getPlayerNum(%i);
  260.         if(dataRetrieve(0, strcat(%curPlayerNum, "isIt")) == "Yes")
  261.         {
  262.             return %curPlayerNum;
  263.         }    
  264.     }
  265.     //return false if no one is IT
  266.     return false;
  267. }
  268.  
  269. //--------------------------------------------------------
  270. function getHighScorePlayerNum(%playerNum)
  271. {
  272.     %highScore = 0;
  273.     %count = playerManager::getPlayerCount();
  274.     %highScorePlayerNum = "";
  275.     
  276.     for(%i = 0; %i < %count; %i = %i + 1)
  277.     {
  278.         %curPlayerNum = playerManager::getPlayerNum(%i);
  279.         %score = getPlayerScore(%curPlayerNum);
  280.         if(%curPlayerNum != %playerNum && %score >= %highScore)
  281.         {
  282.             %highScore = %score;
  283.             %highScorePlayerNum = %curPlayerNum;
  284.         }
  285.     }
  286.     return %highScorePlayerNum;    
  287. }
  288.  
  289. //--------------------------------------------------------
  290. function initStats(%playerNum)
  291. {
  292.     dataStore(0, strcat(%playerNum, "snuff"), 0 );
  293.     dataStore(0, strcat(%playerNum, "choke"),0);
  294.     dataStore(0, strcat(%playerNum, "sack"),0);
  295.     dataStore(0, strcat(%playerNum, "isIt"),"No");
  296. }
  297.  
  298. //-------------------------------------------------------
  299. function playerWonGame(%playerNum)
  300. {
  301.     if(getPlayerScore(%playerNum) >= $winScore)
  302.     {
  303.         $tagWon = 1;
  304.         
  305.         wall("GAME OVER");
  306.         wall(strcat(getName(%playerNum), " won the Game!")); 
  307.         
  308.         %missionEnd = strcat(getName(%playerNum), " won the Game!");
  309.         messageBox(0, %missionEnd);
  310.  
  311.         %orderFade = "fadeEvent(0, out, 5, 0,0,0 );";
  312.         schedule(%orderFade, 5.0);
  313.         
  314.         schedule("missionEndConditionMet();", 10.0);
  315.  
  316.         return true;
  317.     }
  318.     return false;
  319.  
  320. //--------------------------------------------------------
  321. function cleanUp(%playerNum)
  322. {
  323.     dataRelease(0, strcat(%playerNum, "snuff"));
  324.     dataRelease(0, strcat(%playerNum, "choke"));
  325.     dataRelease(0, strcat(%playerNum, "sack"));
  326.     dataRelease(0, strcat(%playerNum, "isIt"));
  327. }
  328.  
  329. //--------------------------------------------------------
  330. //--Score board stuff
  331.  
  332. function getPlayerScore(%a)
  333. {
  334.     return (getPlayerSnuffs(%a) * $snuffValue + getPlayerSacks(%a) * $sackValue - getPlayerChokes(%a) * $chokeValue); // - getPlayerFriendlyKills(%a) * $friendlyKillValue);
  335. }
  336.  
  337. function getPlayerSnuffs(%playerNum)
  338. {
  339.     return dataRetrieve(0, strcat(%playerNum, "snuff"));
  340. }
  341.  
  342. function getPlayerSacks(%playerNum)
  343. {
  344.     return dataRetrieve(0, strcat(%playerNum, "sack"));    
  345. }
  346.  
  347. function getPlayerItStatus(%playerNum)
  348. {
  349.     return dataRetrieve(0, strcat(%playerNum, "isIt"));
  350.  
  351. }
  352.  
  353. function getPlayerChokes(%playerNum)
  354. {
  355.     return dataRetrieve(0, strcat(%playerNum, "choke"));
  356. }
  357.  
  358. //----------------------------------------------
  359. function initScoreboard()
  360. {
  361.    deleteVariables("$ScoreBoard::PlayerColumn*");
  362.    deleteVariables("$ScoreBoard::TeamColumn*");
  363.  
  364.    // Player ScoreBoard column headings
  365.    $ScoreBoard::PlayerColumnHeader1 = "SCORE";
  366.    $ScoreBoard::PlayerColumnHeader2 = "IT";
  367.    $ScoreBoard::PlayerColumnHeader3 = "SNUFFS";
  368.    $ScoreBoard::PlayerColumnHeader4 = "SACKS";
  369.    $ScoreBoard::PlayerColumnHeader5 = "CHOKES";
  370.    $ScoreBoard::PlayerColumnHeader5 = "PING";
  371.    
  372.    //Player ScoreBoard column functions
  373.    $ScoreBoard::PlayerColumnFunction1 = "getPlayerScore";
  374.    $ScoreBoard::PlayerColumnFunction2 = "getPlayerItStatus";
  375.    $ScoreBoard::PlayerColumnFunction3 = "getPlayerSnuffs";
  376.    $ScoreBoard::PlayerColumnFunction4 = "getPlayerSacks";
  377.    $ScoreBoard::PlayerColumnFunction5 = "getPlayerChokes";
  378.    $ScoreBoard::PlayerColumnFunction5 = "getPing";
  379.  
  380.    // tell server to process all the scoreboard definitions defined above
  381.    serverInitScoreBoard();
  382.     
  383. }
  384. // ------TRIGGER OVERLOADS-------------
  385. //--------------------------------------
  386. function heal::trigger::onEnter(%this, %object)
  387. {
  388.     %playerNum = playerManager::vehicleIdToPlayerNum(%object);
  389.     
  390.     //playSound(%object, IDCV_POWER_ON);
  391.     chat(%object, 0, "Entering repair area.");
  392.     
  393.     if(%playerNum == getItNum() && $healTriggerReady == true)
  394.     {    
  395.         healObject(%object, 10000.0);
  396.         healObject(%object, 10000.0);
  397.         healObject(%object, 10000.0);
  398.         $healTriggerReady = false;
  399.         
  400.         initResetHealTimer(%playerNum);
  401.         
  402.     }
  403. }
  404.  
  405.  
  406. //--------------------------------------
  407. function reload::trigger::onEnter(%this, %object)
  408. {
  409.     %playerNum = playerManager::vehicleIdToPlayerNum(%object);
  410.     
  411.     //playSound(%object, IDCV_POWER_ON);
  412.     chat(%object, 0, "Entering reload area.");
  413.     
  414.     if(%playerNum == getItNum() && $ammoTriggerReady == true)
  415.     {    
  416.         reloadObject(%object, 100.0);
  417.         $ammoTriggerReady = false;
  418.         
  419.         initResetAmmoTimer(%playerNum);
  420.  
  421.     }
  422. }
  423.  
  424.  
  425. //---------------------------------------------
  426. function initResetHealTimer(%playerNum)
  427. {
  428.     %playerCount = playerManager::getPlayerCount();
  429.     %timer = 70 - ((%playerCount - 1) * 5);
  430.  
  431.     if( %timer < 30)
  432.     {    
  433.         %timer = 30;
  434.     }
  435.  
  436.     %order = strcat("resetHealTrigger(", %playerNum, ");");
  437.     schedule (%order, %timer);
  438. }
  439.  
  440. //-----------------------------------------------
  441. function initResetAmmoTimer(%playerNum)
  442. {
  443.     %playerCount = playerManager::getPlayerCount();
  444.     %timer = 70 - ((%playerCount - 1) * 5);
  445.  
  446.     if( %timer < 30)
  447.     {    
  448.         %timer = 30;
  449.     }
  450.  
  451.     %order = strcat("resetAmmoTrigger(", %playerNum, ");");
  452.     schedule (%order, %timer);
  453. }
  454.     
  455. //---------------------------------------------
  456. function resetAmmoTrigger(%playerNum)
  457. {
  458.     %object = playerManager::playerNumToVehicleId(%playerNum);
  459.  
  460.     
  461.     if (%playerNum == getItNum())
  462.     {
  463.         $ammoTriggerReady = true;
  464.         chat(%object, 0, "RELOAD PAD IS READY!");
  465.     }
  466. }
  467.         
  468. //---------------------------------------------
  469. function resetHealTrigger(%playerNum)
  470. {
  471.     %object = playerManager::playerNumToVehicleId(%playerNum);
  472.  
  473.     if (%playerNum == getItNum())
  474.     {
  475.         $healTriggerReady = true;
  476.         chat(%object, 0, "HEAL PAD IS READY!");
  477.     }
  478. }
  479.  
  480. //--------------------------------------
  481.  
  482. function setKillValues()
  483. {    
  484.     echo("setKillValues");
  485.  
  486.     %playerCount = playerManager::getPlayerCount();
  487.  
  488.     if(%playerCount <= 2)
  489.     {
  490.         $snuffValue = 2;
  491.         $sackValue     = 1;
  492.         $chokeValue = 0;
  493.         return;
  494.     }
  495.     
  496.        if(%playerCount == 3)
  497.     {
  498.         $snuffValue = 3;
  499.         $sackValue     = 1;
  500.         $chokeValue = 0;
  501.         return;
  502.     }
  503.     
  504.     if(%playerCount == 4)
  505.     {
  506.         $snuffValue = 4;
  507.         $sackValue     = 2;
  508.         $chokeValue = 1;
  509.         return;
  510.     }
  511.     
  512.     if(%playerCount == 5)
  513.     {
  514.         $snuffValue = 6;
  515.         $sackValue     = 3;
  516.         $chokeValue = 2;
  517.         return;
  518.     }
  519.     
  520.     if(%playerCount == 6)
  521.     {
  522.         $snuffValue = 8;
  523.         $sackValue     = 4;
  524.         $chokeValue = 2;
  525.         return;
  526.     }
  527.     
  528.     if(%playerCount >= 7)
  529.     {
  530.         $snuffValue = 10;
  531.         $sackValue     = 4;
  532.         $chokeValue = 2;
  533.         return;
  534.     }                    
  535.     
  536.     return;
  537. }
  538.  
  539. //------------------------------------------------------
  540.  
  541. function displayKillValues()
  542. {
  543.     wallDim(strcat("POINT UPDATE: SNUFF = ", $snuffValue, " | SACK = ", $sackValue, " | CHOKE = ", $chokeValue));    
  544. }
  545.  
  546. //---------------------------------------------------
  547. function boundryCheck()
  548. {
  549.     %itNum = getItNum();
  550.     %itName = getName(%itNum);
  551.     %itVehicle = playerManager::playerNumToVehicleId(%itNum);
  552.  
  553.     %distance = getDistance("MissionGroup/CenterPoint", %itVehicle);
  554.     
  555.     
  556.     if ( %distance >= 2000.0 )
  557.     {    
  558.         wallDim(strcat(%itName, " has run away!"));
  559.         wallDim(strcat("Say goodbye to your score ", %itName, "!"));
  560.         
  561.         // remove sacks and snuffs but keep chokes
  562.         
  563.         %snuffKey    = strcat(%itNum, "snuff");
  564.         %itKey         = strcat(%itNum, "isIt");
  565.         %sackKey      = strcat(%itNum, "sack");
  566.  
  567.         dataStore(0, %snuffKey, 0);
  568.         dataStore(0, %itKey, "No");
  569.         dataStore(0, %sackKey, 0);
  570.  
  571.         // select new It
  572.  
  573.         %newItNum = getHighScorePlayerNum(%playerNum);
  574.  
  575.            if(%newItNum != "" && %newItNum != 0)
  576.         {
  577.               dataStore(0, strcat(%newItNum, "isIt"), "Yes" );
  578.               wall(strcat(getName(%newItNum), " is now IT!"));
  579.            }
  580.     }
  581.  
  582.     %order = "boundryCheck();";
  583.     schedule(%order, 10.0);
  584.  
  585. }    
  586.  
  587.