LSL Audio Scripts

//LOOPS SOUND

default

{

    state_entry()

    {

        llLoopSound("FridgeFan-001", 1.0);

    }


}




//PLAY SOUND ONCE

default

{

    state_entry()

    {

        llPlaySound("FridgeFan-001", 1.0);

    }


}




//PLAY ON TOUCH


 

string sound = "NAME OF SOUND"; 

 

default

{

    touch_start(integer total_num)

    {

        llTriggerSound(sound, 1.0);

    }

}




//RANDOM SOUNDS IN PRIM


float MinimumSeconds = 10.0;

float MaximumSeconds = 30.0;

float volume = 0.5; // How loud? Between 0 and 1.



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 );

    }

}


default

{


    state_entry()

    {

        LoadSounds();

        

        if ( sounds > 0 )

            llSetTimerEvent( 0.1 );

        else

            llOwnerSay("No sounds.");

    }

    

    timer()

    {

        integer random = (integer) llFrand ( sounds );

        string sound = llList2String( soundnames, random );

        llTriggerSound( sound, volume );

        

        llSetTimerEvent( MinimumSeconds + (llFrand( MaximumSeconds - MinimumSeconds)) );

    }

    

    changed (integer change)

    { 

        if (change & CHANGED_INVENTORY)

        {

            llResetScript();

        }

    }

}




//TRIPWIRE PRIMS



default

{

    state_entry()

    {

        if (llGetStatus(STATUS_PHANTOM))

//      {

            llVolumeDetect(TRUE);

//      }

    }

 

    collision_start(integer num_detected)

    {

        string firstSoundInPrim = llGetInventoryName(INVENTORY_SOUND, 0);

 

        llPlaySound(firstSoundInPrim, 1.0);

    }

}



//TOGGLE SOUND



string sound = "air_outlet";

integer gON;

 

default

{

    touch_start(integer total_num)

    {

    {        gON = !gON;

    if (gON)   

        llLoopSound(sound, 1.0);

    else 

    llStopSound();

}

}

}