Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.82 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 = 10.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. llSetLocalRot(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. llSetLocalRot(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. collision(integer number) {
  64. door(DOOR_OPEN);
  65.  
  66. state is_open;
  67. }
  68.  
  69.  
  70. moving_end() { // done moving me around, store new position
  71. mypos = llGetPos();
  72. }
  73. }
  74.  
  75. state is_open {
  76. state_entry() {
  77. llSetTimerEvent(TIMER_CLOSE);
  78. }
  79.  
  80. touch_start(integer num) {
  81. door(DOOR_CLOSE);
  82.  
  83. llSetPos(mypos); // workaround for tiny movements during rotation
  84.  
  85. state default;
  86. }
  87.  
  88.  
  89. timer() { // it's time to close the door
  90. door(DOOR_CLOSE);
  91.  
  92. llSetPos(mypos); // workaround for tiny movements during rotation
  93.  
  94. state default;
  95. }
  96.  
  97. moving_start() { // close door when door is being moved
  98. door(DOOR_CLOSE);
  99.  
  100. state default;
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement