
datablock TriggerData(defaultTrigger)
{
   tickPeriodMS = 200;
};

datablock TriggerData(hairTrigger)
{
   tickPeriodMS = 30;
};

datablock TriggerData(slowTrigger)
{
   tickPeriodMS = 1000;
};

datablock TriggerData(stationTrigger)
{
   tickPeriodMS = 30;
};

datablock TriggerData(markerTrigger)
{
   tickPeriodMS = 100000;
};

datablock TriggerData(defaultTeamTrigger)
{
   tickPeriodMS = 200;
};

function defaultTeamTrigger::onEnterTrigger(%this, %Trigger, %TriggeringObject)
{
   %Group = %Trigger.getGroup();
   if (%Group $= "")
      return;

   // Loop through everything in the same group as the trigger and activate
   // it as well.  If it can be hacked, then pass that data as well.
   %i = 0;
   while (%i < %Group.getCount())
   {
      %Object = %Group.getObject(%i);
      %CanBreak = %Object.CanBreak;

      if (%CanBreak $= "")
         %CanBreak = false;

      if (TriggerCheck(%Trigger, %Object, %CanBreak) == true)
         %Object.onTrigger(%Trigger, 1);

      %i++;
   }
}

function defaultTeamTrigger::onLeaveTrigger(%this, %Trigger, %TriggeringObject)
{
   %Group = %Trigger.getGroup();
   if (%Group $= "")
      return;

   // Loop through everything in the same group as the trigger and activate
   // it as well.  If it can be hacked, then pass that data as well.
   %i = 0;
   while (%i < %Group.getCount())
   {
      %Object = %Group.getObject(%i);

      %CanBreak = %Object.CanBreak;
      if (%CanBreak $= "")
         %CanBreak = false;

      if (TriggerCheck(%Trigger, %Object, %CanBreak) == true)
         %Object.onTrigger(%Trigger, 1);

      %i++;
   }
}

// This function determines wheither a player can active the trigger based
// on the team of the player and trigger.
function TriggerCheck(%Trigger, %Player)
{

   if (%Trigger.team == 0)
      return(true);

   if (%Trigger.team == %Player.team)
      return(true);

   return(false);
}

function defaultTeamTrigger::onTickTrigger(%this, %Trigger)
{
   %Group = %Trigger.getGroup();
   if (%Group $= "")
      return;

   %Tick = false;

   // Check to see if the people within the trigger are on the right team
   %i = 0;
   while (%i < %Trigger.getNumObjects())
   {
      %Object = %Group.getObject(%i);

      %CanBreak = %Object.CanBreak;
      if (%CanBreak $= "")
         %CanBreak = false;

      if (TriggerCheck(%Trigger, %Object, %CanBreak) == true)
      {
         %Tick = true;
         break;
      }

      %i++;
   }

   // If something was found we call the code for that
   if (%Tick == true)
   {
      %i = 0;
      while (%i < %Group.getCount())
      {
         %Object = %Group.getObject(%i);
         %Object.onTriggerTick(%Trigger);

         %i++;
      }
   }
}

// --------------------------------------------------------------------------
// Mappers Triggers 
// --------------------------------------------------------------------------
// This trigger is provided to mappers so that they can do whatever they want
// and not mess up the mod.  It will reset each map.

datablock TriggerData(MapperTrigger)
{
   tickPeriodMS = 200;
};

function MapperTrigger::onEnterTrigger(%data, %Object, %CollidingObject)  
{

}

function MapperTrigger::onLeaveTrigger(%data, %Object, %CollidingObject)
{

}

function MapperTrigger::onTickTrigger(%data, %Object)
{

}

// --------------------------------------------------------------------------
// Game Triggers 
// --------------------------------------------------------------------------

datablock TriggerData(gameTrigger)
{
   tickPeriodMS = 50;
};

function gameTrigger::onEnterTrigger(%data, %Object, %CollidingObject)  
{
   Game.onEnterTrigger(%Object.name, %data, %Object, %CollidingObject);
}

