script transporter.lsl 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. // :SHOW:
  2. // :CATEGORY:Teleport
  3. // :NAME:Elven Door Teleport System
  4. // :AUTHOR:Ferd Frederix
  5. // :KEYWORDS:
  6. // :CREATED:2014-12-04 12:11:30
  7. // :EDITED:2015-04-14 11:57:46
  8. // :ID:1056
  9. // :NUM:1679
  10. // :REV:2
  11. // :WORLD:Second Life
  12. // :DESCRIPTION:
  13. // DESCRIPTION: []::Elven Door teleport System invisible prim - put inside the main system
  14. // :CODE:
  15. // Ferd Frederix
  16. integer debug = 0;
  17. float TIME = 6.0; // animation play time
  18. integer channelin; // listener from other prim
  19. integer menuchannel; // a random channel for hearing the Dialog box
  20. integer chathandle; // handle for the menu, we destroy it to kill lag
  21. integer listener; // channel handle
  22. float oldDist;
  23. vector StartSeatedRotation = <0, 0, 0>; // animation start rotation
  24. vector StopSeatedRotation = <0, 0, -90>; // animation stop rotation
  25. vector StartSeatedOffset = <0, 0, 0.5>; // where we sit to start
  26. vector StopSeatedOffset = <0, .5, 0.2>; // where we end up after teleport
  27. vector DestPosition; // calculated offset to the other door
  28. rotation DestRotation; // calculated rotation when we get there
  29. string animation ; // calculated animation name
  30. key AvatarKey; // key of who touched the door
  31. list menu; // storage for all the remoted doors
  32. Menu()
  33. {
  34. menuchannel = llCeil(llFrand(1000000) + 99999); // large random #
  35. chathandle = llListen(menuchannel,"","",""); // listen for Dialog
  36. integer i = llGetListLength(menu);
  37. list buttons;
  38. integer j;
  39. // make a menu from what we have heard
  40. for (j = 0; j < i; j+=3)
  41. buttons += llList2String(menu,j);
  42. if (debug) llOwnerSay("button channel = " + (string)menuchannel +":" + llDumpList2String(buttons,"=="));
  43. llDialog(AvatarKey,"Pick a destination",buttons,menuchannel);
  44. }
  45. BootUp(integer newchannel)
  46. {
  47. oldDist = 0;
  48. channelin = newchannel;
  49. if (debug) llOwnerSay("Channel=" + (string) channelin);
  50. listener = llListen(channelin,"","","");
  51. rotation SeatedRotation = llEuler2Rot( StartSeatedRotation * DEG_TO_RAD) * llGetRot();
  52. //llOwnerSay("bootup=" + (string) StartSeatedOffset+ "..." + (string) SeatedRotation);
  53. llSitTarget(StartSeatedOffset, <0,0,0,1>);
  54. animation = llGetInventoryName(INVENTORY_ANIMATION,0);
  55. llSetSitText("Enter");
  56. llRegionSay(channelin,"reset");
  57. llSetTimerEvent(30); // die when the door shuts
  58. }
  59. MovePrim(float dir)
  60. {
  61. vector vPosOffset = <dir, 0.0, 0.0>; //-- creates an offset one tick in the positive X direction.
  62. integer i = 0;
  63. for (i = 0; i < 20; i++)
  64. {
  65. vector vPosRotOffset = vPosOffset * llGetRot(); //-- rotate the offset to be relative to objects rotation
  66. vector vPosOffsetIsAt = llGetPos() + vPosRotOffset; //-- get the region position of the rotated offset
  67. llSetPos(vPosOffsetIsAt);
  68. }
  69. }
  70. Go()
  71. {
  72. if (debug) llOwnerSay("starting animation");
  73. llStartAnimation(animation);
  74. MovePrim(.1);
  75. if (debug) llOwnerSay("starting movement to " + (string )DestPosition);
  76. warpPos();
  77. MovePrim(.1);
  78. if (debug) llOwnerSay("ending animation");
  79. llStopAnimation(animation);
  80. llUnSit(AvatarKey);
  81. if (! debug)
  82. llDie();
  83. }
  84. warpPos()
  85. {
  86. llSetRegionPos( DestPosition );
  87. DestRotation = llEuler2Rot( StopSeatedRotation * DEG_TO_RAD) * DestRotation ; // maybe rotate
  88. //DestRotation = llGetRot() * DestRotation ; // maybe rotate
  89. llSetRot(DestRotation); // set dest rotation
  90. llWhisper(channelin,"open");
  91. llSleep(1.0);
  92. }
  93. default
  94. {
  95. state_entry()
  96. {
  97. if (((integer) llGetObjectDesc()) == 0)
  98. llSetObjectDesc("22221");
  99. BootUp((integer) llGetObjectDesc());
  100. }
  101. changed (integer what)
  102. {
  103. if (what & CHANGED_LINK)
  104. {
  105. if (debug) llOwnerSay("changed");
  106. AvatarKey = llAvatarOnSitTarget();
  107. if (AvatarKey != NULL_KEY)
  108. {
  109. integer i = llGetListLength(menu);
  110. if (debug) llOwnerSay("Menu L= " + (string) i);
  111. if (i > 0)
  112. Menu();
  113. }
  114. }
  115. else
  116. {
  117. animation = llGetInventoryName(INVENTORY_ANIMATION,0);
  118. }
  119. }
  120. run_time_permissions(integer perm)
  121. {
  122. if(PERMISSION_TRIGGER_ANIMATION & perm)
  123. {
  124. if (debug) llOwnerSay("perms granted");
  125. Go();
  126. }
  127. }
  128. on_rez(integer p)
  129. {
  130. if (p ==0)
  131. p = (integer) llGetObjectDesc();
  132. BootUp(p);
  133. }
  134. timer()
  135. {
  136. llSetTimerEvent(0);
  137. if (! debug)
  138. llDie();
  139. }
  140. listen(integer channels,string name, key id, string message)
  141. {
  142. if(debug) llOwnerSay("Heard:" + message);
  143. if (channels == channelin)
  144. {
  145. if (id == llGetKey())
  146. return;
  147. if (message == "reset")
  148. return;
  149. if (message == "open")
  150. return;
  151. list params = llParseString2List(message,["|"],[""]);
  152. vector DestPositionproto = (vector) llList2String(params,0);
  153. rotation DestRotationproto = (rotation) llList2String(params,1);
  154. // remember the furthest prim that responds
  155. float dist = llVecDist(DestPositionproto,llGetPos());
  156. menu += name;
  157. menu += DestPositionproto;
  158. menu += DestRotationproto;
  159. if (debug) llOwnerSay("Set Pos:" + (string) DestPosition + " rot:" + (string) DestRotation);
  160. }
  161. else if (channels == menuchannel)
  162. {
  163. llListenRemove(chathandle);
  164. integer i = llGetListLength(menu);
  165. integer j;
  166. for (j = 0; j < i; j+=3)
  167. {
  168. if ( llList2String(menu,j) == message) // they want to go somewhere
  169. {
  170. DestPosition = llList2Vector(menu,j+1);
  171. DestRotation = llList2Rot(menu,j+2);
  172. // convert position to lsl rotated form
  173. if (debug) llOwnerSay("Located:" + (string) DestPosition + " rot:" + (string) DestRotation);
  174. vector vPosRotOffset = StopSeatedOffset * DestRotation; //-- rotate the offset to be relative to objects rotation
  175. DestPosition = DestPosition + vPosRotOffset; //-- get the region position of the rotated offset
  176. if (DestPosition != <0,0,0>)
  177. {
  178. if (debug) llOwnerSay("request perms");
  179. llRequestPermissions(AvatarKey,PERMISSION_TRIGGER_ANIMATION );
  180. }
  181. }
  182. }
  183. }
  184. }
  185. }