Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* TOLL BELL ON HOUR
- Created 2020-03-24 by Bugs Larnia
- Please keep annotations
- */
- //USER SETTINGS;
- float gfInterval = 3.5; //Interval between chimes in seconds
- //END USER SETTINGS
- //Global variables
- key gkDefaultSound = "e26c8e8f-0896-ec74-c796-bc6287aa7807"; //In case no sound was loaded in prim inventory
- key gkSound;
- integer giLastHour;
- //Sets the sound that needs to be used, either from prim inventory or the default
- SetSound()
- {
- if (llGetInventoryNumber(INVENTORY_SOUND) > 0)
- {
- gkSound = llGetInventoryKey(llGetInventoryName(INVENTORY_SOUND, 0));
- }
- else
- {
- gkSound = gkDefaultSound;
- }
- llPreloadSound(gkSound); //Preload sound for faster playback
- }
- //Checks the time
- CheckTime()
- {
- integer iTime = (integer)llGetWallclock(); //Get SLT time as a number of seconds since midnight
- integer iMinutes = (iTime / 60) % 60; //Get the minutes
- integer iHours = (iTime / 3600); //Get the hours
- if ((iMinutes == 0) && (iHours != giLastHour)) //If minutes is 0 and hour is different from last one, chime
- {
- ChimeHour(iHours);
- }
- }
- //Determine the number of times to ring the bell and then ring it
- ChimeHour(integer piHour)
- {
- integer i;
- giLastHour = piHour; //Update last hour
- if (piHour > 12) //Compensate for 24 hour clock
- {
- piHour -= 12;
- }
- else if (piHour == 0) //Compensate for midnight
- {
- piHour = 12;
- }
- for (i = 0; i < piHour; ++i) //Sound the bell the required number of times
- {
- SoundBell();
- }
- }
- //Ring the bell with optional pauses
- SoundBell()
- {
- llPlaySound(gkSound, 1.0);
- llSleep(gfInterval);
- }
- default
- {
- state_entry()
- {
- SetSound();
- llSetTimerEvent(2.0);
- }
- timer()
- {
- CheckTime();
- }
- changed(integer piChange)
- {
- if (piChange & CHANGED_INVENTORY)
- {
- SetSound(); //Check for new bell sound, since inventory has changed
- }
- }
- //Debugging
- touch_start(integer piNum)
- {
- //Test - for owner only
- if (llDetectedKey(0) == llGetOwner())
- {
- ChimeHour(6); //Should sound the number of times indicated in parentheses
- }
- }
- //Hourskeeping
- on_rez(integer piParam)
- {
- llResetScript();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement