Script:Day Random Sounds
Jump to navigation
Jump to search
<lsl> /*
This script will play the sounds in the object's inventory randomly during the region's day.
- /
float MinimumSeconds = 10.0; float MaximumSeconds = 30.0; float volume = 0.5; // How loud? Between 0 and 1. float DaylightCheckSeconds = 60.0;
/////////////////////////////////////////////////////////////////////// integer sounds = 0; // # sounds in inventory list soundnames; // names of sounds in inventory /////////////////////////////////////////////////////////////////////// LoadSounds() {
soundnames = []; sounds = llGetInventoryNumber( INVENTORY_SOUND ); integer n; for ( n=0; n < sounds; ++n ) { soundnames += llGetInventoryName( INVENTORY_SOUND, n ); }
} /////////////////////////////////////////////////////////////////////// integer IsSunUp() {
vector sunPosition = llGetSunDirection(); return ( sunPosition.z > 0 );
} /////////////////////////////////////////////////////////////////////// default {
state_entry() { LoadSounds(); if ( sounds > 0 ) llSetTimerEvent( 0.1 ); else llOwnerSay("No sounds."); } timer() { if ( IsSunUp() == TRUE ) { integer random = (integer) llFrand ( sounds ); string sound = llList2String( soundnames, random ); llTriggerSound( sound, volume ); llSetTimerEvent( MinimumSeconds + (llFrand( MaximumSeconds - MinimumSeconds)) ); } else llSetTimerEvent( DaylightCheckSeconds ); } changed (integer change) { if (change & CHANGED_INVENTORY) { llResetScript(); } }
} </lsl>