Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Sound Trigger Script ?

BloodDoll Lulu
FIX Inventory Issues 1st
Join date: 9 Jul 2005
Posts: 152
08-31-2005 06:50
Is there a way through a script for a sound to trigger when a player gets near a certain objective/point whatever you chose? I tried looking for it, not sure what it might be called if it exists but I've seen a few houses that say welcome and weren't streaming music either... but anyway if anyone can help me out, I would really appreciate it.

thanks
Jesrad Seraph
Nonsense
Join date: 11 Dec 2004
Posts: 1,463
08-31-2005 08:01
Yup, fairly easy. First you need a prim that takes up the space where you want people to trigger sound when they enter. If triggered when passing a door, make this prim take up the space within the door's opening, for example.

Then drop your sound to be played in its inventory, along with this script:
CODE

default {
state_entry() { llSetAlpha(0.0, ALL_SIDES); llVolumeDetect(TRUE); }

collision_start(integer c) { llTriggerSound(llGetInventoryName(INVENTORY_SOUND, 0), 1.0); }
}
_____________________
Either Man can enjoy universal freedom, or Man cannot. If it is possible then everyone can act freely if they don't stop anyone else from doing same. If it is not possible, then conflict will arise anyway so punch those that try to stop you. In conclusion the only strategy that wins in all cases is that of doing what you want against all adversity, as long as you respect that right in others.
BloodDoll Lulu
FIX Inventory Issues 1st
Join date: 9 Jul 2005
Posts: 152
08-31-2005 08:14
Hey THANK you, you are so nice. I was playing around trying to get a couple sounds to cycle... not sure if that works, but the script you put up, does nicely. Made a huge difference in something I was trying to present.

thank you
Keknehv Psaltery
Hacker
Join date: 11 Apr 2005
Posts: 1,185
08-31-2005 10:27
Ahem, Jesrad's code was a bit ugly... here's it beautified.

CODE

default
{
state_entry()
{
llSetAlpha(0, ALL_SIDES);
llVolumeDetect(TRUE);
}

collision_start(integer c)
{
llTriggerSound(llGetInventoryName(INVENTORY_SOUND,0), 1.0);
}
}
BloodDoll Lulu
FIX Inventory Issues 1st
Join date: 9 Jul 2005
Posts: 152
08-31-2005 21:00
thanks for the post Keknehv, and both of you for taking the time to answer my question. I really appreciate it. Been looking for awhile. Is there a way to play a random sound or a serious of sounds or if i drop a few into the prim i use will they play randomly or will it confuse the script?
Keknehv Psaltery
Hacker
Join date: 11 Apr 2005
Posts: 1,185
08-31-2005 21:20
Sure, that's manageable.

Just explain exactly what you want. Do you want it to continuosly play random sounds? On touch? On command?

The more you define a script, the easier it is to make it.
BloodDoll Lulu
FIX Inventory Issues 1st
Join date: 9 Jul 2005
Posts: 152
08-31-2005 21:33
just something that randomly plays, not by touch, just plays. You know like a bunch of ambient sounds, thunder, rain, wind, wolf howl... all just playing. That's just an example. It could be for urban too.
a lost user
Join date: ?
Posts: ?
09-01-2005 01:22
From: BloodDoll Lulu
just something that randomly plays, not by touch, just plays. You know like a bunch of ambient sounds, thunder, rain, wind, wolf howl... all just playing. That's just an example. It could be for urban too.



Well those are all different "types" of ambient sounds and you will need to treat each "type" differently.. For example, you will want to continualy loop the rain sound and possibly even the wind sound as they are, more or less, continuous sounds in the environment. It's either raining or it's not; the wind is either blowing or it's not.. so when it's raining, you need the rain sound to loop. when the wind is blowing, you need the wind sound to loop.

On the other hand you have thunder and wolf howl, these are sounds that would not be played continuously. You'd want a random time between each one with a reasonable space of time between them. So these sounds would need triggering within the script using timer events.

What this means is that you couldn't just throw in all your sounds, into a generic script that played random sounds, and expect it to play correctly. You would need to do some work, whether through a notecard or hardcoded into the script, to set up which sounds are looping sounds, which sounds are triggered sounds and how to treat all the soundsl so that rather than all playing randomly, they would play "correctly".
Jesrad Seraph
Nonsense
Join date: 11 Dec 2004
Posts: 1,463
09-01-2005 02:25
Random play of sounds at various times:
CODE

