OSSL Script Library/Teleport Map

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
(New page created for the script library)
 
m
Line 4: Line 4:
  
 
<source lang="lsl">
 
<source lang="lsl">
 +
// -----------------------
 +
// ++++ TELEPORT MAP ++++
 +
//  by FRITIGERN GOTHLY
 +
//    Version 1.1
 +
// -----------------------
 +
// Put a region map on a prim, and use that to teleport around.
 +
// This teleport system is amazingly accurate.
 +
// Do note that when a change is made to the region, the map on the
 +
// teleporter will only be updated when the rest of the world map is updated.
 +
 +
 
key map;                    // This is where the texture UUID will be stored.
 
key map;                    // This is where the texture UUID will be stored.
 
integer timeout = 60;      // This many seconds for the map to refresh.
 
integer timeout = 60;      // This many seconds for the map to refresh.
 
integer region_size;        // We need this to do a little math later.
 
integer region_size;        // We need this to do a little math later.
 +
integer face = 4;          // Which side of the prim the map should appear on.
  
refresh(){                                                                                     // A user-defined function to keep the code short.
+
refresh(){
     map = osGetMapTexture();                                                                   // Get the map texture
+
     map = osGetMapTexture();                                                                       // Get the map texture
     llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_TEXTURE, 4, map, <1.0,1.0,0>, <0,0,0>, 0,      // Put the map texture on side 4 of a prim
+
     llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_TEXTURE, face, map, <1.0,1.0,0>, <0,0,0>, 0,      // Put the map texture on the chosen side of a prim
                           PRIM_COLOR,4,<1,1,1>,1,                                              // Set the color of side 4 to white.
+
                           PRIM_COLOR,face,<1,1,1>,1,                                              // Set the color of the chosen side to white.
                           PRIM_FULLBRIGHT,4,1]);                                                // Set side 4 to full bright.
+
                           PRIM_FULLBRIGHT,face,1]);                                                // Set the chosen side to full bright.
 
}
 
}
  
Line 27: Line 39:
 
     touch_start(integer numdet)
 
     touch_start(integer numdet)
 
     {
 
     {
         if(llDetectedTouchFace(0) != 4) return;         // If the prim is not touched on side 4, then do nothing.
+
         if(llDetectedTouchFace(0) != face) return;     // If the prim is not touched on the chosen side, then do nothing.
 
         key toucher = llDetectedKey(0);                // Get the UUID of the person that touched the map.
 
         key toucher = llDetectedKey(0);                // Get the UUID of the person that touched the map.
 
         vector target = llDetectedTouchUV(0);          // Find out where the map has been touched
 
         vector target = llDetectedTouchUV(0);          // Find out where the map has been touched
Line 40: Line 52:
 
     }
 
     }
 
      
 
      
     on_rez(integer la)
+
     on_rez(integer start_param)
 
     {
 
     {
 
         llResetScript();    // Reset the script when rezzed to ensure a fresh map on the prim.
 
         llResetScript();    // Reset the script when rezzed to ensure a fresh map on the prim.

Revision as of 13:19, 21 October 2015

This script will put a region map on the containing prim, and will instantly teleport the user to the map location that they clicked on.

The code contains a lot of comments, explaining what does what, and why it is there.

// -----------------------
// ++++ TELEPORT MAP ++++
//  by FRITIGERN GOTHLY
//     Version 1.1
// -----------------------
// Put a region map on a prim, and use that to teleport around.
// This teleport system is amazingly accurate.
// Do note that when a change is made to the region, the map on the 
// teleporter will only be updated when the rest of the world map is updated.
 
 
key map;                    // This is where the texture UUID will be stored.
integer timeout = 60;       // This many seconds for the map to refresh.
integer region_size;        // We need this to do a little math later.
integer face = 4;           // Which side of the prim the map should appear on.
 
refresh(){
    map = osGetMapTexture();                                                                       // Get the map texture
    llSetLinkPrimitiveParamsFast(LINK_THIS,[PRIM_TEXTURE, face, map, <1.0,1.0,0>, <0,0,0>, 0,      // Put the map texture on the chosen side of a prim
                          PRIM_COLOR,face,<1,1,1>,1,                                               // Set the color of the chosen side to white.
                          PRIM_FULLBRIGHT,face,1]);                                                // Set the chosen side to full bright.
}
 
default
{
    state_entry()
    {
        vector size = osGetRegionSize();    // Find out how large the region is.
        region_size = (integer)size.x;      // Because the length and the width of a region MUST be equal, we only need one of the floats from the vector.        
        refresh();                          // Refresh the map texture
        llSetTimerEvent(timeout);           // And now we make ure that the map texture gets updated every X seconds. (default 60)
    }
 
    touch_start(integer numdet)
    {
        if(llDetectedTouchFace(0) != face) return;      // If the prim is not touched on the chosen side, then do nothing.
        key toucher = llDetectedKey(0);                 // Get the UUID of the person that touched the map.
        vector target = llDetectedTouchUV(0);           // Find out where the map has been touched
            target.x = (region_size*target.x);          // Multiply the X-position of where the map was touched with the region size. This changes value of the vector
            target.y = (region_size*target.y);          // Multiply the Y-position of where the map was touched with the region size. This changes value of the vector
        osTeleportAgent(toucher, target, ZERO_VECTOR);  // Teleport the person who touched the prim to the corresponding coordinates in the region.
    }
 
    timer()
    {
        refresh();      // Refresh the map when the timer runs out.
    }
 
    on_rez(integer start_param)
    {
        llResetScript();    // Reset the script when rezzed to ensure a fresh map on the prim.
    }
}
Personal tools
General
About This Wiki