script transporter.txt.txt 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. // Ferd Frederix
  2. integer debug = 0;
  3. float TIME = 6.0;
  4. integer channel; // listener from other prim
  5. integer listener; // channel handle
  6. float oldDist;
  7. vector StartSeatedRotation = <0, 0, 0>; // animation start rotation
  8. vector StopSeatedRotation = <0, 0, 180>; // animation stop rotation
  9. vector StartSeatedOffset = <0, 0, 0.5>; // where we sit to start
  10. vector StopSeatedOffset = <.5, 0, 0.2>; // where we end up after teleport
  11. vector DestPosition; // calculated offset to the other door
  12. rotation DestRotation; // calculated rotation when we get there
  13. string animation ; // calculated animation name
  14. key AvatarKey; // key of who touched the door
  15. BootUp(integer newchannel)
  16. {
  17. oldDist = 0;
  18. channel = newchannel;
  19. if (debug) llOwnerSay("Channel=" + (string) channel);
  20. listener = llListen(channel,"","","");
  21. rotation SeatedRotation = llEuler2Rot( StartSeatedRotation * DEG_TO_RAD) * llGetRot();
  22. //llOwnerSay("bootup=" + (string) StartSeatedOffset+ "..." + (string) SeatedRotation);
  23. llSitTarget(StartSeatedOffset, <0,0,0,1>);
  24. animation = llGetInventoryName(INVENTORY_ANIMATION,0);
  25. llSetSitText("Enter");
  26. llRegionSay(channel,"reset");
  27. llSetTimerEvent(30); // die when the door shuts
  28. }
  29. MovePrim(float dir)
  30. {
  31. vector vPosOffset = <dir, 0.0, 0.0>; //-- creates an offset one tick in the positive X direction.
  32. integer i = 0;
  33. for (i = 0; i < 20; i++)
  34. {
  35. vector vPosRotOffset = vPosOffset * llGetRot(); //-- rotate the offset to be relative to objects rotation
  36. vector vPosOffsetIsAt = llGetPos() + vPosRotOffset; //-- get the region position of the rotated offset
  37. llSetPos(vPosOffsetIsAt);
  38. }
  39. }
  40. Go()
  41. {
  42. if (debug) llOwnerSay("starting animation");
  43. llStartAnimation(animation);
  44. MovePrim(.1);
  45. if (debug) llOwnerSay("starting movement to " + (string )DestPosition);
  46. warpPos();
  47. MovePrim(.1);
  48. if (debug) llOwnerSay("ending animation");
  49. llStopAnimation(animation);
  50. llUnSit(AvatarKey);
  51. if (! debug)
  52. llDie();
  53. }
  54. warpPos()
  55. { //R&D by Keknehv Psaltery, 05/25/2006
  56. //with a little poking by Strife, and a bit more
  57. //some more munging by Talarus Luan
  58. //Final cleanup by Keknehv Psaltery
  59. //Changed jump value to 411 (4096 ceiling) by Jesse Barnett
  60. // Compute the number of jumps necessary
  61. // rotated by Ferd Frederix
  62. //llSitTarget(destpos, ROT);//Set the sit target
  63. integer jumps = (integer)(llVecDist(DestPosition, llGetPos()) / 10.0) + 1;
  64. // Try and avoid stack/heap collisions
  65. if (jumps > 411)
  66. jumps = 411;
  67. list rules = [ PRIM_POSITION, DestPosition ]; //The start for the rules list
  68. integer count = 1;
  69. while ( ( count = count << 1 ) < jumps)
  70. rules = (rules=[]) + rules + rules; //should tighten memory use.
  71. llSetPrimitiveParams( rules + llList2List( rules, (count - jumps) << 1, count) );
  72. if ( llVecDist( llGetPos(), DestPosition ) > .001 ) //Failsafe
  73. while ( --jumps )
  74. llSetPos( DestPosition );
  75. DestRotation = llEuler2Rot( StopSeatedRotation * DEG_TO_RAD) * DestRotation ; // maybe rotate
  76. //DestRotation = llGetRot() * DestRotation ; // maybe rotate
  77. llSetRot(DestRotation); // set dest rotation
  78. llWhisper(channel,"open");
  79. llSleep(1.0);
  80. }
  81. default
  82. {
  83. state_entry()
  84. {
  85. BootUp((integer) llGetObjectDesc());
  86. }
  87. changed (integer what)
  88. {
  89. if (what & CHANGED_LINK)
  90. {
  91. if (debug) llOwnerSay("changed");
  92. AvatarKey = llAvatarOnSitTarget();
  93. if (AvatarKey != NULL_KEY)
  94. {
  95. if (DestPosition != <0,0,0>)
  96. {
  97. if (debug) llOwnerSay("request perms");
  98. llRequestPermissions(AvatarKey,PERMISSION_TRIGGER_ANIMATION );
  99. }
  100. else
  101. {
  102. llOwnerSay("Did not locate a second door by the same number!");
  103. llUnSit(AvatarKey);
  104. }
  105. }
  106. }
  107. else
  108. {
  109. animation = llGetInventoryName(INVENTORY_ANIMATION,0);
  110. }
  111. }
  112. run_time_permissions(integer perm)
  113. {
  114. if(PERMISSION_TRIGGER_ANIMATION & perm)
  115. {
  116. if (debug) llOwnerSay("perms granted");
  117. Go();
  118. }
  119. }
  120. on_rez(integer p)
  121. {
  122. BootUp(p);
  123. }
  124. timer()
  125. {
  126. llSetTimerEvent(0);
  127. if (! debug)
  128. llDie();
  129. }
  130. listen(integer channel,string name, key id, string message)
  131. {
  132. if(debug) llOwnerSay("Heard:" + message);
  133. if (id == llGetKey())
  134. return;
  135. if (message == "reset")
  136. return;
  137. if (message == "open")
  138. return;
  139. list params = llParseString2List(message,["|"],[""]);
  140. vector DestPositionproto = (vector) llList2String(params,0);
  141. rotation DestRotationproto = (rotation) llList2String(params,1);
  142. // remember the furthest prim that responds
  143. float dist = llVecDist(DestPositionproto,llGetPos());
  144. if (dist > oldDist)
  145. {
  146. DestRotation = DestRotationproto;;
  147. DestPosition = DestPositionproto;
  148. oldDist = dist;
  149. }
  150. if (debug) llOwnerSay("Located:" + (string) DestPosition + " rot:" + (string) DestRotation);
  151. vector vPosRotOffset = StopSeatedOffset * DestRotation; //-- rotate the offset to be relative to objects rotation
  152. DestPosition = DestPosition + vPosRotOffset; //-- get the region position of the rotated offset
  153. if (debug) llOwnerSay("Set Pos:" + (string) DestPosition + " rot:" + (string) DestRotation);
  154. }
  155. }