Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

~Sound Script Needed~

ZsuZsanna Raven
~:+: Supah Kitteh :+:~
Join date: 19 Dec 2004
Posts: 2,361
10-09-2007 15:47
Hello there, I am in need of a script that when placed in a prim with a few different sounds will play each sound randomly. Yeah that probably made no sense lol. Basically I have set up my land for Halloween and I bought what I thought were sound prims that I could place around my land, but in actuality they were just sounds and nothing else. What I want to do is place the sounds in a prim with a script that will play each sound fully in a random order. Kinda of like an AO for sounds. I've looked in SL but can't seem to find anything of help. Does anyone have any ideas on this for me? Thanks!
_____________________
~Mewz!~ :p
Ace Cassidy
Resident Bohemian
Join date: 5 Apr 2004
Posts: 1,228
10-09-2007 16:30
Try this. I'm not in world to compile and verify, but it should do what you want.

-- Begin code

integer gSoundCount;
float gPlayFrequency = 20.0;

default
{
state_entry()
{
gSoundCount = llGetInventoryNumber(INVENTORY_SOUND);
llSetTimerEvent(gPlayFrequency);
}

changed(integer change)
{
if ( change == CHANGED_INVENTORY )
gSoundCount = llGetInventoryNumber(INVENTORY_SOUND);
}

timer()
{
llPlaySound(llFloor(llFrand(gSoundCount)));
}
}
_____________________
"Free your mind, and your ass will follow" - George Clinton
ZsuZsanna Raven
~:+: Supah Kitteh :+:~
Join date: 19 Dec 2004
Posts: 2,361
10-10-2007 10:11
I tried that but it kept saying error after saving :(
_____________________
~Mewz!~ :p
FireEyes Fauna
Registered User
Join date: 26 Apr 2004
Posts: 138
10-10-2007 11:12
llPlaySound(llGetInventoryName(llFloor(llFrand(gSoundCount))),1.0);

I sent you the modified script in world
ZsuZsanna Raven
~:+: Supah Kitteh :+:~
Join date: 19 Dec 2004
Posts: 2,361
10-11-2007 07:19
I got the script and I thank you, the only problem is it randomly has a script error that says "Couldn't find sound" Other than that, it is playing the sounds. If I need to modify anything please let me know what and I'll try to fix it hehe.
_____________________
~Mewz!~ :p
Anthalia Nemeth
Registered User
Join date: 8 Mar 2007
Posts: 17
10-13-2007 06:51
This will play a random sound from the object's inventory at full volume every X seconds.
CODE

// Plays random sound in object's inventory by GarrMe Dagger 10.13.07

float fTime = 15.0; // How long between playing sounds

default
{
state_entry()
{
llSetTimerEvent(fTime);
}
timer()
{
float num = (float)llGetInventoryNumber(INVENTORY_SOUND);
llPlaySound(llGetInventoryName(INVENTORY_SOUND, (integer)llFrand(num)), 1.0);
}
}