//-- Open map for owner to 1st landmark in object inventory on touch
//-- *MUST* be in an attached object (llMapDestination Requirement for non-touch use)
key vgKeyOwner;
default
{
touch_start( integer vIntNull )
{
if (llDetectedKey( 0 ) == vgKeyOwner)
{
integer vIntLMcount = llGetInventoryNumber( INVENTORY_LANDMARK );
//-- make sure we have a landmark in invetory
if (vIntLMcount)
{
llRequestInventoryData( llGetInventoryName( INVENTORY_LANDMARK, 0 ) );
}
}
}
dataserver( key vKeyNull, string vStrData )
{
//-- because we don't know who touched us in this event, this
//-- only works for the owner when called from the dataserver
llMapDestination( llGetRegionName(), (vector)vStrData, ZERO_VECTOR );
}
on_rez( integer vIntNull )
{
llResetScript();
}
state_entry()
{
vgKeyOwner = llGetOwner();
}
}
//An easily-configurable teleporter that sets its destination by getting it from a landmark in the prim's inventory
//Note: this teleporter is subject to the 300m distance limit for llSitTarget
//by Ilse Mannonen
//on state entry, request inventory data and set text for first landmark found in inventory.
//If none, complain
//on getting data, set sit target
//on change in inventory, reset script
//on sit, TP the person and unsit
//Thanks to Pol Tabla, who wrote the simple sit-teleport script I have adapted here
key requestid;
default
{
state_entry()
{
//complain if there are no landmarks
if (llGetInventoryNumber(INVENTORY_LANDMARK) == 0)
{
llSay(0, "There are no landmarks in me. You need to put a landmark in me for me to work.");
}
else
{
//set floating text according to the LM name
llSetText("Teleport to " + llGetInventoryName(INVENTORY_LANDMARK, 0), <1.0, 1.0, 1.0>, 1.0);
//request the LM data
requestid = llRequestInventoryData(llGetInventoryName(INVENTORY_LANDMARK, 0));
}
}
dataserver(key id, string data)
{
if (id == requestid)
{
//data will be in vector format
rotation rot = ZERO_ROTATION / llGetRot();
vector dest = (vector)data;
vector offset = (dest - llGetPos()) * rot;
llSitTarget(offset, rot);
}
}
changed(integer change)
{
if (change & CHANGED_LINK)
{ // and it was a link change
llSleep(0.5); // llUnSit works better with this delay
key user = llAvatarOnSitTarget();
if (user) { // somebody is sitting on me
llUnSit(user); // unsit him
}
}
//when doing "ifs" on bitwise things, it's best to do them separate instead of using else..if,
//in case you hit the one in a billion chance when the inventory and link changes are reported in the same event.
if (change & CHANGED_INVENTORY)
{
//reset on inventory change, so people don't have to manually reset when they add a new LM
llResetScript();
}
}
on_rez(integer param)
{
llResetScript();
}
}
// Click to print slurl for every landmark in inventory.
// Uses llRequestInventoryData() to get coordinates
// Uses http://wiki.secondlife.com/wiki/Linden_Lab_Official:Map_API_Reference#Region_name_from_global_coordinates to get region name
integer landmarkIndex;
vector landmarkCoords;
string landmarkRegion;
string landmarkSlurl;
key inventoryRequestId;
key mapRequestId;
requestLandmarkInfo(integer inventoryIndex) {
if (inventoryIndex >= llGetInventoryNumber(INVENTORY_LANDMARK)) return;
landmarkIndex = inventoryIndex;
string landmarkName = llGetInventoryName(INVENTORY_LANDMARK, landmarkIndex);
inventoryRequestId = llRequestInventoryData(landmarkName);
}
default {
touch_start(integer count) {
requestLandmarkInfo(0);
}
dataserver(key requestId, string data) {
if (requestId != inventoryRequestId) return;
if ((vector)data == ZERO_VECTOR) return;
// landmark request
landmarkCoords = llGetRegionCorner() + (vector)data;
// http://wiki.secondlife.com/wiki/Linden_Lab_Official:Map_API_Reference#Region_name_from_global_coordinates
mapRequestId = llHTTPRequest(
"https://cap.secondlife.com/cap/0/b713fe80-283b-4585-af4d-a3b7d9a32492?var=region"
+ "&grid_x=" + (string)((integer)landmarkCoords.x / 256)
+ "&grid_y=" + (string)((integer)landmarkCoords.y / 256), [], "");
}
http_response(key requestId, integer status, list metadata, string body) {
if (requestId != mapRequestId) return;
landmarkRegion = llList2String(llParseString2List(body, ["var region='", "';"], []), 0);
landmarkSlurl = "http://maps.secondlife.com/secondlife/" + llEscapeURL(landmarkRegion) +
"/" + (string)((integer)landmarkCoords.x % 256) +
"/" + (string)((integer)landmarkCoords.y % 256) +
"/" + (string)((integer)landmarkCoords.z);
llOwnerSay(llGetInventoryName(INVENTORY_LANDMARK, landmarkIndex) + ": "
+ landmarkSlurl + " <nolink>" + landmarkSlurl + "</nolink>");
requestLandmarkInfo(landmarkIndex + 1);
}
}