function gameTrigger::onLeaveTrigger(%data, %Object, %CollidingObject)
{
   Game.onLeaveTrigger(%Object.name, %data, %Object, %CollidingObject);
}

function gameTrigger::onTickTrigger(%data, %Object)
{
   Game.onTickTrigger(%Object.name, %data, %Object);
}

// ------------------------------------------------------------------------
// Regular Teleporter Trigger
// ------------------------------------------------------------------------

datablock TriggerData(TeleporterTrigger)
{
   tickPeriodMS = 200;
};

function TeleporterTrigger::onTickTrigger(%this, %trigger)
{
   // Stops Console Spamming
}

function TeleporterTrigger::onEnterTrigger(%Data, %Trigger, %Player)  
{
   //make sure it's a player object, and that that object is still alive
   if (%Player.getDataBlock().className !$= "Armor" || %Player.getState() $= "Dead")
      return; 

   if (%Player.CantTeleport == true)
      return;

   %Teleporter = %Trigger.Teleporter;
   %Player.Teleporter = %Teleporter;
   %TeleporterData = %Teleporter.getDataBlock();

   if (%Teleporter.NeedsPower == true && %Teleporter.isPowered() == false)
   {
      messageClient(%Player.client, 'msgStationDenied', '\c2Teleport Station is not powered!');
      return;
   }

   // Mark the teleporter as occupied
   if (%Teleporter.UsedBy $= "")
      %Teleporter.UsedBy = 0;
   %Teleporter.UsedBy++;

   %Player.inStation = true;
   commandToClient(%Player.client,'setStationKeys', true);

   // Check for team of player and station
   if (TriggerCheck(%Trigger.teleporter, %Player) == false)
   {
      if (%Player.Special !$= "CodeBreaker")
      {
         %Teleporter.playAudio(2, StationAccessDeniedSound);
         messageClient(%Player.client, 'msgStationDenied', '\c2Access Denied -- Wrong team.');
      }
      return;
   }

   if (%Teleporter.getDamageLevel() > %TeleporterData.disabledLevel)
   {
      messageClient(%Player.client, 'msgStationDisabled', '\c2Teleporter is disabled.');
      return;
   } 

   if (%Player.client.ChooseTeleport $= "" || %Teleporter.team != %Player.team)
      %Teleporter.getDataBlock().AttemptTeleport(%Player, %Teleporter);
   else {
      if (%Teleporter.team == 1)
         %Count = $Team1TeleporterCount;
      else
         %Count = $Team2TeleporterCount;

      if (%Count < 2)
         return;

      // If there are 2 pads and the client is on auto, then just teleport them.
      if (%Count == 2 && %Player.client.ChooseTeleport == 1)
      {
         %Teleporter.getDataBlock().AttemptTeleport(%Player, %Teleporter);
         return;
      }
         
      %Player.setVelocity("0 0 0");

      %Rotation = rotFromTransform(%Player.getTransform());
      %Position = posFromTransform(%Teleporter.getTransform());

      %PositionXY = getWords(%Position, 0, 1);
      %PositionZ = getWord(%Position, 2) + 0.15;
      %Position = %PositionXY @ " " @ %PositionZ;

      %Player.setTransform(%Position @ " " @ %Rotation);

      serverCmdGetTeleporterList(%Player.client);
   }
}

// Clear the Players Teleporter Setting so that it is not decremented when they die.
function TeleporterTrigger::onLeaveTrigger(%Data, %Trigger, %Player)  
{
   // If the player is on the other team, let the hack trigger handle them leaving
   if (TriggerCheck(%Trigger.teleporter, %Player) == false)
      return;
  
   %Player.inStation = false;
   commandToClient(%Player.client,'setStationKeys', false);

   %Player.mountImage(%Player.lastWeapon, $WeaponSlot);

   %Player.Teleporter = "";
   %Teleporter = %Trigger.Teleporter;

   %Teleporter.UsedBy--;

   if (%Teleporter.UsedBy < 0)
      %Teleporter.UsedBy = 0;
}

