Script teleport
From The Schommunity Wiki
This script allows you to make an object a teleportation device.
1. Make an object - just a plain cube is fine 2. Put this script into it 3. Create a notecard in your inventory: simplest is one with vectors on the first line <x,y,z> and a name on the second line. 4. Drag this notecard onto the object 5. You can now teleport from the object to the vectors specified.
It got me out of a trap space fine! But the object stays where it is and doesn't come with you.
--Mgaved 13:07, 27 February 2007 (GMT)
/ Teleporter Script v 3.0 by Asira Sakai (with help from LSLWiki)
// requires a notecard in the object's inventory with target vectors and destination descriptions
// in alternating lines (or just a single line with a target vector)
// Will teleport any agent who "sits" on the object containing the script within the simulator
// Touching the object will select the next destination if there are more than one
string gName; // name of a notecard in the object's inventory
integer gLine = 0; // current line number
key gQueryID; // id used to identify dataserver queries
vector homeVector; // starting vector
vector targetVector; // vector to teleport to
vector color = <0,0,1>; // set float text color to blue
integer listIndex; // current index on the list
list destinations; // the list of all destinations, strided <vector> , string
string staticText = "Teleport Cube v 3.0"; // optional custom text
string destinationText; // the text describing the destination
warpPos( vector destpos ) // copied straight from LSLWiki
{ //R&D by Keknehv Psaltery, 05/25/2006
//with a little pokeing by Strife, and a bit more
//some more munging by Talarus Luan
//Final cleanup by Keknehv Psaltery
// Compute the number of jumps necessary
integer jumps = (integer)(llVecDist(destpos, llGetPos()) / 10.0) + 1;
// Try and avoid stack/heap collisions
if (jumps > 100 )
jumps = 100; // 1km should be plenty
list rules = [ PRIM_POSITION, destpos ]; //The start for the rules list
integer count = 1;
while ( ( count = count << 1 ) < jumps)
rules = (rules=[]) + rules + rules; //should tighten memory use.
llSetPrimitiveParams( rules + llList2List( rules, (count - jumps) << 1, count) );
} // end of warpPos
init()
{
destinations = []; // clear out destinations
llSetText(staticText, color, 1.0); // set optional initial floating text
llSetSitText("Teleport"); // change "sit" option to "Teleport"
llSitTarget(<0.0, 0.0, 0.1>, ZERO_ROTATION); // needed for llAvatarOnSitTarget to work
gName = llGetInventoryName(INVENTORY_NOTECARD, 0); // select the first notecard in the object's inventory
if (gName != "") // if a notecard is found
gQueryID = llGetNotecardLine(gName, gLine); // request first notecard line
else
llSay(0,"No location set, insert notecard with target vector in <x,y,z> format");
if(llAvatarOnSitTarget() != NULL_KEY) // if someone is sitting
llUnSit(llAvatarOnSitTarget()); // unsit him
}
default
{
state_entry()
{
init();
}
touch_start(integer total_number)
{
if (gName != ""){
if (gLine <= 2) // if there is only one destination available
llSay(0, "Right click and select Teleport to activate");
else {
llSay(0, "Selecting next destination, right click and select Teleport to activate");
// get next entries from the list
if (listIndex >= gLine)
listIndex = 0;
targetVector = (vector)llList2String(destinations, listIndex);
destinationText = llList2String(destinations, listIndex + 1);
llSetText(destinationText, color, 1.0);
listIndex += 2;
}
}
else
llResetScript();
}
dataserver(key query_id, string data) {
if (query_id == gQueryID) {
if (data != EOF) { // if not at the end of the notecard
destinations = (destinations=[]) + destinations + data; // add the line data to the list
gLine++; // increase line count
gQueryID = llGetNotecardLine(gName, gLine); // request next line
}
else { // display the loaded list to the owner
llOwnerSay("Loaded Locations:");
listIndex = 0;
while (listIndex < gLine) {
llOwnerSay(llList2String(destinations, listIndex));
listIndex++;
}
// set up first destination
targetVector = (vector)llList2String(destinations, 0);
destinationText = llList2String(destinations, 1);
if (destinationText != "")
llSetText(destinationText, color, 1.0);
listIndex = 2;
}
}
}
changed(integer change) {
if (change & CHANGED_LINK){ // if a link change occurs (sit or unsit)
if(llAvatarOnSitTarget() != NULL_KEY){ // and there is someone sitting now
if (gName != ""){ // if there is a valid notecard loaded
homeVector = llGetPos(); // record current position for return
warpPos(targetVector); // teleport to selected coordinates
llUnSit(llAvatarOnSitTarget()); // unsit him
warpPos(homeVector); // teleport back to old position
}
else
llResetScript();
}
}
}
}
- I've made a hugely simpler teleport script that will teleport you to anywhere within a 512x512x512 cube centred on the teleport:
vector target = <165,110,25>;
default
{
state_entry()
{
llSetSitText("Teleport");
llSitTarget(target-llGetPos(), ZERO_ROTATION);
}
}
- Combine this with setting the on-left-click action on the box to sitting should mean that you can teleport around by clicking it. The only problem is that you have to edit the script and reset it to change the destination... Oh, and you end up sat in midair instead of stood up... --Decimus 12:32, 10 April 2007 (BST)