llSetRegionPos Teleporter Script for Second Life, Kitely, or OpenSim

Make A Simple llSetRegionPos Teleporter for Second Life


This is an LSL teleporter script for use in Second Life® or OpenSim that uses the new llSetRegionPos function.  When placed in a prim this script will turn the prim into a regional teleporter.  This teleporter is suitable for simple tasks such as teleporting between floors in a home or up to a skybox.  I’ve done minimum testing of  this script in OpenSim, but it seems to work in Kitely (Kitely.com).



  • The x & y components of vector destination must be between -10 and 266.  Note that a negative value or a value over 256 will place you in the adjacent region.  The script will fail if you try to go more than 10m into an adjacent region.
  • The z component of the vector destination must be between 0 and 4096.  If you set it to 4096 there will be no headroom for your avatar since the maximum height in SL is 4096, so use a lower value to allow for headroom.   If the z coordinate is below ground level the teleporter will move the avatar to ground level.
  • See the llSetRegionPos function page for specific details on how this function works.
  • If you do not have permission to move a prim onto the property at the coordinates you enter into the vector destination, the prim will be lost and the teleport may fail.  Generally this means you must own, or be part of a group that owns, the property at both the teleporter location and the destination.
  • The script may be compiled with or without Mono.
  • An apparent change in the SL servers to the llSetRegionPos function showed up sometime in August 2012, it seems to slows this script down considerably when used for teleport distances over 30m.  You can read more about it here: http://community.secondlife.com/t5/LSL-Scripting/llSetRegionPos-teleporter-problems/td-p/1656421
  • The avatar’s camera will often temporarily display the view from the region’s 0,0,0 coordinates on longer teleports.  This is a known bug.  To avoid it lengthen the sleep function to around 5.0 seconds.  You can play with different sleep values, the length needed varies for different sims and users.
  • Keep in mind that the teleporter script is run on the sim’s server.  But the graphics rendering is done by the viewer on the user’s computer.  So the script is being processed at two places.  Generally the server is much faster than the viewer, so at times it will “outrun” the viewer.  This can cause the script execution to stumble and instructions may be missed or executed too soon.  There’s an excellent example of that in this script.  In this script the server calls for the  llSetRegionPos function to execute.  This function tells the viewer to move the teleporter and avatar to the new destination.  It takes the server a few milliseconds to issue that command and send it over the Internet to the viewer.  Once it has done that it is through with that function and moves to the next, which is to unsit the avatar.  So it sends that unsit command to the viewer as well.  Meanwhile the poor viewer is struggling under the graphics load of rendering all this.  When the viewer gets the command for llSetRegionPos it begins to move the teleporter to the new location.  This takes some time because of the need to load new graphics to display the new location.   The viewer receives the unsit command while it is still moving the teleporter, but it doesn’t always wait for the relocation to finish, it unsits the avatar as soon as it receives the unsit order.  This is because functions in LSL do not operate sequentially.  The viewer will try to multi-task and execute as many functions as possible at one time.   So what happens is the avatar gets unseated and  dumped off someplace along the route before reaching the destination.  Then the avatar lands at the wrong location.  So how can this be fixed?  The not very elegant solution is to insert delays into the script to try to slow it down.  One way to do that is the llSleep function.  But how long a delay is required?  Unfortunately that depends a lot on the speed of the Internet connection and the user’s computer.  So someone with a slow computer and a slow Internet connection needs longer delays.
The teleporter script here is a modification based on the full permission one found at http://forums-archive.secondlife.com/54/a9/295421/1.html.


shameless plug:

Teleporter with Rotation.  You can buy a much better teleporter than this script – and it’s dirt cheap!  My Leaf Illusion Store at Second Life Marketplace sells a very inexpensive, Home Version of the Teleporter with Rotation.   The Teleporter with Rotation uses the new  llSetRegionPos function.  The Teleporter with Rotation has a number of extra features as well, such as the ability to set the direction the avatar is facing after teleporting (the rotation part.)   The teleporter also becomes transparent during the teleport process, which looks better when there is a lot of local lag in the sim (most of the time the teleport is so fast you don’t notice the actual motion.)   You can also change the appearance of the teleporter by modifying the prim shape or textures.   Complete illustrated step-by-step instructions for set up are included on my store’s website.  Here’s a link to the Teleporter with Rotation at Second Life marketplace


