Teleport Board - Multi Location

From Fire And Ice Grid
Revision as of 20:13, 28 February 2022 by Admindiamond (talk | contribs) (→‎Notecard (notecard name must me TpLocation))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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.


  • 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


Script On Github

LSL And OSSL Script Library On GitHub

Licence

 1 BSD 3-Clause License
 2 Copyright (c) 2020, Sara Payne
 3 All rights reserved.
 4 Redistribution and use in source and binary forms, with or without
 5 modification, are permitted provided that the following conditions are met:
 6 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
 7 2. Redistributions in binary form must reproduce the above copyright notice,
 8    this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
 9 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.
10 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
11 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
12 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
13 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
14 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
15 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
16 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
17 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
18 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
19 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Script

  1 vector landing;
  2 vector lookAt;
  3 string gridUri;
  4 string regionName;
  5 string destination;
  6 string buttonName;
  7 
  8 integer linkImage;
  9 key imageUUID;
 10 
 11 list tpNotecards = [];
 12 list tpButtons = [];
 13 
 14 integer debug = FALSE;
 15 
 16 list GetTpButtons()
 17 {
 18     list links = [];
 19     integer numberOfPrims = llGetNumberOfPrims();
 20     integer linkNumber;
 21     for (linkNumber = 2; linkNumber <= llGetNumberOfPrims(); linkNumber++)
 22     {   //start at 2 so we don't bother scanning the root prim
 23         string linkName = llGetLinkName(linkNumber);
 24         if (linkName == "LocationImage") linkImage = linkNumber;
 25         else
 26         {
 27             string locationName = locationTestString(linkName);
 28             if (locationName != "")
 29             {
 30                 links += locationName;
 31                 links += linkNumber;
 32             }   
 33         }
 34     }
 35     return links;
 36 }
 37 
 38 list GetTpNotecards()
 39 {
 40     if (debug)
 41     {
 42         llOwnerSay("Debug:EnteredGetTpNotecards");
 43     }
 44     list locations;
 45     integer numberofNotecards = llGetInventoryNumber(INVENTORY_NOTECARD);
 46     integer notecardIndex;
 47     for (notecardIndex = 0; notecardIndex < numberofNotecards; notecardIndex++)
 48     {
 49         string notecardName = llGetInventoryName(INVENTORY_NOTECARD, notecardIndex);
 50         if (debug)
 51         {
 52             llOwnerSay("Debug:GetTpNotecards:NotecardName:" + notecardName);
 53         }
 54         string locationName = locationTestString(notecardName);
 55         if (locationName != "")
 56         {
 57             locations += locationName;
 58             if (debug)
 59             {
 60                 llOwnerSay("Debug:GetTpNotecards:LocationName:" + notecardName);
 61             }
 62         }   
 63     }
 64     if (debug)
 65     {
 66         llOwnerSay("Debug:GetTpNotecards:Locations: " + llList2CSV(locations));
 67     }
 68     return locations;
 69 }
 70 
 71 string locationTestString(string input)
 72 {
 73     string testValue = "TpLocation_";
 74     string testString = llGetSubString(input, 0, llStringLength(testValue)-1);
 75     string locationName = "";
 76     if (testString == testValue)
 77     {
 78         list elements = llParseStringKeepNulls(input, "_", "!");
 79         locationName = llList2String(elements, 1);
 80     }
 81     return locationName;
 82 }
 83 
 84 string CleanUpString(string inputString)
 85 { 
 86     string cleanString = llStringTrim( llToLower(inputString), STRING_TRIM );
 87     return cleanString;   
 88 }
 89 
 90 ProcessInstructionLine(string instruction, string data)
 91 {
 92     if (instruction == "landing")
 93     {
 94         landing = (vector)data;
 95     }
 96     else if (instruction == "lookat")
 97     {
 98         lookAt = (vector)data;
 99     }
100     else if (instruction == "griduri")
101     {
102         gridUri = data;
103     }
104     else if (instruction == "region")
105     {
106         regionName = data;
107     }
108     else if (instruction =="image")
109     {
110         imageUUID = data;
111     }
112 }
113 
114 ReadConfigCards(string notecardName)
115 {   //Reads the named config card if it exists
116     if (llGetInventoryType(notecardName) == INVENTORY_NOTECARD)
117     {   //only come here if the name notecard actually exists, otherwise give the user an error
118         integer notecardLength = osGetNumberOfNotecardLines(notecardName); //gets the length of the notecard
119         integer index; //defines the index for the next line
120         for (index = 0; index < notecardLength; ++index)
121         {    //loops through the notecard line by line  
122             string currentLine = osGetNotecardLine(notecardName,index); //contents of the current line exactly as it is in the notecard
123             string firstChar = llGetSubString(currentLine, 0,0); //gets the first character of this line
124             integer equalsIndex = llSubStringIndex(currentLine, "="); //gets the position of hte equals sign on this line if it exists
125             if (currentLine != "" && firstChar != "#" && equalsIndex != -1 )
126             {   //only come here if the line has content, it does not start with # and it contains an equal sign
127                 string instruction = llGetSubString (currentLine, 0, equalsIndex-1); //everything before the equals sign
128                 string data = llGetSubString(currentLine, equalsIndex+1, -1); //everything after the equals sign    
129                 instruction = CleanUpString (instruction); //sends the instruvtion to the cleanup method to remove white space and turn to lower case
130                 data = CleanUpString (data); //sends the data to the cleanup method to remove white space and turn to lower case
131                 ProcessInstructionLine(instruction, data); //sends the instruction and the data to the Process instruction method
132             }//close if the line is valid
133             else
134             {
135                 if ( (currentLine != "") && (firstChar != "#") && (equalsIndex == -1))
136                 {
137                     llOwnerSay("Line number: " + (string)index + " is malformed. It is not blank, and does not begin with a #, yet it contains no equals sign.");
138 
139                 }
140             }
141         }
142     }//close if the notecard exists
143     else 
144     {   //the named notecard does not exist, send an error to the user. 
145         llOwnerSay ("The notecard called " + notecardName + " is missing, please address this");
146     }//close error the notecard does not exist
147 }//close read config card. 
148 
149 Teleport(key aviUUID)
150 {
151     if (gridUri == "")
152     {
153         destination = regionName;
154     }
155     else
156     {
157         destination = gridUri + "/" + regionName;
158     }
159         
160     if (destination == "" || destination == "/")
161     {
162          if (debug)
163          {
164              llOwnerSay("Debug:Teleport: No Desination, same region tp");
165          }
166         osTeleportAgent(aviUUID, landing, lookAt);
167     }
168     else
169     {
170         if (debug)
171         {
172             llOwnerSay("Debug:Teleport: Desitination Set as: " + destination);
173         }
174         osTeleportAgent(aviUUID, destination, landing, lookAt);
175     }
176     llRegionSayTo(aviUUID, 0, "Teleporting you to : " + buttonName);
177 }
178 
179 UpdateImage()
180 {
181     llSetLinkPrimitiveParamsFast(linkImage, [PRIM_TEXTURE, ALL_SIDES, imageUUID, <1.0, 1.0, 0.0>, ZERO_VECTOR, 0.0]);
182 }
183 
184 ProcessTouch(integer touchedLink, key user)
185 {
186     string linkName = llGetLinkName(touchedLink);
187     if (debug) llOwnerSay("Debug:ProcessTouch:LinkName: " + linkName);
188     if (linkName == "LocationImage")
189     {
190         if (debug) llOwnerSay("Debug:ProcessTouch:TeleportUser: " + linkName);
191         Teleport(user);
192     }
193     else
194     {
195         string locationName = locationTestString(linkName);
196         if (locationName != "")
197         {
198             if (debug) llOwnerSay("Debug:ProcessTouch:ReadLocationCard:");
199             ReadConfigCards(linkName);
200             UpdateImage();
201         }
202     }
203 }
204 
205 default
206 {
207     changed(integer change)
208     {
209         if (change & CHANGED_INVENTORY) //note that it's & and not &&... it's bitwise!
210         {
211             llResetScript();
212         }
213     }
214     
215     state_entry()
216     {
217         tpNotecards = GetTpNotecards();
218         tpButtons = GetTpButtons();
219         //add checks here to make sure buttons and notecards match!
220         string defaultLocation = "TpLocation_" + llList2String(tpNotecards, 0);
221         ReadConfigCards(defaultLocation);
222         UpdateImage();
223         llMessageLinked(LINK_ALL_OTHERS, 987654, "update", llGetKey());
224     }
225 
226     touch_start( integer num_detected )
227     {
228         key user = llDetectedKey(0);
229         integer touchedLink = llDetectedLinkNumber(0);
230         if (debug) llOwnerSay("Debug:TouchStart:TouchedBy: " + (string)user);
231         ProcessTouch(touchedLink, user);
232     }
233 }