// ------------------------------------------------------------------------
// Hacking Teleporter Stuff
// ------------------------------------------------------------------------

datablock TriggerData(HackersTeleportTrigger)
{
   tickPeriodMS = 200;
};

function HackersTeleportTrigger::onTickTrigger(%this, %trigger)
{
   // Stops Console Spamming
}

// This function checks to make sure that the player is alive, that they are on the
// opposite team from the one who owns the teleporter, that they are allowed to teleport,
// that the teleporter is powered and functional, that the player has a code breaker,
// and then it will start the hacking
function HackersTeleportTrigger::onEnterTrigger(%Data, %Trigger, %Player)  
{
   // If not a player, stop
   if (%Player.getDataBlock().className !$= "Armor")
      return; 

   // If the player is not alive, stop.
   if (%Player.getState() $= "Dead")
      return;

   // If the Player is on the same team as the trigger, stop
   %Teleporter = %Trigger.Teleporter; 
   if (TriggerCheck(%Teleporter, %Player) == true)
      return;

   // We Load the information relating to the teleporter now
   %Player.Teleporter = %Teleporter;
   %TeleporterData = %Teleporter.getDataBlock();

   // Mark the teleporter as occupied
   if (%Teleporter.UsedBy $= "")
      %Teleporter.UsedBy = 0;
   %Teleporter.UsedBy++;

   // If the Teleporter is down, don't do anything
   if (%Teleporter.getDamageLevel() > %TeleporterData.disabledLevel)
   {
      messageClient(%Player.client, 'msgStationDisabled', '\c2Teleporter is disabled.');
      return;
   }

   if (%Teleporter.NeedsPower == true && %Teleporter.isPowered() == false)
   {
      messageClient(%Player.client, 'msgStationDenied', '\c2Teleport Station is not powered!');
      return;
   }

   // If not premitted to teleporter, then don't
   if (%Player.CantTeleport == true)
      return;

   // If the enemy doesn't have a Code Breaker, stop
   if (%Player.Special !$= "CodeBreaker")
      return;

   // If the player is attempting to hack something else, stop that and start
   // on this.
   if (%Player.HackingSchedule !$= "")
   {
      cancel(%Player.HackingSchedule);
      %Player.HackingSchedule = "";
   }

   // Somewhat based on how experienced the player is with the hacker a random
   // value is decided for when the hacking is complete.
   %Experience = %Player.client.HackingExperience;
   %Random = (getRandom() * (6 - %Experience)) + (8 - %Experience);

   // Start the hacking
   %Player.HackingSchedule = %Player.schedule(%Random * 1000, HackingTeleportCheck, %Trigger);

   %Message = "Starting to Hack into the enemy teleport pad.";
   messageClient(%Player.client, '', %Message);
}

// Record that the player has moved away from the object they are/were trying to hack
function HackersTeleportTrigger::onLeaveTrigger(%Data, %Trigger, %Player)  
{
   // If not a player, stop
   if (%Player.getDataBlock().className !$= "Armor")
      return; 

   // If the player is not alive, stop.
   if (%Player.getState() $= "Dead")
      return;

   // If the Player is on the same team as the trigger, stop
   %Teleporter = %Trigger.Teleporter; 
   if (TriggerCheck(%Teleporter, %Player) == true)
      return;

   // We Load the information relating to the teleporter now
   %Player.Teleporter = %Teleporter;
   %TeleporterData = %Teleporter.getDataBlock();

   %Player.mountImage(%Player.lastWeapon, $WeaponSlot);

   // Mark the teleporter as occupied
   %Teleporter.UsedBy--;
   if (%Teleporter.UsedBy < 0)
      %Teleporter.UsedBy = 0;

   // If the enemy doesn't have a Code Breaker, stop
   if (%Player.Special !$= "CodeBreaker")
      return;

   if (%Player.HackingSchedule !$= "")
   {
      cancel(%Player.HackingSchedule);
      %Player.HackingSchedule = "";

      %Message = "Stopped trying to Hack into the enemy teleport pad.";
      messageClient(%Player.client, '', %Message);   
   }
}

