Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Av touch

Poon Pan
Registered User
Join date: 2 Aug 2006
Posts: 11
08-06-2006 17:23
I was wondering if there is a basic script that would make a box play a sound, only when a collision is made with an avatar, and not land or object collisions.
Lexi Foley
Registered User
Join date: 1 Mar 2006
Posts: 43
08-06-2006 18:02
i think you can try it whit llSensor or llSensorRepeat

collision......
{
llSensor("","",AGENT,3,PI);
or
llSensorRepeat("","",AGENT,3,PI,0.1);
}

sensor()

if(llDetectedKey(0)!=NULL_KEY)
{
llPlaySound
}

i think this will work,,,
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
08-06-2006 18:58
You don't need to do it that way, and shouldn't!

Firing off sensors when they're not essential is a bad idea, they're heavy on the sim. You're also using the sensor event with an extra if statement, there's a no_sensor for no returns.

Anyway try something like:
CODE

default
{
collision_start(integer num)
{
integer i=0;
while(i<num)
{
if(llDetectedType(i) & AGENT) llPlaySound() // put your sound call in here
i++;
}
}
}
_____________________
Eloise's MiniMall
Visit Eloise's Minimall
New, smaller footprint, same great materials.

Check out the new blog
Gearsawe Stonecutter
Over there
Join date: 14 Sep 2005
Posts: 614
08-07-2006 09:24
You probably don't even need the 'for loop' for the DetectedType with a collision_start or collision_end. Now with a collision only you would. More than likely you only need DectedType(0). But certainly you don't need the sensors.
Catherine Omega
Geometry Ninja
Join date: 10 Jan 2003
Posts: 2,053
08-07-2006 13:13
From: Gearsawe Stonecutter
You probably don't even need the 'for loop' for the DetectedType with a collision_start or collision_end. Now with a collision only you would. More than likely you only need DectedType(0). But certainly you don't need the sensors.
Personally, I'd do it exactly as Eloise has written it. The FOR loop is not totally necessary, it's true... however, there's very little extra load, and multiple collision_start triggers have been known to happen. As to whether or not they're possible right now, that's another matter. If not, they may at least be possible again in the future. LSL's tricky that way.
_____________________
Need scripting help? Visit the LSL Wiki!
Omega Point - Catherine Omega's Blog
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
08-07-2006 15:37
I tend to put the for loops in those sorts of things on autopilot. Multiple collision_starts are unlikely granted, but the number of auto givers for notecards that don't do it, then you get dozens of avies swearing and clicking again and again because it will only give to one person at a time, and people get 5 and ... well you get the idea.

It's very little extra load if it's only one person, it makes it easy to play random sounds with each hit in this case as the script evolves, if it goes that way, or not play sounds when the owner gets home or whatever, 100% reliably.
_____________________
Eloise's MiniMall
Visit Eloise's Minimall
New, smaller footprint, same great materials.

Check out the new blog
Poon Pan
Registered User
Join date: 2 Aug 2006
Posts: 11
08-07-2006 16:07
I didn't want the looping, i think its perfect, Thanks.
Escort DeFarge
Together
Join date: 18 Nov 2004
Posts: 681
08-07-2006 17:47
From: Poon Pan
I didn't want the looping, i think its perfect, Thanks.

Sure you don't need it for just you, but oh but you will want it when you have a high load situation and people say your stuff "doesn't work"... Eloise is right and it's good practice.
_____________________
http://slurl.com/secondlife/Together
Norman Desmoulins
Grand Poohba
Join date: 10 Nov 2005
Posts: 194
08-07-2006 17:55
From: Escort DeFarge
Sure you don't need it for just you, but oh but you will want it when you have a high load situation and people say your stuff "doesn't work"... Eloise is right and it's good practice.


That makes no sense... a high load situation would be like 5 people running into it at once, and with the loop the script will play the sound 5 times... without the loop the script will play the sound once (more appropriate, less spamming, etc).
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
08-07-2006 23:48
Remember too that only for (currently present) avatars is:
llGetOwnerKey(id) == id

true.
Bitzer Balderdash
Dazed and Confused
Join date: 21 Dec 2005
Posts: 246
08-08-2006 06:34
From: Norman Desmoulins
That makes no sense... a high load situation would be like 5 people running into it at once, and with the loop the script will play the sound 5 times... without the loop the script will play the sound once (more appropriate, less spamming, etc).


Unless the first one is an object or the ground, in which case the other four, the agents, all get ignored.
Azurei Ash
The Sticky!
Join date: 12 Jan 2006
Posts: 38
08-08-2006 10:22
Not necessary under fair conditions, but it may indeed be better practice to use Eloise's script.

If you want to ensure that the sound is only played once per collision_start event, even when multiple agents collide with it, try this:

CODE

default
{
collision_start(integer num)
{
integer i=0;
while(i<num)
{
if(llDetectedType(i) & AGENT)
{
llPlaySound(); // put your sound call in here
return;
}
i++;
}
}
}


That should cause it to return (exit) from the event immediately after playing the sound the first time.

The danger I think the others are referring to is that in high load situations it is more likely to have more than one collision get grouped into this event due to slower processing. Then if the first one it lists happens to be the ground or an object, you don't detect others which may possibly be agents unless you loop.

~Az