Teleport HUD

From Second Life Wiki
Revision as of 12:39, 18 October 2012 by Kireji Haiku (talk | contribs) (replaced example script with gridwide teleport HUD script using the new llTeleportAgent function)
Jump to navigation Jump to search

Gridwide Teleport HUD

  1. Link 9 prims.
  2. Drop this script.
  3. Add up to 8 landmarks.
  4. Attach to HUD and enjoy!

<lsl> key owner; integer gotTPperms; integer isShowing;

toggle(integer inputInteger) {

   if (inputInteger)
   {
       integer numOfPrims = llGetNumberOfPrims();
       rotation currentRot = llGetRot();
       vector white = <1.0, 1.0, 1.0>;
       vector orange = <1.0, 0.4, 0.0>;
       integer index;
       while (index <= numOfPrims)
       {
           string linkName = llGetLinkName(index);
           if (linkName == "TP HUD for landmarks")
           {
               llSetLinkPrimitiveParamsFast(index,
                   [PRIM_COLOR, ALL_SIDES, ZERO_VECTOR, 1.0,
                   PRIM_COLOR, 3, <0.0, 1.0, 0.0>, 1.0,
                   PRIM_TEXT, "click green button to close\nor select TP destination", <0.0, 1.0, 0.0>, 1.0]);
           }
           else if (linkName == "tp1")
           {
               llSetLinkPrimitiveParamsFast(index, [
                   PRIM_COLOR, ALL_SIDES, white, 1.0,
                   PRIM_POSITION, <0.0, 0.0, -0.0475>*currentRot,
                   PRIM_SIZE, <0.025, 0.025, 0.010>,
                   PRIM_TEXT, llGetInventoryName(INVENTORY_LANDMARK, 0), white, 1.0]);
           }
           else if (linkName == "tp2")
           {
               llSetLinkPrimitiveParamsFast(index, [
                   PRIM_COLOR, ALL_SIDES, orange, 1.0,
                   PRIM_POSITION, <0.0, 0.0, -0.0875>*currentRot,
                   PRIM_SIZE, <0.025, 0.025, 0.01>,
                   PRIM_TEXT, llGetInventoryName(INVENTORY_LANDMARK, 1), orange, 1.0]);
           }
           else if (linkName == "tp3")
           {
               llSetLinkPrimitiveParamsFast(index, [
                   PRIM_COLOR, ALL_SIDES, white, 1.0,
                   PRIM_POSITION, <0.0, 0.0, -0.1275>*currentRot,
                   PRIM_SIZE, <0.025, 0.025, 0.01>,
                   PRIM_TEXT, llGetInventoryName(INVENTORY_LANDMARK, 2), white, 1.0]);
           }
           else if (linkName == "tp4")
           {
               llSetLinkPrimitiveParamsFast(index, [
                   PRIM_COLOR, ALL_SIDES, orange, 1.0,
                   PRIM_POSITION, <0.0, 0.0, -0.1675>*currentRot,
                   PRIM_SIZE, <0.025, 0.025, 0.01>,
                   PRIM_TEXT, llGetInventoryName(INVENTORY_LANDMARK, 3), orange, 1.0]);
           }
           else if (linkName == "tp5")
           {
               llSetLinkPrimitiveParamsFast(index, [
                   PRIM_COLOR, ALL_SIDES, white, 1.0,
                   PRIM_POSITION, <0.0, 0.0, -0.2075>*currentRot,
                   PRIM_SIZE, <0.025, 0.025, 0.01>,
                   PRIM_TEXT, llGetInventoryName(INVENTORY_LANDMARK, 4), white, 1.0]);
           }
           else if (linkName == "tp6")
           {
               llSetLinkPrimitiveParamsFast(index, [
                   PRIM_COLOR, ALL_SIDES, orange, 1.0,
                   PRIM_POSITION, <0.0, 0.0, -0.2475>*currentRot,
                   PRIM_SIZE, <0.025, 0.025, 0.01>,
                   PRIM_TEXT, llGetInventoryName(INVENTORY_LANDMARK, 5), orange, 1.0]);
           }
           else if (linkName == "tp7")
           {
               llSetLinkPrimitiveParamsFast(index, [
                   PRIM_COLOR, ALL_SIDES, white, 1.0,
                   PRIM_POSITION, <0.0, 0.0, -0.2875>*currentRot,
                   PRIM_SIZE, <0.025, 0.025, 0.01>,
                   PRIM_TEXT, llGetInventoryName(INVENTORY_LANDMARK, 6), white, 1.0]);
           }
           else if (linkName == "tp8")
           {
               llSetLinkPrimitiveParamsFast(index, [
                   PRIM_COLOR, ALL_SIDES, orange, 1.0,
                   PRIM_POSITION, <0.0, 0.0, -0.3275>*currentRot,
                   PRIM_SIZE,<0.025, 0.025, 0.01>,
                   PRIM_TEXT, llGetInventoryName(INVENTORY_LANDMARK, 7), orange, 1.0]);
           }
           index++;
       }
   }
   else
   {
       rotation currentRot = llGetRot();
       integer numOfPrims = llGetNumberOfPrims();
       integer index;
       while (index <= numOfPrims)
       {
           string linkName = llGetLinkName(index);
           if (linkName == "TP HUD for landmarks")
           {
               llSetLinkPrimitiveParamsFast(index,
                   [PRIM_COLOR, ALL_SIDES, ZERO_VECTOR, 1.0,
                   PRIM_COLOR, 3, <1.0, 0.0, 0.0>, 1.0,
                   PRIM_TEXT, "<~!~ TP HUD ~!~>", <1.0, 0.0, 0.0>, 1.0]);
           }
           else if (linkName == "tp1" || linkName == "tp2"
                   || linkName == "tp3" || linkName == "tp4"
                   || linkName == "tp5" || linkName == "tp6"
                   || linkName == "tp7" || linkName == "tp8")
           {
               llSetLinkPrimitiveParamsFast(index, [
                   PRIM_COLOR, ALL_SIDES, ZERO_VECTOR, 0.0,
                   PRIM_POSITION, ZERO_VECTOR*currentRot,
                   PRIM_SIZE, <0.01, 0.01, 0.01>,
                   PRIM_TEXT, "", ZERO_VECTOR, 0.0]);
           }
           index++;
       }
   }

}