Notecard (notecard name must me TpLocation)

 1 #Fire And Ice Teleport Board - Multi Location
 2 #==============================
 3 
 4 add an under score to each notecard name after TpLocation then the name of the notecard it matches
 5 Add a button for each one with the same name. 
 6 
 7 #Will work on the same sim / to another sim on the same grid or a location on another grid. 
 8 #All locations needs a landing point and looking at
 9 
10 #Teleport In the same region:
11 #----------------------------------
12 # Leave the region name and the grid uri empty
13 
14 #Teleport To Another Region On The Same Grid
15 #--------------------------------------------------------
16 #Fill in the region name but not the Grid Uri, 
17 
18 #Teleport To Another Region On A Different Grid
19 #--------------------------------------------------------
20 #Fill in the region name and the grid uri
21 
22 #Options Description
23 #--------------------------
24 #Blank Lines and lines starting with # are ignored
25 #Landing: point is a vector <x,y,z> which represents the landing point on the destination region. 
26 #LookAt: is the direction the avatar will face when they land (assuming its ever fixed)
27 #GridUri: is the URI for the destination grid. Example: http://fireandicegrid.net:8002
28 #Region: is the name of the destination region. Example: Covey Stores
29 #Image: this is the UUID/Key of the image you wish to display. 
30 #Name: a descriptive name used to tell people where they are being teleported to, the board will also rename its self using this. 
31 
32 Landing =  <132.76846, 128.44232, 23.36178>
33 LookAt =  <648.81219, 84.31132, 44.19897>
34 GridUri = 
35 Region = Norse Adventure
36 Image = ede3919d-433e-4cc6-841b-04e5f75bd179
37 Name =

Syntax Highlighting

GeShi syntax highlighting is enabled on this wiki. <be>

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