teleporter.lslp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. /*
  2. * teleporter_using_crystals.lsl
  3. * Part of the Sloodle project (www.sloodle.org)
  4. *
  5. * Copyright (c) 2011-06 contributors (see below)
  6. * Released under the GNU GPL v3
  7. * -------------------------------------------
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. * All scripts must maintain this copyrite information, including the contributer information listed
  23. *
  24. * DESCRIPTION
  25. * This script was built for an adventure game which involves access to hidden chambers etc.
  26. * A user must collect a blue crystal, drop it onto the ground, to insert it into this teleporter
  27. * Once a crystal has been inserted, the teleporter will be activated for 30 seconds.
  28. * The teleporter makes use of the objects description input field, which you can find in the edit
  29. * box inside the Second Life viewer.
  30. * Enter in: CHANNEL:99882234,NAME:Teleporter,REZSOUND:SND_dancershort,DROPSOUND:SND_splash2
  31. * CHANNEL: is the channel the blue crystal will use to communicate with this teleporter
  32. * NAME is the name of the object which the blue crystal will set its sensors for, and when found, move towards
  33. * REZSOUND is the name of the sound file that will play when this teleporter is rezzed
  34. * After a crystal shouts an INSERT message into this script, this script will send a linked message to
  35. * sloodle_mod_touchable to see if the interaction (teleport) is allowed
  36. * sloodle_mod_touchable will contact the server, and respond via linked message if teleporting is allowed
  37. * ie: if the user's currency matches any restrictions placed in this objects configuration
  38. * if all restrictions have been fulfilled, the teleporter will teleport the sitting user to the destination
  39. * in the config.
  40. *
  41. * THIS VERSION IS FOR OPENSIM - llAvatarSitOnTarget doesnt work in Opensim, so the behavior is modified:
  42. * User must sdrop a crystal in to activate the teleporter, then sit, then click to tp
  43. *
  44. * For this script to function properly, it should have the following sounds inside
  45. * SND_POWER_DOWN
  46. * SND_POWER_UP
  47. * SND_SPARKS
  48. * SND_VORTEX
  49. *
  50. * Accompaning scripts:
  51. * sloodle_mod_touchable-1.0
  52. * sloodle_rezzer_object
  53. * sloodle_setup_notecard_httpin
  54. *
  55. * Contributors:
  56. * Paul Preibisch
  57. * Edmund Edgar
  58. * SND_SPARKS: http://www.freesound.org/people/Connum/
  59. */
  60. // The Long distance telport script license info is below:
  61. //Long distance teleport version 1.1
  62. // ----------------------------------
  63. // This script is based on other public domain free scripts, so I don't
  64. // take credit for any of the work here.
  65. // Bits and pieces combined by Lisbeth Cohen - plus added show/hide.
  66. //
  67. // The basics of the script is based on Till Sterling's simple teleport
  68. // script, with cross sim transportation routine developed by
  69. // Keknehv Psaltery, modified by Strife Onizuka, Talarus Luan and
  70. // Keknehv Psaltery.
  71. // The transportation functionality is based upon Nepenthes Ixchel's
  72. // 1000m Menu-driven Intra-Sim Teleporter
  73. //
  74. // Thank you to authors who have given me permission to publish this script.
  75. // A special thank you to Keknehv Psaltery for suggesting small improvements!
  76. //
  77. // Realeased as public domain - you are NOT allowed to sell it without the
  78. // permissions of all the authors I've credited above (except those who
  79. // may have left sl at the time)!
  80. // Feel free to use it in freebies and to give it to your friends :-)
  81. //
  82. // Please do not take credit for the work of all those great authors
  83. // mentioned above!
  84. // If you edit the script, please do not change the lines above - thanks!
  85. // ------------------------------------------------------------------------
  86. string SLOODLE_EOF = "sloodleeof";
  87. integer eof = FALSE; // Have we reached the end of the configuration data?
  88. integer SLOODLE_CHANNEL_OBJECT_DIALOG = -3857343;//configuration channel
  89. integer isconfigured = 0;
  90. integer MAX=30;
  91. key sitter;
  92. integer counter=0;
  93. string animation;
  94. integer SLOODLE_TELPORTER_POWER_UP= -1639277101;
  95. integer SLOODLE_TELPORTER_POWER_DOWN= -1639277102;
  96. integer SLOODLE_OBJECT_INTERACTION= -1639271132; //channel interaction objects speak on
  97. integer TARGET_CHANNEL;
  98. string TARGET_NAME;
  99. integer SLOODLE_TOUCH_OBJECT_SUCCESS = -1639277100;
  100. vector RED =<1.00000, 0.00000, 0.00000>;
  101. vector ORANGE=<1.00000, 0.43763, 0.02414>;
  102. vector YELLOW=<1.00000, 1.00000, 0.00000>;
  103. vector GREEN=<0.00000, 1.00000, 0.00000>;
  104. vector BLUE=<0.00000, 0.00000, 1.00000>;
  105. vector BABYBLUE=<0.00000, 1.00000, 1.00000>;
  106. vector PINK=<1.00000, 0.00000, 1.00000>;
  107. vector PURPLE=<0.57338, 0.25486, 1.00000>;
  108. vector BLACK= <0.00000, 0.00000, 0.00000>;
  109. vector WHITE= <1.00000, 1.00000, 1.00000>;
  110. //order of animation messages
  111. key userKey;
  112. vector MYDEST;
  113. integer SLOODLE_NOT_ENOUGH_CURRENCY= -1001;// AWARDS You do not have enough points to use this object. (There may be a customized message in the next line.)
  114. integer SLOODLE_OBJECT_REGISTER_INTERACTION= -1639271133; //channel objects send interactions to the mod_interaction-1.0 script on to be forwarded to server
  115. debug(string str){
  116. //llOwnerSay(str);
  117. }
  118. string objecttogive;
  119. integer soundCounter=0;
  120. integer DOOR_STATE;
  121. vector rezzer_position_offset;
  122. rotation rezzer_rotation_offset;
  123. key rezzer_uuid;
  124. /***********************************************
  125. * extractResponse()
  126. * Is used so that sending of linked messages is more readable by humans. Ie: instead of sending a linked message as
  127. * GETDATA|50091bcd-d86d-3749-c8a2-055842b33484
  128. * Context is added instead: COMMAND:GETDATA|PLAYERUUID:50091bcd-d86d-3749-c8a2-055842b33484
  129. * By adding a context to the messages, the programmer can understand whats going on when debugging
  130. * All this function does is strip off the text before the ":" char
  131. ***********************************************/
  132. string extractResponse(string cmd){
  133. return llList2String(llParseString2List(cmd, [":"],[]),1);
  134. }
  135. move_to_layout_position() {
  136. // llOwnerSay("todo: move to position "+(string)rezzer_position_offset+", rot "+(string)rezzer_rotation_offset+ " in relation to rezzer "+(string)rezzer_uuid);
  137. list rezzerdetails = llGetObjectDetails( rezzer_uuid, [ OBJECT_POS, OBJECT_ROT ] );
  138. vector rezzerpos = llList2Vector( rezzerdetails, 0 );
  139. rotation rezzerrot = llList2Rot( rezzerdetails, 1 );
  140. sloodle_set_pos( rezzerpos + ( rezzer_position_offset * rezzerrot ) );
  141. llSetRot( rezzerrot * rezzer_rotation_offset );
  142. }
  143. sloodle_set_pos(vector targetposition){
  144. integer counter=0;
  145. while ((llVecDist(llGetPos(), targetposition) > 0.001)&&(counter<50)) {
  146. counter+=1;
  147. llSetPos(targetposition);
  148. }
  149. }
  150. vector getVector(string s){
  151. list vector_parts = llParseString2List(s,["<",",",">"], []);
  152. vector result;
  153. result.x = llList2Float(vector_parts,0);
  154. result.y = llList2Float(vector_parts,1);
  155. result.z = llList2Float(vector_parts,2);
  156. return result;
  157. }
  158. integer sloodle_handle_command(string str){
  159. // llOwnerSay("handling command "+str);
  160. list bits = llParseString2List(str,["|"],[]);
  161. integer numbits = llGetListLength(bits);
  162. string name;
  163. if (numbits >= 1 ) {
  164. name = llList2String(bits,0);
  165. string value1 = "";
  166. string value2 = "";
  167. if (numbits > 1) value1 = llList2String(bits,1);
  168. if (numbits > 2) value2 = llList2String(bits,2);
  169. }
  170. if (name == "set:destination") {
  171. string dataStr = llList2String(bits,1);
  172. llOwnerSay("dataStr: "+dataStr);
  173. if (llGetSubString(dataStr, 0, 0)=="<"){
  174. MYDEST= getVector(dataStr);
  175. }else{
  176. list data = llParseString2List(dataStr, ["/"], []);
  177. MYDEST= <llList2Float(data, 0),llList2Float(data, 1),llList2Float(data, 2)>;
  178. }
  179. llOwnerSay("Teleporter Destination: "+(string)MYDEST);
  180. }else
  181. if (name == "set:position") {
  182. rezzer_position_offset = (vector)llList2String(bits,1);
  183. rezzer_rotation_offset = (rotation)llList2String(bits,2);
  184. rezzer_uuid = llList2Key(bits,3);
  185. }
  186. return TRUE;
  187. }
  188. trytoTp(key av){
  189. //when touched, tell mod_interaction script that a water action has occured
  190. llMessageLinked(LINK_SET, SLOODLE_OBJECT_REGISTER_INTERACTION, "accessteleporter", av);
  191. llSay(0,"Attempting to Teleport");
  192. }
  193. list give_in_folder;
  194. integer item_no = 0;
  195. //The target location .. change this to where you want to end up (x, y, z)
  196. vector gTargetPos = <246, 181, 415>;
  197. // Text for the "pie menu"
  198. string gSitText="Teleport";
  199. // Return position for tp object - no need to edit
  200. vector gStartPos=<0,0,0>;
  201. // Key for avatar sitting on object, if any
  202. key gAvatarID=NULL_KEY;
  203. // If you don't enable this the teleport object will be left at the destination.
  204. integer gReturnToStartPos=TRUE;
  205. // This routine do the actual transport
  206. warpPos( vector destpos)
  207. { //R&D by Keknehv Psaltery, 05/25/2006
  208. //with a little pokeing by Strife, and a bit more
  209. //some more munging by Talarus Luan
  210. //Final cleanup by Keknehv Psaltery
  211. // Compute the number of jumps necessary
  212. integer jumps = (integer)(llVecDist(destpos, llGetPos()) / 10.0) + 1;
  213. // Try and avoid stack/heap collisions
  214. if (jumps > 100 )
  215. jumps = 100; // 1km should be plenty
  216. list rules = [ PRIM_POSITION, destpos ]; //The start for the rules list
  217. integer count = 1;
  218. while ( ( count = count << 1 ) < jumps)
  219. rules = ([]) + rules + rules; //should tighten memory use.
  220. llSetPrimitiveParams( rules + llList2List( rules, (count - jumps) << 1, count) );
  221. if (sitter!=NULL_KEY){
  222. llUnSit(sitter);
  223. }
  224. move_to_layout_position();
  225. }
  226. string teleporter="OFF";
  227. integer count=0;
  228. default {
  229. on_rez(integer start_param) {
  230. llResetScript();
  231. llSitTarget ( <-0.00000, 0.00000, 1.20565>, <0.00000, 0.00000, 0.00000, 1.00000>);
  232. }
  233. state_entry() {
  234. llSitTarget(<0.0, 0.0, 1.0>, ZERO_ROTATION);
  235. teleporter="ON";
  236. }
  237. changed(integer change) {
  238. if ((change & CHANGED_LINK) != 0){
  239. sitter = llAvatarOnSitTarget();
  240. // llOwnerSay((string)sitter);
  241. if (sitter!=NULL_KEY){
  242. trytoTp(sitter);
  243. }
  244. }
  245. }
  246. link_message(integer sender_num, integer num, string str, key id) {
  247. // Split the data up into lines
  248. list lines = llParseStringKeepNulls(str, ["\n"], []);
  249. integer numlines = llGetListLength(lines);
  250. // Extract all the status fields
  251. list statusfields = llParseStringKeepNulls( llList2String(lines,0), ["|"], [] );
  252. // Get the statuscode
  253. integer statuscode = llList2Integer(statusfields,0);
  254. key user = llList2Key(statusfields,6);
  255. // Was it an error code?
  256. if (num==SLOODLE_CHANNEL_OBJECT_DIALOG){
  257. llTriggerSound("SND_POWER_UP", 1);
  258. }
  259. if (num==SLOODLE_OBJECT_INTERACTION){
  260. string notenoughcurrencymessage=llList2String(lines,1);
  261. if (statuscode==1){
  262. if (llList2String(lines,1)=="accessteleporter"){
  263. llSay(0,"Teleporting to: "+(string)MYDEST);
  264. llTriggerSound("SND_TELEPORTING", 0.7);
  265. warpPos(MYDEST);
  266. }
  267. }else if (statuscode=-1001){
  268. llSay(0,notenoughcurrencymessage);
  269. llTriggerSound("SND_SPARKS", 0.7);
  270. llUnSit(sitter);
  271. }
  272. }
  273. if (num == SLOODLE_CHANNEL_OBJECT_DIALOG) {
  274. // Split the message into lines
  275. integer i = 0;
  276. for (i=0; i < numlines; i++) {
  277. isconfigured = sloodle_handle_command(llList2String(lines, i));
  278. }
  279. return;
  280. }
  281. }
  282. }
  283. // Please leave the following line intact to show where the script lives in Git:
  284. // SLOODLE LSL Script Git Location: mod/interaction-1.0/objects/teleporter/assets/teleporter.lslp