default {

   changed(integer change)
   {
       if (change & (CHANGED_OWNER | CHANGED_INVENTORY))
           llResetScript();
   }
   attach(key attached)
   {
       if (attached != NULL_KEY)
           llResetScript();
   }
   state_entry()
   {
       llSetLinkPrimitiveParamsFast(LINK_ROOT,
           [PRIM_NAME, "TP HUD for landmarks",
           PRIM_LINK_TARGET, 2, PRIM_NAME, "tp1",
           PRIM_LINK_TARGET, 3, PRIM_NAME, "tp2",
           PRIM_LINK_TARGET, 4, PRIM_NAME, "tp3",
           PRIM_LINK_TARGET, 5, PRIM_NAME, "tp4",
           PRIM_LINK_TARGET, 6, PRIM_NAME, "tp5",
           PRIM_LINK_TARGET, 7, PRIM_NAME, "tp6",
           PRIM_LINK_TARGET, 8, PRIM_NAME, "tp7",
           PRIM_LINK_TARGET, 9, PRIM_NAME, "tp8",]);
       owner = llGetOwner();
       gotTPperms = FALSE;
       isShowing = FALSE;
       toggle(isShowing);
       llRequestPermissions(owner, (PERMISSION_TELEPORT | PERMISSION_TAKE_CONTROLS));
   }
   touch_start(integer num_detected)
   {
       key id = llDetectedKey(0);
       string linkName = llGetLinkName(llDetectedLinkNumber(0));
       string tpDestination;
       if (id != owner)
           return;
       if (gotTPperms && linkName == "TP HUD for landmarks")
       {
           isShowing = !isShowing;
           toggle(isShowing);
       }
       else if (linkName == "tp1")
           tpDestination = llGetInventoryName(INVENTORY_LANDMARK, 0);
       else if (linkName == "tp2")
           tpDestination = llGetInventoryName(INVENTORY_LANDMARK, 1);
       else if (linkName == "tp3")
           tpDestination = llGetInventoryName(INVENTORY_LANDMARK, 2);
       else if (linkName == "tp4")
           tpDestination = llGetInventoryName(INVENTORY_LANDMARK, 3);
       else if (linkName == "tp5")
           tpDestination = llGetInventoryName(INVENTORY_LANDMARK, 4);
       else if (linkName == "tp6")
           tpDestination = llGetInventoryName(INVENTORY_LANDMARK, 5);
       else if (linkName == "tp7")
           tpDestination = llGetInventoryName(INVENTORY_LANDMARK, 6);
       else if (linkName == "tp8")
           tpDestination = llGetInventoryName(INVENTORY_LANDMARK, 7);
       if (tpDestination == "")
           llOwnerSay("Invalid destination!");
       else
           llTeleportAgent(owner, tpDestination, ZERO_VECTOR, ZERO_VECTOR);
   }
   control(key id,integer held, integer change)
   {
       return;
   }
   run_time_permissions(integer perm)
   {
       if (perm & PERMISSION_TAKE_CONTROLS)
           llTakeControls(CONTROL_UP,TRUE,TRUE);
       if (perm & PERMISSION_TELEPORT)
           gotTPperms = TRUE;
   }

} </lsl>