OSSL Script Library/Teleport Map
From OpenSimulator
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.
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.
refresh(){ // A user-defined function to keep the code short.
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
PRIM_COLOR,4,<1,1,1>,1, // Set the color of side 4 to white.
PRIM_FULLBRIGHT,4,1]); // Set side 4 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) != 4) return; // If the prim is not touched on side 4, 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 la)
{
llResetScript(); // Reset the script when rezzed to ensure a fresh map on the prim.
}
}