default
{
state_entry()
{
llSetTimerEvent(30.0);
}

timer()
{
integer n = llGetInventoryNumber(INVENTORY_SOUND);
llTriggerSound(llGetInventoryName(INVENTORY_SOUND, llFloor(llFrand(n))));
llSetTimerEvent(20.0 + llFrand(20.0));
}
}


Continuous playing of a sound when touched (touch again to turn off):
CODE

integer is_active = FALSE;

default
{
touch_start(integer c)
{
if (llDetectedKey(0) != llGetOwner()) return;
if (is_active) { is_active = FALSE; llStopSound(); } else
{ is_active = TRUE; llLoopSound(llGetInventoryName(INVENTORY_SOUND, 0), 1.0); }
}
}
_____________________
Either Man can enjoy universal freedom, or Man cannot. If it is possible then everyone can act freely if they don't stop anyone else from doing same. If it is not possible, then conflict will arise anyway so punch those that try to stop you. In conclusion the only strategy that wins in all cases is that of doing what you want against all adversity, as long as you respect that right in others.
BloodDoll Lulu
FIX Inventory Issues 1st
Join date: 9 Jul 2005
Posts: 152
09-01-2005 02:48
hey thank you for the code. Can you animate too? I'll pay you. Thanks for doing this though.
BloodDoll Lulu
FIX Inventory Issues 1st
Join date: 9 Jul 2005
Posts: 152
09-01-2005 09:50
this one gives me an error actually


default
{
state_entry()
{
llSetTimerEvent(30.0);
}

timer()
{
integer n = llGetInventoryNumber(INVENTORY_SOUND);
llTriggerSound(llGetInventoryName(INVENTORY_SOUND, llFloor(llFrand(n)));
llSetTimerEvent(20.0 + llFrand(20.0));
}
}
Keknehv Psaltery
Hacker
Join date: 11 Apr 2005
Posts: 1,185
09-01-2005 09:56
BloodLulu, please use the PHP tags. I think she was missing a parentheses...

Add one to the end of the longest line.
BloodDoll Lulu
FIX Inventory Issues 1st
Join date: 9 Jul 2005
Posts: 152
09-01-2005 10:52
ah sorry I tried to edit it several times it wouldnt let me... i should have started a new post.

Alright I
ll try to fix it. Not sure why I played around with it a few times but..
Jesrad Seraph
Nonsense
Join date: 11 Dec 2004
Posts: 1,463
09-01-2005 11:02
I've edited my post, there was indeed a missing parenthese.
_____________________
Either Man can enjoy universal freedom, or Man cannot. If it is possible then everyone can act freely if they don't stop anyone else from doing same. If it is not possible, then conflict will arise anyway so punch those that try to stop you. In conclusion the only strategy that wins in all cases is that of doing what you want against all adversity, as long as you respect that right in others.
BloodDoll Lulu
FIX Inventory Issues 1st
Join date: 9 Jul 2005
Posts: 152
09-01-2005 11:04
hey thanks. I thought I knew where, wasn't sure. I just build, but I am trying to learn.
Corporal Candour
Registered User
Join date: 3 Sep 2005
Posts: 38
09-04-2005 05:35
Is it possible to make the sound loop while you're inside of it?
Aylah Hope
Registered User
Join date: 6 Dec 2004
Posts: 133
How would it look like if...
02-17-2006 04:25
From: Jesrad Seraph
Random play of sounds at various times:
CODE

default
{
state_entry()
{
llSetTimerEvent(30.0);
}

timer()
{
integer n = llGetInventoryNumber(INVENTORY_SOUND);
llTriggerSound(llGetInventoryName(INVENTORY_SOUND, llFloor(llFrand(n))));
llSetTimerEvent(20.0 + llFrand(20.0));
}
}


Continuous playing of a sound when touched (touch again to turn off):
CODE

integer is_active = FALSE;

default
{
touch_start(integer c)
{
if (llDetectedKey(0) != llGetOwner()) return;
if (is_active) { is_active = FALSE; llStopSound(); } else
{ is_active = TRUE; llLoopSound(llGetInventoryName(INVENTORY_SOUND, 0), 1.0); }
}
}


And how would this code look like if not only the owner could touch, but anyone?
Very curious, thanks for an answer :D
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
02-17-2006 05:10
Just remove the line "if (llDetectedKey(0) != llGetOwner()) return;"
Aylah Hope
Registered User
Join date: 6 Dec 2004
Posts: 133
02-17-2006 05:23
Thanks alot:D