function Player::HackingTeleportCheck(%Player, %Trigger)
{
   if (%Player.getState() $= "Dead")
      return;

   %Client = %Player.client;
   %ExperienceLevel = %Client.HackingExperience;
   %CaughtLevel = 0.65;

   // See if the player has hacked the security system
   %Random = getRandom();
   if (%Random > %CaughtLevel)
   {
      // Notify the player that thier experience is what saved them.
      if (%Random < %CaughtLevel + (%ExperienceLevel / 12))
      {
         messageClient(%Player.client, '', "Because of quick thinking, you were able to avoid detection.");
      } else {
         %Caught = true;            
      }
   }

   if (%Caught == false)
      %Client.HackingExperience += 0.12;

   if (%Client.HackingExperience > 3)
      %Client.HackingExperience = 3;

   %Teleporter = %Trigger.Teleporter;
   %Teleporter.getDataBlock().AttemptTeleport(%Player, %Teleporter, %Caught);
}

// -------------------------------------------------------------------------------
// Hacking Forcefield Stuff
// -------------------------------------------------------------------------------

// Causes the forcefield to open for a few seconds.
function ForceFieldCycle(%ForceField)
{
   %Random = (getRandom() * 2) + 2.5;

   ForceFieldDown(%ForceField);

   %ForceField.CycleSchedule = schedule(%Random * 1000, 0, ForceFieldUp, %ForceField);
}

// Opens the forcefield
function ForceFieldDown(%ForceField)
{
   %ForceField.open();

   if (%ForceField.PZone !$= "")
      %ForceField.PZone.deactivate();
}

// Closes the forcefield back
function ForceFieldUp(%ForceField)
{
   %ForceField.close();

   if (%ForceField.PZone !$= "")
      %ForceField.PZone.activate();

   // Clear the restore schedule marker
   if (%ForceField.CycleSchedule !$= "")
      %ForceField.CycleSchedule = "";

   KillAllPlayersWithinZone(%ForceField.getDataBlock(), %ForceField, %ForceField.Team);
}

// If power is restored to the Forcefield (The generator was fixed)
// then reinstate the forcefield.
function deployFieldBare::gainPower(%data, %ForceField)
{
   if (%ForceField.CycleSchedule !$= "")
      return;

   Parent::gainPower(%data, %ForceField);
   %ForceField.close();

   // Activate the field's physical zone, if it has one
   if (%ForceField.PZone !$= "")
      %ForceField.PZone.activate();
}

// If power is cut to the Forcefield (The generator was damaged)
// then cut the forcefield.
function deployFieldBare::losePower(%data, %ForceField)
{
   Parent::losePower(%data, %ForceField);
   %ForceField.open();

   // Deactivate the field's physical zone, if it has one.
   if (%ForceField.PZone !$= "")
      %ForceField.PZone.deactivate();
}

datablock TriggerData(HackersForceFieldTrigger)
{
   tickPeriodMS = 200;
};

function HackersForceFieldTrigger::onTickTrigger(%this, %trigger)
{
   // Stops Console Spamming
}

// This function checks to make sure that the player is alive, that they are on the
// opposite team from the one who owns the teleporter, that they are allowed to teleport,
// that the teleporter is powered and functional, that the player has a code breaker,
// and then it will start the hacking
function HackersForceFieldTrigger::onEnterTrigger(%Data, %Trigger, %Player)  
{
   // If not a player, stop
   if (%Player.getDataBlock().className !$= "Armor")
      return; 

   // If the player is not alive, stop.
   if (%Player.getState() $= "Dead")
      return;

   // If the Player is on the same team as the trigger, stop
   if (TriggerCheck(%Trigger, %Player) == true)
      return;

   // We Load the information relating to the teleporter now
   %Generator = %Trigger.Generator;
   %ForceField = %Trigger.ForceField; 
   %Player.ForceField = %ForceField;
   %ForceFieldData = %ForceField.getDataBlock();

   // If the ForceField Generator is down, don't do anything
   if (%Generator.getDamageLevel() > %Generator.getDataBlock().disabledLevel)
      return;

   // If the enemy doesn't have a Code Breaker, stop
   if (%Player.Special !$= "CodeBreaker")
      return;

   // If the player is attempting to hack something else, stop that and start
   // on this.
   if (%Player.HackingSchedule !$= "")
   {
      cancel(%Player.HackingSchedule);
      %Player.HackingSchedule = "";
   }

   %Message = "Starting to hack into the enemy forcefield control array.";
   messageClient(%Player.client, '', %Message);

   // Somewhat based on how experienced the player is with the hacker a random
   // value is decided for when the hacking is complete.
   %Experience = %Player.client.HackingExperience;
   %Random = (getRandom() * (5 - %Experience)) + (7 - %Experience);

   // Start the hacking
   %Player.HackingSchedule = %Player.schedule(%Random * 1000, HackingForceFieldCheck, %Trigger);
}

// Record that the player has moved away from the object they are/were trying to hack
function HackersForceFieldTrigger::onLeaveTrigger(%Data, %Trigger, %Player)  
{
   // If not a player, stop
   if (%Player.getDataBlock().className !$= "Armor")
      return; 

   // If the player is not alive, stop.
   if (%Player.getState() $= "Dead")
      return;

   // If the Player is on the same team as the trigger, stop
   if (TriggerCheck(%Trigger, %Player) == true)
      return;

   // If the enemy doesn't have a Code Breaker, stop
   if (%Player.Special !$= "CodeBreaker")
      return;

   if (%Player.HackingSchedule !$= "")
   {
      cancel(%Player.HackingSchedule);
      %Player.HackingSchedule = "";

      %Message = "Stopped trying to hack into the enemy forcefield control array.";
      messageClient(%Player.client, '', %Message);   
   }
}

function Player::HackingForceFieldCheck(%Player, %Trigger)
{
   if (%Player.getState() $= "Dead")
      return;

   %Client = %Player.client;
   %ExperienceLevel = %Client.HackingExperience;
   %CaughtLevel = 0.70;

   // See if the player has hacked the security system
   %Random = getRandom();
   if (%Random > %CaughtLevel)
   {
      // Notify the player that thier experience is what saved them.
      if (%Random < %CaughtLevel + (%ExperienceLevel / 12))
      {
         messageClient(%Player.client, '', "Because of quick thinking, you were able to avoid detection.");
      } else {
         messageClient(%Player.client, 'msgStationDenied', "You enter the wrong series of key strokes and set off the alarms.");
         TeamHackNotify(%Trigger.Generator);
         return;       
      }
   }
 
   %Client.HackingExperience += 0.1;
   if (%Client.HackingExperience > 3)
      %Client.HackingExperience = 3;

   messageClient(%Player.client, '', "You have hacked the forcefield control array; forcefield cycling now.");

   ForceFieldCycle(%Trigger.ForceField);
}

// ------------------------------------------------------------------
// Hacking Deployed Inventory Stations
// ------------------------------------------------------------------

datablock TriggerData(hackstationTrigger)
{
   tickPeriodMS = 200;
};

function hackstationTrigger::onTickTrigger(%this, %trigger)
{
   // Stops Console Spamming
}

