Guest User

Untitled

a guest
Jun 23rd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. / improved door script by Ezhar Fairlight
  2. // features: automatic closing, workaround for rotating out of position,
  3. // doesn't mess up when moved, adjustable direction (inwards/outwards)
  4. // updated for SL 1.1 damped rotations, small bugfix
  5.  
  6. // ********** USER SETTINGS HERE **********
  7. float TIMER_CLOSE = 0; // automatically close the door after this many seconds,
  8. // set to 0 to disable
  9.  
  10. integer DIRECTION = -1; // direction door opens in. Either 1 (outwards) or -1 (inwards);
  11. // ********** END OF USER SETTINGS **********
  12.  
  13.  
  14.  
  15. integer DOOR_OPEN = 1;
  16. integer DOOR_CLOSE = 2;
  17.  
  18. vector mypos; // door position (objects move a tiny amount
  19. // away from their position each time they are rotated,
  20. // thus we need to workaround this by resetting
  21. // the position after rotating)
  22.  
  23. door(integer what) {
  24. rotation rot;
  25. rotation delta;
  26.  
  27. llSetTimerEvent(0); // kill any running timers
  28.  
  29. if ( what == DOOR_OPEN ) {
  30. llTriggerSound("Door open", 0.8);
  31.  
  32. rot = llGetRot();
  33. delta = llEuler2Rot(<0, 0, -DIRECTION * PI_BY_TWO>);
  34. rot = delta * rot; // rotate by -45 degree
  35. llSetRot(rot);
  36.  
  37. } else if ( what == DOOR_CLOSE) {
  38. rot = llGetRot();
  39. delta = llEuler2Rot(<0, 0, DIRECTION * PI_BY_TWO>); // rotate by 45 degree
  40. rot = delta * rot;
  41. llSetRot(rot);
  42.  
  43. llTriggerSound("Door close", 0.8);
  44. }
  45. }
  46.  
  47.  
  48. default { // is closed
  49. on_rez(integer start_param) { // reset, so we store the new position
  50. llResetScript();
  51. }
  52.  
  53. state_entry() {
  54. mypos = llGetPos(); // remember where we're supposed to be
  55. }
  56.  
  57. touch_start(integer total_number) {
  58. door(DOOR_OPEN);
  59.  
  60. state is_open;
  61. }
  62.  
  63. moving_end() { // done moving me around, store new position
  64. mypos = llGetPos();
  65. }
  66. }
  67.  
  68. state is_open {
  69. state_entry() {
  70. llSetTimerEvent(TIMER_CLOSE);
  71. }
  72.  
  73. touch_start(integer num) {
  74. door(DOOR_CLOSE);
  75.  
  76. llSetPos(mypos); // workaround for tiny movements during rotation
  77.  
  78. state default;
  79. }
  80.  
  81. timer() { // it's time to close the door
  82. door(DOOR_CLOSE);
  83.  
  84. llSetPos(mypos); // workaround for tiny movements during rotation
  85.  
  86. state default;
  87. }
  88.  
  89. moving_start() { // close door when door is being moved
  90. door(DOOR_CLOSE);
  91.  
  92. state default;
  93. }
  94. }
Add Comment
Please, Sign In to add comment