Teleport Board - Single Destination

From Fire And Ice Grid
Revision as of 14:26, 10 August 2021 by Admindiamond (talk | contribs)
(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 integer debug = FALSE;
  7 integer mainMenuChannel;
  8 integer mainMenuChannelListen;
  9 key imageUUID;
 10 string name;
 11 
 12 SetUpListeners()
 13 {//sets the coms channel and the random menu channel then turns the listeners on.
 14     mainMenuChannel = (integer)(llFrand(-1000000000.0) - 1000000000.0); //generates random main menu channel
 15     mainMenuChannelListen = llListen(mainMenuChannel, "", NULL_KEY, "");//sets up main menu listen integer
 16     llListenControl (mainMenuChannelListen, FALSE); //turns off listeners for main menu channel
 17 }//close set up listeners
 18 
 19 string locationTestString(string input)
 20 {
 21     string testValue = "TpLocation_";
 22     string testString = llGetSubString(input, 0, llStringLength(testValue)-1);
 23     string locationName = "";
 24     if (testString == testValue)
 25     {
 26         list elements = llParseStringKeepNulls(input, "_", "!");
 27         locationName = llList2String(elements, 1);
 28     }
 29     return locationName;
 30 }
 31 
 32 string CleanUpString(string inputString)
 33 { 
 34     string cleanString = llStringTrim( llToLower(inputString), STRING_TRIM );
 35     return cleanString;   
 36 }
 37 
 38 ProcessInstructionLine(string instruction, string data)
 39 {
 40     if (debug)
 41     {
 42         llOwnerSay("Debug:ProcessInstruction: Instruction:" + instruction + " Data:" + data);
 43     }
 44     if (instruction == "landing")
 45     {
 46         landing = (vector)data;
 47     }
 48     else if (instruction == "lookat")
 49     {
 50         lookAt = (vector)data;
 51     }
 52     else if (instruction == "griduri")
 53     {
 54         gridUri = data;
 55     }
 56     else if (instruction == "region")
 57     {
 58         regionName = data;
 59     }
 60     else if (instruction =="image")
 61     {
 62         imageUUID = data;
 63     }
 64     else if (instruction == "name")
 65     {
 66         name = data;
 67     }
 68 }
 69 
 70 ReadConfigCards(string notecardName)
 71 {   //Reads the named config card if it exists
 72     if (llGetInventoryType(notecardName) == INVENTORY_NOTECARD)
 73     {   //only come here if the name notecard actually exists, otherwise give the user an error
 74         integer notecardLength = osGetNumberOfNotecardLines(notecardName); //gets the length of the notecard
 75         integer index; //defines the index for the next line
 76         for (index = 0; index < notecardLength; ++index)
 77         {    //loops through the notecard line by line  
 78             string currentLine = osGetNotecardLine(notecardName,index); //contents of the current line exactly as it is in the notecard
 79             string firstChar = llGetSubString(currentLine, 0,0); //gets the first character of this line
 80             integer equalsIndex = llSubStringIndex(currentLine, "="); //gets the position of hte equals sign on this line if it exists
 81             if (currentLine != "" && firstChar != "#" && equalsIndex != -1 )
 82             {   //only come here if the line has content, it does not start with # and it contains an equal sign
 83                 string instruction = llGetSubString (currentLine, 0, equalsIndex-1); //everything before the equals sign
 84                 string data = llGetSubString(currentLine, equalsIndex+1, -1); //everything after the equals sign    
 85                 instruction = CleanUpString (instruction); //sends the instruvtion to the cleanup method to remove white space and turn to lower case
 86                 data = CleanUpString (data); //sends the data to the cleanup method to remove white space and turn to lower case
 87                 ProcessInstructionLine(instruction, data); //sends the instruction and the data to the Process instruction method
 88             }//close if the line is valid
 89             else
 90             {
 91                 if ( (currentLine != "") && (firstChar != "#") && (equalsIndex == -1))
 92                 {
 93                     llOwnerSay("Line number: " + (string)index + " is malformed. It is not blank, and does not begin with a #, yet it contains no equals sign.");
 94 
 95                 }
 96             }
 97         }
 98     }//close if the notecard exists
 99     else 
100     {   //the named notecard does not exist, send an error to the user. 
101         llOwnerSay ("The notecard called " + notecardName + " is missing, please address this");
102     }//close error the notecard does not exist
103 }//close read config card. 
104 
105 Teleport(key aviUUID)
106 {
107     if (gridUri == "")
108     {
109         destination = regionName;
110     }
111     else
112     {
113         destination = gridUri + "/" + regionName;
114     }
115         
116     if (destination == "" || destination == "/")
117     {
118          if (debug)
119          {
120              llOwnerSay("Debug:Teleport: No Desination, same region tp");
121          }
122         osTeleportAgent(aviUUID, landing, lookAt);
123     }
124     else
125     {
126         if (debug)
127         {
128             llOwnerSay("Debug:Teleport: Desitination Set as: " + destination);
129         }
130         osTeleportAgent(aviUUID, destination, landing, lookAt);
131     }    
132     llRegionSayTo(aviUUID, 0,  "Teleporting you to" + name);
133 }
134 
135 string SetLocationName()
136 {
137     if (debug) llOwnerSay("Debug:SetLocationName:Entered");
138     string locationName = "";
139     if (name == "")
140     {
141         if (debug) llOwnerSay("Debug:SetLocationName:Empty Name string found");
142         if (regionName == "")
143         {
144             if (debug) llOwnerSay("Debug:SetLocationName:Empty Region Name found, location name set to the region name");
145             locationName += llGetRegionName();
146         }
147         else
148         {
149             if (debug) llOwnerSay("Debug:SetLocationName:location name set to the region name");
150             locationName += regionName;
151         }
152         if (gridUri == "")
153         {
154             locationName += "@" + osGetGridName();
155         }
156         else
157         {
158             locationName += gridUri;
159         }
160     }
161     else
162     {
163         locationName = name;
164     }
165     if (debug) llOwnerSay("Debug:SetLocationName:LocationName: " + locationName);
166     return locationName;
167 }
168 
169 DeliverInfo(key aviUUID)
170 {
171    list inventoryItems =[];
172    integer inventoryNumber = llGetInventoryNumber(INVENTORY_ALL); 
173    integer index;
174    for (index = 0; index < inventoryNumber; ++index )
175    {
176         string itemName = llGetInventoryName(INVENTORY_ALL, index);
177         if (debug)
178         {
179             llOwnerSay("Debug:DeliverInfo:ItemName: " + itemName);
180         }
181         
182         if (!(itemName == llGetScriptName() || itemName == "TpLocation"))
183         {
184             if (debug)
185             {
186                 llOwnerSay("Debug:DevliverInfo:" + itemName + "added to deliverables");
187             }
188             if (llGetInventoryPermMask(itemName, MASK_OWNER) & PERM_COPY)
189             {
190                 inventoryItems += itemName;
191             }
192             else
193             {
194                 llSay(0, "Unable to copy the item named '" + itemName + "'.");
195             }
196         }
197     }
198     if (inventoryItems == [] )
199     {
200         llRegionSayTo(aviUUID, PUBLIC_CHANNEL, "No copiable items found, sorry.");
201     }
202     else llGiveInventoryList(aviUUID, llGetObjectName(), inventoryItems);    // 3.0 seconds delay
203     llResetScript();
204 }
205 
206 UpdateImage()
207 {
208     llSetLinkPrimitiveParamsFast(ALL_SIDES, [PRIM_TEXTURE, ALL_SIDES, imageUUID, <1.0, 1.0, 0.0>, ZERO_VECTOR, 0.0]);
209 }
210 
211 ProcessMenuChoices(key aviUUID, string message)
212 {
213     if (message == "Teleport")
214     {
215         Teleport(aviUUID);
216     }
217     else if (message == "GetInfo")
218     {
219         DeliverInfo(aviUUID);
220     }
221 }
222 
223 default
224 {
225   on_rez(integer start_param)
226   {
227     llResetScript();
228   }
229 
230   changed(integer change) // something changed, take action
231   {
232       if(change & (CHANGED_OWNER | CHANGED_REGION_RESTART | CHANGED_INVENTORY)) 
233       {
234           llResetScript();
235       }
236   } 
237   
238   state_entry()
239   {
240     SetUpListeners();
241     ReadConfigCards("TpLocation");
242     UpdateImage();
243     llSetObjectName(SetLocationName() + " Teleport Board");
244   }
245   
246   touch_start(integer num_detected) 
247   {
248     llListenControl (mainMenuChannelListen, TRUE);
249     list buttons = ["Teleport", "GetInfo"];
250     llDialog(llDetectedKey(0), "Please select from the following options", buttons, mainMenuChannel); 
251     llSetTimerEvent(30);    
252   }
253   
254   listen(integer channel, string name, key uuid, string message)
255   {//listens on the set channels, then depending on the heard channel sends the message for processing. 
256       if (channel == mainMenuChannel)
257       {
258           ProcessMenuChoices(uuid, message);  
259       }
260   }//close listen 
261     
262   timer()
263   {
264       llWhisper(PUBLIC_CHANNEL, "sorry the menu timed out, please click again");
265       llResetScript();
266   }
267 }

Notecard (notecard name must me TpLocation)

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