function hackstationTrigger::onEnterTrigger(%data, %Trigger, %Player)
{
   // If not a player, stop
   if (%Player.getDataBlock().className !$= "Armor")
      return; 

   // If the player is not alive, stop.
   if (%Player.getState() $= "Dead")
      return;

   // If the Player is on the same team as the trigger, stop
   if (TriggerCheck(%Trigger, %Player) == true)
      return;

   // If the enemy doesn't have a Code Breaker, stop
   if (%Player.Special !$= "CodeBreaker")
      return;

   // If the Station is down, don't do anything
   if (%Station.getDamageLevel() > %Station.getDataBlock().disabledLevel)
   {
      messageClient(%Player.client, 'msgStationDisabled', "\c2Station is disabled.");
      return;
   }

   // If the player is attempting to hack something else, stop that and start
   // on this.
   if (%Player.HackingSchedule !$= "")
   {
      cancel(%Player.HackingSchedule);
      %Player.HackingSchedule = "";
   }

   %Player.inStation = true;

   %Client = %Player.client;
   commandToClient(%Client, 'setStationKeys', true);

   // Somewhat based on how experienced the player is with the hacker a random
   // value is decided for when the hacking is complete.
   %Experience = %Player.client.HackingExperience;
   %Random = (getRandom() * (6 - %Experience));

   // Start the hacking
   %Player.HackingSchedule = %Player.schedule(%Random * 1000, HackingStationCheck, %Trigger);

   %Message = "Starting to hack into enemy deployed inventory station.";
   messageClient(%Player.client, '', %Message);
}

function hackstationTrigger::onLeaveTrigger(%Data, %Trigger, %Player)
{
   // If not a player, stop
   if (%Player.getDataBlock().className !$= "Armor")
      return; 

   // If the player is not alive, stop.
   if (%Player.getState() $= "Dead")
      return;

   // If the Player is on the same team as the trigger, stop
   if (%Player.team == %Trigger.team)
      return;

   if (%Player.HackingSchedule !$= "")
   {
      cancel(%Player.HackingSchedule);
      %Player.HackingSchedule = "";

      %Message = "Stopped trying to hack into the enemy deployable Inventory Station.";
      messageClient(%Player.client, '', %Message);   
   }

   %Station = %Trigger.station;

   %Player.inStation = false;
   commandToClient(%Player.client,'setStationKeys', false);

   // If the player is in a station, then stop repairing and give them thier weapon back
   if (%Player.station !$= "")
   {
      if (%Station.triggeredBy == %Player)
      {
         %StationData = %Station.getDataBlock();

         %StationData.stationFinished(%Station);
         %StationData.endRepairing(%Station);
         %Station.triggeredBy = "";
         %StationData.stationTriggered(%Station, 0);
               
         if (%Player.getMountedImage($WeaponSlot) == 0 || %Player.getMountedImage($WeaponSlot) $= "")
         {
	    if (%Player.inv[%Player.lastWeapon])
               %Player.use(%Player.lastWeapon);
	         
            if (%Player.getMountedImage($WeaponSlot) == 0) 
               %Player.selectWeaponSlot(0);
         }
      } else {
         // If a hack is running, stop it.
         if (%Player.HackingSchedule !$= "")
         {
            cancel(%Player.HackingSchedule);
            %Player.HackingSchedule = "";

            %Message = "Stopped trying to hack into the enemy deployed inventory station.";
            messageClient(%Player.client, '', %Message);   
         }
      }
   }
}

function Player::HackingStationCheck(%Player, %Trigger)
{
   if (%Player.getState() $= "Dead")
      return;

   // Load the name of the object to hack into
   %Client = %Player.client;
   %ExperienceLevel = %Client.HackingExperience;
   %CaughtLevel = 0.80;

   %Caught = false;

   // See if the player has hacked the security system
   %Random = getRandom();
   if (%Random > %CaughtLevel)
   {
      // Notify the player that thier experience is what saved them.
      if (%Random < %CaughtLevel + (%ExperienceLevel / 14))
      {
         messageClient(%Player.client, '', "Because of quick thinking, you were able to avoid detection.");
      } else {
         messageClient(%Player.client, 'msgStationDenied', "You enter the wrong series of key strokes and set off the alarms.");
         TeamHackNotify(%Trigger.Station);
         return;
      }
   }

   // Since this is easier to hack, give them less experience
   %Client.HackingExperience += 0.08;

   if (%Client.HackingExperience > 3)
      %Client.HackingExperience = 3;

   if (%Player.HackingSchedule !$= "")
   {
      cancel(%Player.HackingSchedule);
      %Player.HackingSchedule = "";
   }

   messageClient(%Client, 'msgStationDenied', "You hack the deployed inventory station.");

   ActivateRemoteStation(%Trigger, %Player);
}

