-
Notifications
You must be signed in to change notification settings - Fork 10
/
quietfountain.lsl
46 lines (40 loc) · 1.76 KB
/
quietfountain.lsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//
// quietfountain.lsl -- fountain sound controller
//
// Turns down sound if there is an avatar very close.
//
#define SOUND "fountainsound"
#define VOLHI 0.40 // loud sound, with nobody nearby
#define VOLLO 0.10 // soft sound, with someone nearby
#define RANGE 15.0 // someone this close
#define TIMEINTERVAL (20) // check every 20 seconds
float gVolume = VOLHI; // current audio volume
default
{
state_entry()
{ llStopSound();
llLoopSound(SOUND,gVolume);
llSetTimerEvent(TIMEINTERVAL); // long timer
}
timer()
{
list agents = llGetAgentList(AGENT_LIST_PARCEL_OWNER,[]); // get agents in parcel
integer length = llGetListLength(agents);
integer i;
float volume = VOLHI; // assume nobody around
for (i=0; i<length; i++) // for all agents in parcel
{ ////llOwnerSay("Agent: " + llKey2Name(llList2Key(agents,i))); // ***TEMP***
vector apos = llList2Vector(llGetObjectDetails(llList2Key(agents,i), [OBJECT_POS]),0); // get
if (llVecMag(apos-llGetPos()) <= RANGE) // if within range
{ volume = VOLLO; // turn down volume
}
}
if (volume != gVolume) // if volume changed
{ gVolume = volume;
llStopSound();
llLoopSound(SOUND, gVolume); // change volume
}
}
on_rez(integer rezarg)
{ llResetScript(); }
}