Teleporter with Rotation Version for OpenSim: Unfortunately the rotation feature doesn’t work in OpenSim due to a bug in OpenSim.  However the OpenSim version of the teleporter is available from Kitely Marketplace. at a discounted price due to the bug.  I left the rotation feature in the OpenSim script, so if they ever fix the bug, the rotation feature will start working. 

You can grab a copy of the compiled script from Second Life Marketplace.  Yeah, I charge L$1 for it  That’s just to discourage the freebie lovers who take up bandwidth by downloading anything that is free, even if they have no use for it!  I assume if you need a teleporter, one Linden Dollar (a little under half a penny!) is not a big issue for you.  Just look down next time you’re walking through a parking lot, chances are you can not just recover, but double your investment!

Here’s the code for the script.  I’ve been having trouble getting it to display properly on the website.  If you get error messages when compiling, try grabbing the compiled script from the link above.




// Simple-llsetregionpos-Teleporter.lsl
// Edit the next few lines to set up your teleporter.
// Brief instructions for each line are shown.
// This script uses the Linden Lab llSetRegionPos function introduced in January 2012.
// By Leaf Illusion, this script is Public Domain.  Use any way you wish.
// http://findingmywayinsl.com/llsetregionpos-teleporter-script-second-life/
// Last updated: 10-27-2012

vector gDestination = <000,000,000>; // Replace the 3 numbers with your destination coordinates.
string gText = " "; // Optional: Edit floating text above the teleporter. Insert a space for no text.
vector gTextColor = <1.0,1.0,1.0> ; // Optional: Change the color of the floating text if desired.
integer gAccessMode = 1; // Change who can use the teleporter: 1 - public, 2 - owner, 3 - group.
float gDelaySeconds = 0.0; // Inserts a delay if needed to slow down the script.

// About delay_seconds-
// If your avatar doesn't land accurately at the destination try setting the delay_seconds value to 0.2 or higher.
// If you experience problems with the avatar taking a side-trip to 0,0,0 set the delay_seconds value to 5.0 or higher.
// The 000 problem is due to a bug in the llSetRegionPos function.  The delay shouldn't be needed after the bug is fixed.

// You shouldn't need to change anything below this line

//=================================================
//=================================================

default
{
    state_entry()
    {
        llSitTarget(<0.0, 0.0, 0.51>, ZERO_ROTATION);
        llSetSitText("Teleport");
        llSetTouchText("Teleport");
        llSetText(gText,gTextColor,1.0);
        llSetClickAction(CLICK_ACTION_SIT);
    }
    changed(integer change) 
    {
        if (change & CHANGED_LINK)
        {
            key USER = llAvatarOnSitTarget();

            if (llGetAgentSize(USER) != ZERO_VECTOR)
            {
                if (gDestination == <0.0,0.0,0.0>)
                {
                    llUnSit(USER);
                    llOwnerSay(" ");
                    llOwnerSay("!!!!! WARNING !!!!!");
                    llOwnerSay("Teleporter destination is set to 0,0,0.  Aborting.");
                }
                integer access_granted = FALSE;
                if (gAccessMode == 1)
                    access_granted = TRUE;
                else if (gAccessMode == 2)
                {
                    if (USER == llGetOwner())
                        access_granted = TRUE;
                    else
                    {
                        llUnSit(USER);
                        llSay(0,"  sorry, teleporter for owner use only.");
                    }
                }
                else if (gAccessMode == 3)
                {
                    if (llSameGroup(USER))
                        access_granted = TRUE;
                    else
                    {
                        llUnSit(USER);
                        llSay(0,"  sorry, teleporter for group use only.");
                    }
                }

                if (access_granted)
                {
                    vector _InitPos = llGetPos();
                    llSetRegionPos(gDestination); // use llSetRegionPos function
                    llSleep(gDelaySeconds); // Delay for llSetRegionPos bug and lag work-around.
                    llUnSit(USER);
                    llSetRegionPos(_InitPos); // use llSetRegionPos function
                }
            }
        }
    }
}

No comments:

Post a Comment