Changes

Jump to navigation Jump to search
Created page with "Category: Useful Scripts Category: Opensim Script Library When a user clicks the prim they will get a menu offering to tp them or give information about the place. The..."
[[Category: Useful Scripts]]
[[Category: Opensim Script Library]]
When a user clicks the prim they will get a menu offering to tp them or give information about the place. The information option will deliver all prim contents other than the script and the location note card.
It will work inside the same sim, going to another sim or even another hypergrid destination

This script is written in OLSL and will not compile in second life but works in Opensim under both the X and Y Engine.

<br>

* Create a prim in world
* Add a new script to the prim
* Copy-paste the licence and script
* Make a new notecard called TpLocation and add it to the prims contents
* Adjust the notecard to your requirements

<br>

=== Script On Github ===
[https://github.com/Fire-And-Ice-Grid/LSL-And-OSSL-Script-Library LSL And OSSL Script Library On GitHub]

==== Licence ====
<syntaxhighlight lang="ini" line>
BSD 3-Clause License
Copyright (c) 2020, Sara Payne
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</syntaxhighlight>

==== Script ====
<syntaxhighlight lang="lsl" line>
vector landing;
vector lookAt;
string gridUri;
string regionName;
string destination;
string buttonName;

integer linkImage;
key imageUUID;

list tpNotecards = [];
list tpButtons = [];

integer debug = FALSE;

list GetTpButtons()
{
list links = [];
integer numberOfPrims = llGetNumberOfPrims();
integer linkNumber;
for (linkNumber = 2; linkNumber <= llGetNumberOfPrims(); linkNumber++)
{ //start at 2 so we don't bother scanning the root prim
string linkName = llGetLinkName(linkNumber);
if (linkName == "LocationImage") linkImage = linkNumber;
else
{
string locationName = locationTestString(linkName);
if (locationName != "")
{
links += locationName;
links += linkNumber;
}
}
}
return links;
}

list GetTpNotecards()
{
if (debug)
{
llOwnerSay("Debug:EnteredGetTpNotecards");
}
list locations;
integer numberofNotecards = llGetInventoryNumber(INVENTORY_NOTECARD);
integer notecardIndex;
for (notecardIndex = 0; notecardIndex < numberofNotecards; notecardIndex++)
{
string notecardName = llGetInventoryName(INVENTORY_NOTECARD, notecardIndex);
if (debug)
{
llOwnerSay("Debug:GetTpNotecards:NotecardName:" + notecardName);
}
string locationName = locationTestString(notecardName);
if (locationName != "")
{
locations += locationName;
if (debug)
{
llOwnerSay("Debug:GetTpNotecards:LocationName:" + notecardName);
}
}
}
if (debug)
{
llOwnerSay("Debug:GetTpNotecards:Locations: " + llList2CSV(locations));
}
return locations;
}

string locationTestString(string input)
{
string testValue = "TpLocation_";
string testString = llGetSubString(input, 0, llStringLength(testValue)-1);
string locationName = "";
if (testString == testValue)
{
list elements = llParseStringKeepNulls(input, "_", "!");
locationName = llList2String(elements, 1);
}
return locationName;
}

string CleanUpString(string inputString)
{
string cleanString = llStringTrim( llToLower(inputString), STRING_TRIM );
return cleanString;
}

ProcessInstructionLine(string instruction, string data)
{
if (instruction == "landing")
{
landing = (vector)data;
}
else if (instruction == "lookat")
{
lookAt = (vector)data;
}
else if (instruction == "griduri")
{
gridUri = data;
}
else if (instruction == "region")
{
regionName = data;
}
else if (instruction =="image")
{
imageUUID = data;
}
}

ReadConfigCards(string notecardName)
{ //Reads the named config card if it exists
if (llGetInventoryType(notecardName) == INVENTORY_NOTECARD)
{ //only come here if the name notecard actually exists, otherwise give the user an error
integer notecardLength = osGetNumberOfNotecardLines(notecardName); //gets the length of the notecard
integer index; //defines the index for the next line
for (index = 0; index < notecardLength; ++index)
{ //loops through the notecard line by line
string currentLine = osGetNotecardLine(notecardName,index); //contents of the current line exactly as it is in the notecard
string firstChar = llGetSubString(currentLine, 0,0); //gets the first character of this line
integer equalsIndex = llSubStringIndex(currentLine, "="); //gets the position of hte equals sign on this line if it exists
if (currentLine != "" && firstChar != "#" && equalsIndex != -1 )
{ //only come here if the line has content, it does not start with # and it contains an equal sign
string instruction = llGetSubString (currentLine, 0, equalsIndex-1); //everything before the equals sign
string data = llGetSubString(currentLine, equalsIndex+1, -1); //everything after the equals sign
instruction = CleanUpString (instruction); //sends the instruvtion to the cleanup method to remove white space and turn to lower case
data = CleanUpString (data); //sends the data to the cleanup method to remove white space and turn to lower case
ProcessInstructionLine(instruction, data); //sends the instruction and the data to the Process instruction method
}//close if the line is valid
else
{
if ( (currentLine != "") && (firstChar != "#") && (equalsIndex == -1))
{
llOwnerSay("Line number: " + (string)index + " is malformed. It is not blank, and does not begin with a #, yet it contains no equals sign.");

}
}
}
}//close if the notecard exists
else
{ //the named notecard does not exist, send an error to the user.
llOwnerSay ("The notecard called " + notecardName + " is missing, please address this");
}//close error the notecard does not exist
}//close read config card.

Teleport(key aviUUID)
{
if (gridUri == "")
{
destination = regionName;
}
else
{
destination = gridUri + "/" + regionName;
}

if (destination == "" || destination == "/")
{
if (debug)
{
llOwnerSay("Debug:Teleport: No Desination, same region tp");
}
osTeleportAgent(aviUUID, landing, lookAt);
}
else
{
if (debug)
{
llOwnerSay("Debug:Teleport: Desitination Set as: " + destination);
}
osTeleportAgent(aviUUID, destination, landing, lookAt);
}
llRegionSayTo(aviUUID, 0, "Teleporting you to : " + buttonName);
}

UpdateImage()
{
llSetLinkPrimitiveParamsFast(linkImage, [PRIM_TEXTURE, ALL_SIDES, imageUUID, <1.0, 1.0, 0.0>, ZERO_VECTOR, 0.0]);
}

ProcessTouch(integer touchedLink, key user)
{
string linkName = llGetLinkName(touchedLink);
if (debug) llOwnerSay("Debug:ProcessTouch:LinkName: " + linkName);
if (linkName == "LocationImage")
{
if (debug) llOwnerSay("Debug:ProcessTouch:TeleportUser: " + linkName);
Teleport(user);
}
else
{
string locationName = locationTestString(linkName);
if (locationName != "")
{
if (debug) llOwnerSay("Debug:ProcessTouch:ReadLocationCard:");
ReadConfigCards(linkName);
UpdateImage();
}
}
}

default
{
changed(integer change)
{
if (change & CHANGED_INVENTORY) //note that it's & and not &&... it's bitwise!
{
llResetScript();
}
}

state_entry()
{
tpNotecards = GetTpNotecards();
tpButtons = GetTpButtons();
//add checks here to make sure buttons and notecards match!
string defaultLocation = "TpLocation_" + llList2String(tpNotecards, 0);
ReadConfigCards(defaultLocation);
UpdateImage();
llMessageLinked(LINK_ALL_OTHERS, 987654, "update", llGetKey());
}

touch_start( integer num_detected )
{
key user = llDetectedKey(0);
integer touchedLink = llDetectedLinkNumber(0);
if (debug) llOwnerSay("Debug:TouchStart:TouchedBy: " + (string)user);
ProcessTouch(touchedLink, user);
}
}
</syntaxhighlight>

==== Notecard (notecard name must me TpLocation) ====
<syntaxhighlight lang="ini" line>
#Fire And Ice Teleport Board - Single Location
#==============================

#Will work on the same sim / to another sim on the same grid or a location on another grid.
#All locations needs a landing point and looking at

#Teleport In the same region:
#----------------------------------
# Leave the region name and the grid uri empty

#Teleport To Another Region On The Same Grid
#--------------------------------------------------------
#Fill in the region name but not the Grid Uri,

#Teleport To Another Region On A Different Grid
#--------------------------------------------------------
#Fill in the region name and the grid uri

#Options Description
#--------------------------
#Blank Lines and lines starting with # are ignored
#Landing: point is a vector <x,y,z> which represents the landing point on the destination region.
#LookAt: is the direction the avatar will face when they land (assuming its ever fixed)
#GridUri: is the URI for the destination grid. Example: http://fireandicegrid.net:8002
#Region: is the name of the destination region. Example: Covey Stores
#Image: this is the UUID/Key of the image you wish to display.
#Name: a descriptive name used to tell people where they are being teleported to, the board will also rename its self using this.

Landing = <132.76846, 128.44232, 23.36178>
LookAt = <648.81219, 84.31132, 44.19897>
GridUri =
Region = Norse Adventure
Image = ede3919d-433e-4cc6-841b-04e5f75bd179
Name =
</syntaxhighlight>

==Syntax Highlighting==

[https://www.mediawiki.org/wiki/Extension:SyntaxHighlight GeShi] syntax highlighting is enabled on this wiki. <be>

When using the tabs described in the link, change the language part to "lsl". Eg.<br>
syntaxhighlight lang="lsl" line<br>
inside angled brackets <>

Navigation menu