
// Function that makes a team waypoint on an object for a certain period
// of time.  Duration is in seconds.

function MakeTeamObjectWayPoint(%Object, %Duration)
{
   %Position = posFromTransform(%Object.getTransform());

   // create a marker on this object
   %Waypoint = new MissionMarker()
   {
      dataBlock = "TeamMarker";
      position = %Position;
   };
   MissionCleanup.add(%Waypoint);
   %Object.Waypoint = %Waypoint;

   %Name = %Object.getName();
   if (%Name $= "")
      %Name = %Object.getDataBlock().name;

   // create a target for this
   %Target = createTarget(%Waypoint, $teamName[%Object.team], "", "", %Name, %Object.team, 0);
   setTargetAlwaysVisMask(%Target, 0xffffffff);

   // Schedule it's removal, if the duration passed is greater than 0
   if (%Duration > 0)
      schedule(%Duration * 1000, 0, ClearTeamObjectWayPoint, %Object);
}

function ClearTeamObjectWayPoint(%Object)
{
   if (%Object.WayPoint !$= "")
   {
      %Object.WayPoint.delete();
      %Object.WayPoint = "";
   }
}