Advertisement
Bugs_Larnia

LSL: Toll Bell on the Hour

Jan 13th, 2021 (edited)
872
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* TOLL BELL ON HOUR
  2. Created 2020-03-24 by Bugs Larnia
  3. Please keep annotations
  4. */
  5.  
  6. //USER SETTINGS;
  7. float gfInterval = 3.5; //Interval between chimes in seconds
  8. //END USER SETTINGS
  9.  
  10. //Global variables
  11. key gkDefaultSound = "e26c8e8f-0896-ec74-c796-bc6287aa7807"; //In case no sound was loaded in prim inventory
  12. key gkSound;
  13. integer giLastHour;
  14.  
  15. //Sets the sound that needs to be used, either from prim inventory or the default
  16. SetSound()
  17. {
  18.     if (llGetInventoryNumber(INVENTORY_SOUND) > 0)
  19.     {
  20.         gkSound = llGetInventoryKey(llGetInventoryName(INVENTORY_SOUND, 0));
  21.     }
  22.     else
  23.     {
  24.         gkSound = gkDefaultSound;
  25.     }
  26.     llPreloadSound(gkSound); //Preload sound for faster playback
  27. }
  28.  
  29. //Checks the time
  30. CheckTime()
  31. {
  32.     integer iTime = (integer)llGetWallclock(); //Get SLT time as a number of seconds since midnight
  33.     integer iMinutes = (iTime / 60) % 60; //Get the minutes
  34.     integer iHours = (iTime / 3600); //Get the hours
  35.    
  36.     if ((iMinutes == 0) && (iHours != giLastHour)) //If minutes is 0 and hour is different from last one, chime
  37.     {
  38.         ChimeHour(iHours);
  39.     }
  40. }
  41.  
  42. //Determine the number of times to ring the bell and then ring it
  43. ChimeHour(integer piHour)
  44. {
  45.     integer i;
  46.    
  47.     giLastHour = piHour; //Update last hour
  48.     if (piHour > 12) //Compensate for 24 hour clock
  49.     {
  50.         piHour -= 12;
  51.     }
  52.     else if (piHour == 0) //Compensate for midnight
  53.     {
  54.         piHour = 12;
  55.     }
  56.    
  57.     for (i = 0; i < piHour; ++i) //Sound the bell the required number of times
  58.     {
  59.         SoundBell();
  60.     }
  61. }
  62.  
  63. //Ring the bell with optional pauses
  64. SoundBell()
  65. {
  66.     llPlaySound(gkSound, 1.0);
  67.     llSleep(gfInterval);
  68. }
  69.  
  70. default
  71. {
  72.     state_entry()
  73.     {
  74.         SetSound();
  75.         llSetTimerEvent(2.0);
  76.     }
  77.    
  78.     timer()
  79.     {
  80.         CheckTime();
  81.     }
  82.    
  83.     changed(integer piChange)
  84.     {
  85.         if (piChange & CHANGED_INVENTORY)
  86.         {
  87.             SetSound(); //Check for new bell sound, since inventory has changed
  88.         }
  89.     }
  90.    
  91.     //Debugging
  92.     touch_start(integer piNum)
  93.     {
  94.         //Test - for owner only
  95.         if (llDetectedKey(0) == llGetOwner())
  96.         {
  97.             ChimeHour(6); //Should sound the number of times indicated in parentheses
  98.         }
  99.     }
  100.    
  101.     //Hourskeeping
  102.     on_rez(integer piParam)
  103.     {
  104.         llResetScript();
  105.     }
  106. }
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement