10494eb1-6911-9467-09e7-b7e64c0312fb_script.lsl 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // The line above should be left blank to avoid script errors in OpenSim.
  3. // Sloodle Set object simple door script.
  4. //
  5. // Part of the Sloodle project (www.sloodle.org).
  6. // Copyright (c) 2007-8 Sloodle
  7. // Released under the GNU GPL v3
  8. //
  9. // Contributors:
  10. // Edmund Edgar
  11. // Paul Preibisch
  12. integer open=FALSE;
  13. integer SLOODLE_CHANNEL_SET_SIMPLE_DOOR_OPEN =-1639270101;
  14. integer SLOODLE_CHANNEL_SET_SIMPLE_DOOR_CLOSED = -1639270102;
  15. integer SLOODLE_CHANNEL_OBJECT_DIALOG = -3857343;
  16. integer last_touch_ts = 0;
  17. default
  18. {
  19. state_entry()
  20. {
  21. llSetLocalRot(llEuler2Rot( <0, 0, 270.00 * DEG_TO_RAD> ));
  22. llTriggerSound("close",1.0);
  23. llSleep(2); // Give it a couple of seconds for the texture inside the door to load, before we allow the user to open it. This prevents problems with auto-zoom that occur if you click too early.
  24. }
  25. link_message(integer sender_num, integer num, string str, key id)
  26. {
  27. // Check the channel
  28. if (num == SLOODLE_CHANNEL_OBJECT_DIALOG) {
  29. // What was the message?
  30. if (str == "do:reset") llResetScript();
  31. }
  32. }
  33. touch_start(integer total_number)
  34. {
  35. // if(llDetectedKey(0) == llGetOwner())
  36. integer j=0;
  37. for (j=0;j<total_number;j++){
  38. if (llDetectedKey(j)!=llGetOwner()){
  39. llInstantMessage(llDetectedKey(j),"Sorry, but you must be the owner to open this rezzer");
  40. return;
  41. }
  42. }
  43. // If less than three seconds have elapsed since the last touch we handled, ignore it.
  44. // This prevents a double-click closing the door as soon as it finishes opening.
  45. if (llGetUnixTime() - last_touch_ts < 2) {
  46. return;
  47. }
  48. vector theRot = llRot2Euler(llGetLocalRot());
  49. float theRotZ = theRot.z*RAD_TO_DEG;
  50. //the reason we are comparing to -80 instead of -90 is because opensim and sl have different precision for rotations, 90 would probably be ok, but lets be safe!
  51. if (theRotZ<=-80){
  52. llSetLocalRot(llEuler2Rot( <0, 0, 45 * DEG_TO_RAD> ));
  53. llMessageLinked(LINK_ALL_OTHERS,SLOODLE_CHANNEL_SET_SIMPLE_DOOR_CLOSED,"",NULL_KEY);
  54. llTriggerSound("open",1.0);
  55. llTriggerSound("powerup",1.0);
  56. llMessageLinked(LINK_SET, -99, "turn glow on", NULL_KEY);
  57. } else {
  58. llMessageLinked(LINK_ALL_OTHERS,SLOODLE_CHANNEL_SET_SIMPLE_DOOR_OPEN,"",NULL_KEY);
  59. // llSetPos( llGetRootPosition() );
  60. llTriggerSound("close",1.0);
  61. llTriggerSound("powerdown",1.0);
  62. llSetLocalRot(llEuler2Rot( <0, 0, 270 * DEG_TO_RAD> )); open = TRUE;
  63. llMessageLinked(LINK_SET, -99, "turn glow off", NULL_KEY);
  64. }
  65. last_touch_ts = llGetUnixTime();
  66. }
  67. }
  68. // Please leave the following line intact to show where the script lives in Git:
  69. // SLOODLE LSL Script Git Location: mod/set-1.0/objects/default/assets/sloodle_set_simple_door.lslp