Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Music HUD_Music_player_with_trigger  

HUD_Music_player_with_trigger

The Sensor Script - put this script and your 10 second wav file clips into a prim. Anyone approaching this prim will trigger the music to play for just that avatar./ The avatar must wear a headset or HUD prim with the player script.

Category: Music
By : Ferd Frederix
Created: 2012-10-09 Edited: 2012-10-09
Worlds: Second Life

the Zip file

Download all files for HUD_Music_player_with_trigger
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. HUD_Music_player_with_trigger_1.lsl
Get file # 2. HUD_Music_player_with_trigger_2.lsl

This script by Ferd Frederix may be used in any manner, modified, and republished.  Unless specified otherwise, my scripts are always free and open source.  Objects made with these scripts may be sold with no restrictions.  All I ask is that you point others to this location should they ask you about it and to not sell this script, unless it is for $0 L. Please help improve my work by reporting bugs and improvements.

1 // general purpose avatar sensor for the music playert
2 // When someone gets in range, this starts the music sequence
3 // if used in HUD mode, only the avatar wearing the HUD and also in range of some location can hear the sounds/music.
4 // When used in PRIM mode, anyone standing near will trigger the sound.
5
6 // 10-09-2012 by Ferd Frederix
7
8 // This work is licensed under a Creative Commons Attribution-NonCommercial 3.0 Unported License.
9 // http://creativecommons.org/licenses/by-nc/3.0/deed.en_US
10 // This script cannot be sold even as part of another object, it must always remain free and fully modifiable.
11
12
13
14 // Tuneable thing:
15 float range = 5.0; // how far a avatar has to be before sound plays, in meters
16 float howoften = 5.0; // how often we look for avatars. Average time before it detects is half this.
17 // The longer you make this, the less lag it causes.
18
19 // for a HUD, put the player in the HUD and put the sensor somewhere in-world to trigger the HUD
20
21 // best to leave these bits alone
22 integer secret_channel = 9876; // just a magic number
23 list playingKeys; // a list of all avatars that have been controlled
24 list sensedKeys; // a list of avatars within range.
25 integer debugflag = FALSE; // set to true to see it as it works
26
27 DEBUG (string msg)
28 {
29 if(debugflag) llOwnerSay(msg);
30 }
31
32 // send a list of UUIDs to a player
33 Send(key id)
34 {
35 integer i;
37 llSay(secret_channel,(string) id + "^" + "stop" + "^" );
38 for (i = 0; i < j; i++) {
40 key soundKey = llGetInventoryKey(name); // get key of named sound
41 llSay(secret_channel,(string) id + "^" + "queue" + "^" + (string) soundKey + "^" + name + "^");
42 }
43 llSay(secret_channel,(string) id + "^" + "play" + "^" );
44 }
45
46 default
47 {
49 {
50 llSensorRepeat("","",AGENT,range, PI, howoften);
51 }
52
53 sensor(integer total_number)
54 {
55
56 integer i;
57 sensedKeys = [];
58 for (i = 0; i < total_number; i++)
59 {
60 key id = llDetectedKey(i); // get every avatars key that is near us
61 if(llListFindList(playingKeys,[id]) == -1) // if not in the list of HUD's that are playing ...
62 {
63 playingKeys += id; // add them to the playing list
64 Send(id);
65 }
66 sensedKeys += id; // add them to the current list of nearby listeners
67 }
68
69 // now check to see if anyone has left the vicinity and issue a stop command to them
70 i = 0;
71 while(i < llGetListLength(playingKeys))
72 {
73 DEBUG("i=" + (string) i);
74 key id = llList2Key(playingKeys,i);
75 if(llListFindList(sensedKeys,[id]) == -1) // if not in sensed, stop them
76 {
77 llSay(secret_channel,(string) id + "^" + "stop");
78 playingKeys = llDeleteSubList(playingKeys,i,i); // remove this person, no longer playing
79 } else {
80 DEBUG((string) id + " is nearby");
81 i++; // look at next person, as this one was still nearby
82 }
83 }
84 }
85
86 no_sensor()
87 {
88 integer i;
89 integer j = llGetListLength(playingKeys);
90 for (i = 0; i < j; i++)
91 {
92 key id = llList2Key(playingKeys,i);
93 llShout(secret_channel,(string) id + "^" + "stop");
94 }
95 playingKeys = [];
96
97 }
98
100 {
102 }
103 }

HUD_Music_player_with_trigger

Player Script. Put this in a HUD or other worn item. If worn as a HUD, only the player wearing the HUD can hear it. This is just like a museum player.

Category: Music
By : Ferd Frederix
Created: 2012-10-09 Edited: 2012-10-09
Worlds: Second Life


This script by Ferd Frederix may be used in any manner, modified, and republished.  Unless specified otherwise, my scripts are always free and open source.  Objects made with these scripts may be sold with no restrictions.  All I ask is that you point others to this location should they ask you about it and to not sell this script, unless it is for $0 L. Please help improve my work by reporting bugs and improvements.

1 // suitable for museum-like headphone action. Where you stand in front of something and it talks to you until you move away.
2
3 // 10/9/2012
4 // This work is licensed under a Creative Commons Attribution-NonCommercial 3.0 Unported License.
5 // http://creativecommons.org/licenses/by-nc/3.0/deed.en_US
6 // This script cannot be sold even as part of another object, it must always remain free and fully modifiable.
7
8 // This script goes into a prim worn as a HUD.
9 // Drop 10 second song clips in the inventory of the Sensor object, not the HUD.
10 // A great free tool to make these files is the slice audio file splitter at http://www.nch.com.au/splitter
11 //
12 // Set the variable loop = TRUE to loop over and over after reaching the end, set it to FALSE to play once.
13 // Requires another trigger prim in world with the Sensor script in it.
14
15 integer loop = FALSE; // set to TRUE to loop again and again
16 float set_text_alpha = 1; // the text transparency fo alpha text. Set this to 0 to disable hovertext
17 integer debugflag = FALSE; // chat debug info to owner if TRUE
18
19 // Suff that you should not mess with.
20
21 integer waves_to_preload = 3; // wave files to Preload ahead of the wav being played.
22 float preload_load_time = 0.5; // seconds pause between each preloaded wave file attempt b4 play comnences
23 integer secret_channel = 9876; // just a magic number
24 vector set_text_colour = <1,1,1>; // colour of floating text label ( white)
25 list soundQueue; // a list of sound UUIDs from the sensor
26 list nameQueue; // a list of sound names from the sensor
27 float timer_interval = 9.8; // time interval between requesting server to play the next 10 second wave
28 // times just below 10 seconds are suitable as we use sound queueing
29 integer total_wave_files; //number of wave files
30 integer i_playcounter; //used by timer() player
31
32
33 DEBUG (string msg)
34 {
35 if(debugflag) llOwnerSay(msg);
36 }
37
38
39 go(integer play) {
40
41 if(play)
42 {
43 sound();
44
45 } else {
46 llSetTimerEvent(0.0);
48 DEBUG("Stoped");
49 llSetText(llGetObjectName() + "\n.", <0,1,0>, set_text_alpha);
50 }
51 }
52
53
54
55 sound() {
56
57
58 total_wave_files = llGetListLength(soundQueue);
59 integer counter = 0; //do full preload of sound
60 llSetSoundQueueing(TRUE); // only works on llPlaySound not llTriggerSound, so we can queue these silently
61 integer local_total_wave_files = total_wave_files -1 ;
62
63 float length = total_wave_files * 10.0;
64 for (counter = 0 ; counter < waves_to_preload ; counter ++) //preload X wave files b4 we play
65 {
66 key preloading_wave_key = llList2Key(soundQueue,counter);
67 string preloading_wave_name = llList2Key(nameQueue,counter);
68
69 //Attempt to preload first x wave files to local machines cache!
70 llPreloadSound(preloading_wave_key);
71
72 DEBUG("Preloading wav: " + (string)counter + " " + preloading_wave_name);
73
74 llSleep(preload_load_time);
75 }
76
77 llSetTimerEvent(0.1);
78 i_playcounter=0;
79 counter=0;
80 }
81
82
83 default
84 {
86 {
87
88 //set text above object to the name of the object
89 llListen(secret_channel,"","","");
90 llSetText(llGetObjectName() + "\n.", <0,1,0>, set_text_alpha);
91 }
92
93 listen(integer channel, string name, key id, string message)
94 {
95 //DEBUG("Heard:" + message);
96 list msg = llParseString2List(message,["^"],[""]);
97
98 string targetid = llList2String(msg,0); // avatar key to play
99 string cmd = llList2String(msg,1); // stop, queue, or play
100 string soundKey = llList2String(msg,2); // UUID of sound file
101 string soundName = llList2String(msg,3); // UUID of sound file
102
103 if(( key) targetid == llGetOwner())
104 {
105 if(cmd =="queue") {
106 soundQueue += (key) soundKey;
107 nameQueue += soundName;
108 }
109 else if(cmd == "play")
110 {
111 go(TRUE);
112 }
113 else if(cmd == "stop")
114 {
115 soundQueue = [];
116 nameQueue = [];
117 go(FALSE);
118 }
119 }
120 }
121
122 touch_start(integer total_number)
123 {
124 go(TRUE);
125 }
126
127 timer()
128 {
129 llSetTimerEvent(timer_interval);
130 if( i_playcounter > (total_wave_files -1) )
131 {
132 if(!loop)
133 {
135 }
136 else
137 {
138 sound();
139 }
140
141 } else {
142 key playing_wave_key = llList2Key(soundQueue, i_playcounter);
143 string playing_wave_name = llList2String(nameQueue, i_playcounter);
144 DEBUG("llPlaySound wav: " + (string)i_playcounter + " " + (string)playing_wave_key );
145
146 llSetText("Playing " + (string)i_playcounter + " of " + (string)(total_wave_files -1) , set_text_colour, set_text_alpha);
147
148 llPlaySound(playing_wave_key, 1.0);
149
150 key preloading_wave_key = llList2String(soundQueue, i_playcounter + waves_to_preload);
151 string preloading_wave_name = llList2String(nameQueue, i_playcounter + waves_to_preload);
152
153 DEBUG("Preloading wav:" + (string)(i_playcounter + waves_to_preload) + "\n" +
154 " key: " + (string) playing_wave_key + "\n" +
155 "Preloading sequence: " + (string)(i_playcounter + waves_to_preload));
156
157 llPreloadSound(playing_wave_key);
158 }
159 i_playcounter ++; //increment for next wave file in sequence!
160 }
161
162
163 on_rez(integer param)
164 {
166 }
167 }

Back to the Best Free Tools in Second Life and OpenSim.