// Activate the Remote Station
function ActivateRemoteStation(%Trigger, %Player)
{
   %Station = %Trigger.station;
   %Station.getDataBlock().setPlayersPosition(%Station, %Trigger, %Player);

   %Client = %Player.client;
   messageClient(%Client, 'CloseHud', "", 'inventoryScreen');
   commandToClient(%Client, 'TogglePlayHuds', true);

   %Station.triggeredBy = %Player;
   %Station.getDataBlock().stationTriggered(%Station, 1);

   %Player.station = %Station;
   if (%Player.getMountedImage($WeaponSlot) == 0)
      %Player.lastWeapon = "";
   else
      %Player.lastWeapon = %Player.getMountedImage($WeaponSlot).getName().item;

   %Player.unmountImage($WeaponSlot);   
}

//------------------------------------------------------------------------------------------
// This Trigger is used to stop people from falling forever, those entering it die as though
// they hit the ground hard.
datablock TriggerData(AltitudeDeathTrigger)
{
   tickPeriodMS = 1000;
};

function AltitudeDeathTrigger::onEnterTrigger(%this, %Trigger, %Player)
{
   if (%Player.getState() $= "Dead")
      return;

   %Player.ScriptKill($DamageType::Ground);

   %Name = getTaggedString(%Player.client.name);
   if (%Player.client.sex $= "Male")
      %Possesive = "his";
   else
      %Possesive = "her";

   %Message = %Name @ " falls to " @ %Possesive @ " death.";

   MessageAll('msgSelfKill', %Message);
}

function AltitudeDeathTrigger::onLeaveTrigger(%this, %Trigger, %Player)
{
   if (%Player.getState() $= "Dead")
      return;

   %Player.ScriptKill($DamageType::Ground);

   %Name = getTaggedString(%Player.client.name);
   if (%Player.client.sex $= "Male")
      %Possesive = "his";
   else
      %Possesive = "her";

   %Message = %Name @ " falls to " @ %Possesive @ " death.";

   MessageAll('msgSelfKill', %Message);
}

function MakeAltitudeTrigger(%Altitude)
{
   %Position = "0 0 " @ %Altitude;

   %Trigger = new Trigger()
   {
      dataBlock = AltitudeDeathTrigger;
      polyhedron = "-0.75 0.75 0.1 1.5 0.0 0.0 0.0 -1.5 0.0 0.0 0.0 2.3";
      position = %Position;
      scale = "2500 2500 250";
   };             
   MissionCleanup.add(%Trigger);
}

// --------------------------------------------------------------------------
// Springboard Trigger
// --------------------------------------------------------------------------
// This trigger is for the springboard

datablock TriggerData(SpringboardTrigger)
{
   tickPeriodMS = 200;
};

function SpringboardTrigger::onEnterTrigger(%data, %Trigger, %Player)
{
   %Player.SpringBoard();

   %Pad = %Trigger.SpringBoard;

   %Position = posFromTransform(%Pad.getTransform());
   %PositionXY = getWords(%Position, 0, 2);
   %PositionZ = getWord(%Position, 2) + 0.4;

   %Pad.setTransform(%PositionXY @ " " @ %PositionZ @ " " @ %Pad.Rotation);

   %Pad.schedule(850, setTransform, %PositionXY @ " " @ %PositionZ - 0.8 @ " " @ %Pad.Rotation);
   %Pad.schedule(1800, setTransform, %PositionXY @ " " @ %PositionZ + 0.2 @ " " @ %Pad.Rotation);
   %Pad.schedule(2400, setTransform, %PositionXY @ " " @ %PositionZ @ " " @ %Pad.Rotation);
}

function SpringboardTrigger::onLeaveTrigger(%data, %Trigger, %Player)
{

}

function SpringboardTrigger::onTickTrigger(%data, %Trigger)
{

}
