Advertisement
Guest User

Auto-configuring Teleporter

a guest
Oct 17th, 2019
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.83 KB | None | 0 0
  1. integer CHANNEL = -10001;
  2. float INTERVAL = 10.0;
  3. vector OFFSET = <0.0,0.0,1.2>;
  4.  
  5. integer number = 1;
  6. list descriptions = [];
  7. list positions = [];
  8. list timestamps = [];
  9.  
  10. // Function present menu items in more logical ordering.
  11. list orderButtons(list buttons)
  12. {
  13. return(llList2List(buttons, -3, -1) + llList2List(buttons, -6, -4)
  14. + llList2List(buttons, -9, -7) + llList2List(buttons, -12, -10));
  15. }
  16.  
  17. default
  18. {
  19.  
  20. state_entry()
  21. {
  22.  
  23. // Announce teleporter and setup timer to maintain teleporter list.
  24. key owner = llGetOwner();
  25. string description = llGetObjectDesc();
  26. if (description == "<Location name>") {
  27. description = (string)number;
  28. }
  29. vector position = llGetPos();
  30. llRegionSay(CHANNEL, "teleporter\t" + (string)owner + "\t" + description + "\t" + (string)position);
  31. llSetTimerEvent(INTERVAL);
  32.  
  33. // Setup listener to receive teleporter announcements and user dialog.
  34. llListen(CHANNEL, "", "", "");
  35.  
  36. // Configure sit text and target.
  37. llSetSitText("Teleport");
  38. llSitTarget(OFFSET, ZERO_ROTATION);
  39.  
  40. }
  41.  
  42. changed(integer change)
  43. {
  44.  
  45. // Check if someone sits on the teleporter.
  46. if (change & CHANGED_LINK) {
  47. key id = llAvatarOnSitTarget();
  48. if (id) {
  49. if (llGetInventoryNumber(INVENTORY_ANIMATION) >= 1) {
  50. llRequestPermissions(id, PERMISSION_TRIGGER_ANIMATION);
  51. }
  52. if (llGetInventoryNumber(INVENTORY_SOUND) >= 1) {
  53. llPlaySound(llGetInventoryName(INVENTORY_SOUND, 0), 1.0);
  54. }
  55. integer count = llGetListLength(descriptions);
  56. if (count >= 2) {
  57. list buttons = orderButtons(llListSort(descriptions, 1, TRUE));
  58. llDialog(id, "Select destination:", buttons, CHANNEL);
  59. }
  60. else if (count == 1) {
  61. vector position = llGetPos();
  62. llSleep(0.5);
  63. if (llSubStringIndex(llList2String(descriptions, 0), "*") == 0 && !llSameGroup(id)) {
  64. llRegionSayTo(id, 0, "Only group members are allowed to teleport to locations marked with '*'");
  65. llUnSit(id);
  66. }
  67. else if (llSubStringIndex(llList2String(descriptions, 0), "!") == 0 && id != llGetOwner()) {
  68. llRegionSayTo(id, 0, "Only the owner are allowed to teleport to locations marked with '!'");
  69. llUnSit(id);
  70. }
  71. else {
  72. llSetRegionPos(llList2Vector(positions, 0));
  73. llUnSit(id);
  74. llSetRegionPos(position);
  75. }
  76. }
  77. else {
  78. llSleep(0.5);
  79. llUnSit(id);
  80. }
  81. }
  82. }
  83.  
  84. // Reset the script if the teleporter has changed owner or been moved across a sim border.
  85. if (change & (CHANGED_OWNER|CHANGED_REGION)) {
  86. llResetScript();
  87. }
  88.  
  89. }
  90.  
  91. listen(integer channel, string name, key id, string message)
  92. {
  93.  
  94. if (id == llAvatarOnSitTarget()) {
  95.  
  96. // Teleport avatar to destination.
  97. integer index = llListFindList(descriptions, [message]);
  98. vector position = llGetPos();
  99. if (llSubStringIndex(llList2String(descriptions, index), "*") == 0 && !llSameGroup(id)) {
  100. llRegionSayTo(id, 0, "Only group members are allowed to teleport to locations marked with '*'");
  101. llUnSit(id);
  102. }
  103. else if (llSubStringIndex(llList2String(descriptions, index), "!") == 0 && id != llGetOwner()) {
  104. llRegionSayTo(id, 0, "Only the owner is allowed to teleport to locations marked with '!'");
  105. llUnSit(id);
  106. }
  107. else {
  108. llSetRegionPos(llList2Vector(positions, index));
  109. llUnSit(id);
  110. llSetRegionPos(position);
  111. }
  112.  
  113. }
  114. else {
  115.  
  116. // Parse the received message.
  117. list tokens = llParseString2List(message, ["\t"], []);
  118. string check = llList2String(tokens, 0);
  119. key owner = (key)llList2String(tokens, 1);
  120. string description = llList2String(tokens, 2);
  121. vector position = (vector)llList2String(tokens, 3);
  122. integer timestamp = llGetUnixTime();
  123.  
  124. // Remove old data from the lists and add current data.
  125. if (check == "teleporter" && owner == llGetOwner()) {
  126. integer index = llListFindList(descriptions, [description]);
  127. if (~index) {
  128. descriptions = llDeleteSubList(descriptions, index, index);
  129. positions = llDeleteSubList(positions, index, index);
  130. timestamps = llDeleteSubList(timestamps, index, index);
  131. }
  132. descriptions += description;
  133. positions += position;
  134. timestamps += timestamp;
  135. }
  136.  
  137. // Renumber this teleporter if another has same number.
  138. if ((string)number == description) {
  139. number++;
  140. if (number > 12) {
  141. number = 1;
  142. }
  143. }
  144.  
  145. }
  146.  
  147. }
  148.  
  149. on_rez(integer n)
  150. {
  151.  
  152. // Reset the script when the teleporter is rezzed.
  153. llResetScript();
  154.  
  155. }
  156.  
  157. run_time_permissions(integer perm)
  158. {
  159.  
  160. // Play animation when permission has been granted.
  161. if (perm & PERMISSION_TRIGGER_ANIMATION) {
  162. llStartAnimation(llGetInventoryName(INVENTORY_ANIMATION,0));
  163. }
  164.  
  165. }
  166.  
  167. timer()
  168. {
  169.  
  170. // Announce the teleporter.
  171. key owner = llGetOwner();
  172. string description = llGetObjectDesc();
  173. if (description == "<Location name>") {
  174. description = (string)number;
  175. }
  176. vector position = llGetPos();
  177. integer timestamp = llGetUnixTime();
  178. llRegionSay(CHANNEL, "teleporter\t" + (string)owner + "\t" + description + "\t" + (string)position);
  179.  
  180. // Delete oldest teleporter from list if it is too old.
  181. if (llGetListLength(timestamps) && timestamp-llList2Integer(timestamps, 0) > INTERVAL+1.0) {
  182. descriptions = llDeleteSubList(descriptions, 0, 0);
  183. positions = llDeleteSubList(positions, 0, 0);
  184. timestamps = llDeleteSubList(timestamps, 0, 0);
  185. }
  186.  
  187. }
  188.  
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement