[Home] [Back To Scripts]

Teleport Script Tutorial


This code is inspired by an old TP script in SL by Cubey Terra.  The most important part is a section of code is what I like to call a touch ratchet.  It allows you to advance through stages of script using touch.  Here's the touch ratchet in a script by itself:

integer totalNum = 3;
integer currentNum = 1;
string currentdigit;
string digit1 = "one";
string digit2 = "two";
string digit3 = "three";
 
setNumber()
{
    if (currentNum == 1)
    {
        currentdigit = digit1;
    }
    else if (currentNum == 2)
    {
        currentdigit = digit2;
    }
    else if (currentNum == 3)
    {
        currentdigit = digit3;
    }
    llSay(0, currentdigit);
}
 
default
{
    state_entry()
    {
        llSetText("Touch Ratchet",<1,1,1>,1.0);
    }
    touch_start(integer total_number)
    {
        currentNum += 1;
        if (currentNum > totalNum) currentNum = 1;
        setNumber();
    }
}

 



This code can be used in many scripts that require selecting one of several different variables from within a script, for example, strings, integers, vectors, etc...
I used this touch ratchet in another script as a radio that changes stations on touch.  I used it in the following script to select teleport destinations:

//Teleport v2.01 by Pablo Pharmanaut
//based on old SL TP script by Cubey Terra
 
integer totalPos = 5;                    //This integer should equal total number of positions
integer currentPos = 1;
string currentpos;
 
vector vPos1 = <190.824,168.0,41>;       //These are vectors for the positions to
vector vPos2 = <221.0,99.5,24>;          //which you wish to teleport
vector vPos3 = <128.0,128.0,40>;                  //Add or take away to have the desired number of
vector vPos4 = <45,85,81>;                              //positions.
vector vPos5 = <45,85,91>;
 
string sPos1 = "house";                  //name of positions, if desired.  This helps
string sPos2 = "waterfront";             //you to know where you are going!
string sPos3 = "entry point";                        //Again, add or take away to have the desired number
string sPos4 = "Scriptwerks Level 2";        //of positions.
string sPos5 = "Scriptwerks Level 3";
 
vector currentvPos;
 
setPos()
{
    if (currentPos == 1)
    {
        currentpos = sPos1;
        currentvPos = vPos1;
    }
    else if (currentPos == 2)             //
    {                                     //  add or delete this section of script to change
        currentpos = sPos2;               //  number of TP destinations.  Change currentPos
        currentvPos = vPos2;              //  integer to number of destinations.
    }                                     //
    else if (currentPos == 3)
    {
        currentpos = sPos3;
        currentvPos = vPos3;
    }
    else if (currentPos == 4)
    {
        currentpos = sPos4;
        currentvPos = vPos4;
    }
    else if (currentPos == 5)
    {
        currentpos = sPos5;
        currentvPos = vPos5;
    }
//add else if section here with higher currentPos integer to add TP destinations.
//Don't forget to increase totalPos integer at top of script
 
    vector pos = llGetPos();
    llSetText("Teleport to "+currentpos+"\nTouch me to change destination",<1,1,1>,1.0);
    vector offset = currentvPos - pos;
    llSitTarget(offset, ZERO_ROTATION);
 
 
}
 
default
{
    state_entry()
    {
        llSetSitText("Teleport");            //This changes HUD display from "Sit" to "Teleport"   
    }
    touch_start(integer total_number)
    {
        currentPos += 1;
        if (currentPos > totalPos) currentPos = 1;
        setPos();
    }
}
 


One thing this script doesn't have is llUnSit, due to lack of OS implementation of that function.  Hopefully that function will be implemented soon.  In the meantime, this causes strange behavior.  When you TP, you will go to a different position, until you stand up.  At that point, you will appear at the coordinates you set in the vPos portion of the script.  Still, this script is far superior to the llListen version I had used in previous TP scripts.  I have discovered that OLG does not like the llListen function.  Unless used sparingly, the llListen function will clog up your memory and eventually crash your region.  You have been warned.

The following section of code can be deleted or added depending on number of postions you wish to include in your script. 


else
if (currentPos == 5)
    {
        currentpos = sPos5;
        currentvPos = vPos5;
    }

Just remember to change the line

integer totalPos = ?;

to reflect the total number of positions you use.  I hope this little tutorial helps with setting up your own TP in your region.  No matter how beautiful a build in a region, it's still pretty sterile to me, without some fun scripts that create a more dynamic build.