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
Dance Dance_Server_System  

Dance_Server_System

Dance Srver for multiple people and dnaces

Category: Dance
By : Holy Gavenkrantz
Created: 2011-07-05 Edited: 2011-07-05
Worlds: Second Life

the Zip file

Download all files for Dance_Server_System
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Dance_Server_System_1.lsl
Get file # 2. Dance_Server_System_2.lsl
1 // I have had a lot of people asking about dance server scripts or needing help modifying scripts and they were always by or modeled after the SOLOP server script by Evil Fool. It worked well enough but seemed to be tough on SIM resources in my opinion so I made up my own based on the same idea. The problem I found was that all the scripts would fire their link_message event every time someone touched the dance prim and the more dancers there were the slower the response because each script passes the link_message on to the next script until the filter matched. This causes an onslaught of message_linked events because even though a script may not do anything with the message its event still must fire. Additionally, there were the scanners to detect if the avatar was still around. Add to that again any menus or other features people were requesting to be added to the scripts.// // In my example below all the dance scripts are set to NOT running. The only scripts running are the main server script and any dancer script associated with each avatar. There is only one 30 second timer running checking for the presence of each avatar via llGetAgentSize. The only other running timers only occur while someone has a menu open and those will stop if a selection is made or they time out. It works well for me but I haven't been able to stress test it because well, I don't have enough friends. (I've had 50 dance scripts and 250 dance animations in the server and it worked well but again I didn't have many dancers) Anyway, follow the instructions below and let me know what you think or if you see ways of improving it.// // To Start://
2 // 1. Create a folder in your inventory - call it Dance Server or what ever you want.
3 //
4 // 2. Create a new script in this folder called "!Holy Server" ( the name isn't important but you will help my ego by leaving it this)
5 //
6 // 3. Copy and paste the script from below of the same name into this new script. Save and close it.
7 //
8 // 4. Create another script in this folder and call it "!Dancer" ( name not important again)
9 //
10 // 5. Copy and paste the script from below of the same name into this new script. Save and close it.
11 //
12 // 6. Create your prim that will hold all the animations and scripts.
13 //
14 // 7. Drag a copy of the "!Holy Server" script into the prims inventory.
15 //
16 // 8. Drag as many copies of the "!Dancer" script as you think you will need into the prims inventory. You will see the names of this script change automatically as a number is added to the script name. This is fine as well as required to identify each script later on.
17 //
18 // 9. Drag all your dance animations into the Prim.
19 //
20 // 10. If you have more than 200 animations plus dancer scripts then, while you have the edit box open, go to Tools at the top of your viewer and select Recompile Scripts in Selection > MONO. This is to prevent stack heap errors. Otherwise you should be able to recompile in LSL. If at all possible run the dance server in LSL mode - its just that much less memory used.
21 //
22 // 11. Close the edit box and touch the prim and select "Reset" from the menu when it comes up.
23 //
24 // 12. Dance!
25
26 // !Holy Server
27 // mods by DonJr SpeigelBlatt and Ferd Frederix
28 //Created Oct 2010 by Holy Gavenkrantz
29 //This work uses content from the Second Life® LSL Script library.
30 //Copyright © 2007-2009 Linden Research, Inc. Licensed under the
31 //Creative Commons Attribution-Share Alike 3.0 License
32 // Insert this script in your prim
33 // If you sell this I have hidden code in here that will delete your head
34
35 list gAvKeyList; //store all the keys and associated dance script numbers here
36 list gDanceList; //store all the dance animations in the prims inventory here
37 integer gActive = FALSE; //part of the dance script reset function
38
39 updatetext()//this keeps the users updated as to dance server status
40 {
41 llSetText(llGetObjectName() + "-" + (string)llGetListLength(gDanceList) + " Dances"
42 + "\nClick to start dancing!\nCurrently Dancing: " + (string)(llGetListLength(gAvKeyList) / 2)
44 + " possible slots.", <llFrand(1.0),llFrand(1.0),llFrand(1.0)>, 1);
45 }
46
47 reset_scripts()//this function resets all the individula dance scripts
48 {
49 llSetText(llGetObjectName() +"\nResetting Dance Scripts...", <llFrand(1.0),llFrand(1.0),llFrand(1.0)>, 1);
50 gActive = TRUE;
51 integer num = llGetInventoryNumber(INVENTORY_SCRIPT);//get the number of scripts
52 integer i;
53 while( i < num )
54 {
55 string script_name = llGetInventoryName(INVENTORY_SCRIPT, i);//store the script name temporarily
56 if( script_name != llGetScriptName() )//don't reset this script... just yet
57 {
58 llSetScriptState(script_name, TRUE);//turn on the dance script
59 llResetOtherScript(script_name);//reset it so it loads the data it needs to store ( it will shut itself back off)
60 }
61 ++i;//get the next script
62 }
63 llSleep(1); //this isn't required if you have 10 or more dance scripts
64 updatetext();
65 }
66
67 default
68 {
70 {
71 llSetText(llGetObjectName() +"\nLoading animations...", <llFrand(1.0),llFrand(1.0),llFrand(1.0)>, 1);
73 integer i;
74 while( i < num )//build the list of animations
75 {
77 ++i;
78 }
79 updatetext();
81 }
82
83 touch_start(integer total_number)
84 {
85 if( ! gActive ) //if gActive is false then reset all the scripts
86 {
87 reset_scripts();
88 }
89 integer i;
90 for (i = 0; i < total_number; ++i)
91 {
92 key current_key = llDetectedKey(i);
93 integer search = llListFindList(gAvKeyList,[current_key] ); // missing current_key
94 if( ~search ) //if the detected key is found they already have a dance script assigned
95 {
96 llMessageLinked(LINK_THIS, llList2Integer(gAvKeyList, search + 1),
97 llDumpList2String(gDanceList, ","), current_key);
98 }
99 else
100 {
101 gAvKeyList += current_key;//else add their key to the list
103 {//check to see if there are any positions left
104 //- if not remove their key from the list and let them know they must wait
105 llInstantMessage(current_key, "Sorry but there are no dance positions left");
106 gAvKeyList = llDeleteSubList(gAvKeyList, -1, -1);
107 }
108 else//there is an opening - find a non running script to assign to them
109 {
111 integer j;
112 while( j < num )
113 {
115 if( llGetScriptState(script_name) )//if the script name = this script goto the next one
116 {
117 ++j;
118 }
119 else
120 {
121 j = num;//stop the loop
122 llSetScriptState(script_name, TRUE);//start the dance script
123 integer name_search = llSubStringIndex(script_name, " ");//parse the script number from its name
124 integer script_num = (integer)llGetSubString(script_name, name_search + 1, -1);
125 gAvKeyList += script_num;//add the number to the key list
126 //send a message to the appropriate script containg the list of animation and the users key
127 llMessageLinked(LINK_THIS, script_num, llDumpList2String(gDanceList, ","), current_key);
128 }
129 }
130 }
131 }
132 }
133 }
134
135 link_message(integer sender_num, integer num, string msg, key id)
136 {
137 if( num == -5555 )//only do stuff if a message was sent to this number
138 {
139 if( msg == "cancel" )//if the message was cancel then delete the users key and script number from the key list
140 {
141 integer search = llListFindList(gAvKeyList, [id]); // missing id
142 if( ~search )
143 {
144 gAvKeyList = llDeleteSubList(gAvKeyList, search, search + 1);
145 }
146 }
147 else if( msg == "color" )//this means a dance was selected - start a timer ( explained in the timer function)
148 {
150 }
151 else if( msg == "reset" )//reset the system - only the owner as this capability
152 {
153 reset_scripts();
155 }
156 updatetext();
157 }
158 }
159
160 timer()
161 {
162 if( gAvKeyList )//as long as there is a key in the keylist keep checking that each user is still in the sim
163 {
164 integer len = llGetListLength(gAvKeyList);
165 integer i;
166 while( i < len )
167 {
168 if( llGetAgentSize(llList2Key(gAvKeyList, i)) )//if a valid size is returned then they are still here
169 {
170 i += 2;//check the next key
171 }
172 else//nope, they're gone remove them from the list and check the next key
173 {
174 llMessageLinked(LINK_THIS, llList2Integer(gAvKeyList, i + 1), "", "");
175 gAvKeyList = llDeleteSubList(gAvKeyList, i, i + 1);
176 len = llGetListLength(gAvKeyList);
177 }
178 }
179 updatetext();
180 }
181 else
182 {
183 llSetTimerEvent(0);//the key list is empty - stop checking
184 }
185 }
186
187
188 changed(integer change)
189 {
190 if( change & CHANGED_REGION_START )
191 {
192 reset_scripts();
194 }
195 }
196
197
198 on_rez(integer rez)
199 {
200 llResetScript();//gets the ball rolling
201 }
202 }

Dance_Server_System

Dancer Slave

Category: Dance
By : Holy Gavenkrantz
Created: 2011-07-05 Edited: 2011-07-05
Worlds: Second Life

1 // mods by DonJr SpeigelBlatt and Ferd Frederix
2 //This work uses content from the Second Life LSL Script library. Copyright © 2007-2009 Linden Research, Inc. Licensed under the Creative Commons Attribution-Share Alike 3.0 License
3 // !Dancer
4 //
5 //Created Oct 2010 by Holy Gavenkrantz
6 // Insert as many copies of this script in your prim that you think you will need to match the number of dancers
7 // If you sell this I have hidden code in here that will delete your head
8
9 integer gDialogCH; //channel the menu will use
10 integer gListener; //open a listen so the script will hear menu choices
11 integer gIndex = 0; //used in the menu system to track NEXT and PREV functions
12 integer gScriptNum; //store the script number taken from the script name here
13 key gAvKey; //store the avatar key here
14 list gDanceList; //store the list of dance animations here
15 string gDance; //store the current dance here
16 integer gCount_limit = 9 ; // number of menu items
17
18 menu( list button_list )//le menu
19 {
20 integer items = llGetListLength(button_list);
21 string dialog_text = "\nSelect a Dance";
22 list button;
23 integer count = 0;
24 string check_item = "foo";
25 while( check_item != "" )//compile buttons and descriptions
26 {
27 check_item = llList2String(button_list, gIndex + count);
28 if( check_item != "" )
29 {
30 if( count < gCount_limit )
31 {
32 ++ count;
33 string count_item = (string)( count + gIndex) + ".";
34 dialog_text += "\n" + count_item + " " + check_item;
35 button += (string)( count + gIndex); }
36 else
37 {
38 check_item = "";
39 }
40 }
41 }
42 integer dumb_button;//fill in the spaces with "-"
43 integer i;
44 if( count > 3 && count < 6 )
45 {
46 dumb_button = 6 - count;
47 }
48 if( count > 6 && count < 9 )
49 {
50 dumb_button = 9 - count;
51 }
52 if( count > 10 && count < 12 )
53 {
54 dumb_button = 12 - count;
55 }
56 for ( i = 0; i < dumb_button; ++ i )
57 {
58 button += "-";
59 }
60 button = llList2List(button, -3, -1) + llList2List(button, -6, -4)
61 + llList2List(button, -9, -7) + llList2List(button, -12, -10);//flip the list
62 if( gIndex + gCount_limit < items )//add the next, previous and cancel buttons
63 {
64 button = "Next >>" + button;
65 }
66 else if( gIndex + gCount_limit >= items && items > gCount_limit )//wrap back to start of list
67 {
68 button = "Start >>" + button;
69 }
70 else
71 {
72 button = "-" + button;
73 }
74 button = "Cancel" + button;
75 if( gAvKey == llGetOwner() ) button = "Reset" + button;
76 if( gIndex > 0 )
77 {
78 button = "<< Prev." + button;
79 }
80 else if( gIndex == 0 && items > gCount_limit )//wrap to the end of list
81 {
82 button = "<< End" + button;
83 }
84 else
85 {
86 button = "-" + button;
87 }
89 llListenRemove(gListener);
90 gListener = llListen(gDialogCH, "", gAvKey, "");
91 llDialog(gAvKey, dialog_text, button, gDialogCH);//send the menu
92 }
93
94 default
95 {
96 changed(integer change)
97 {//this probably isn't required because the natural operation of the script resets it anyway
98 if( change & CHANGED_OWNER )
99 {
101 }
102 }
103
105 {
106 //create a negative integer using the scripts key
107 //assign a script number using the number at teh end of the script name
108 //shut the script off
109 gDialogCH = (integer)("0x"+llGetSubString(llGetInventoryKey(llGetScriptName()),0,6)) * -1;
110 integer name_search = llSubStringIndex(llGetScriptName(), " ");
111 gScriptNum = (integer)llGetSubString(llGetScriptName(), name_search + 1, -1);
113 llSleep(.5);
114 }
115
116 link_message(integer sender_num,integer num,string str,key id)
117 {
118 if( num == gScriptNum )
119 {
120 if( id )//if id is a valid key means the main server has passed someone touch request
121 {
122 gAvKey = id;
123 gDanceList = llParseString2List(str, [","], []);//store the list of animations
124 if( gAvKey == llGetOwner() )
125 gCount_limit = 8;
126 else
127 gCount_limit = 9;
128 menu(gDanceList);
129 }
130 else
131 {
132 llResetScript();//any other message from the server requires a reset
133 }
134 }
135 }
136
137 listen(integer channel, string name, key id, string message)
138 {
139 if( channel == gDialogCH )
140 {
142 llListenRemove(gListener);
143 if( message == "Cancel" || message == "-" )
144 {
145 if( llGetPermissionsKey() )//if already dancing just close the menu
146 {
147 gIndex = 0;
148 }
149 else //avatar changed mind. clear the avatar key and reset script
150 {
151 llMessageLinked(LINK_THIS, -5555, "cancel", gAvKey);
153 }
154 }
155 else if( message == "<< Prev." )
156 {
157 gIndex -= gCount_limit;
158 menu ( gDanceList );
159 }
160 else if( message == "Next >>" )
161 {
162 gIndex += gCount_limit;
163 menu ( gDanceList );
164 }
165 else if( message == "Start >>" )
166 {
167 gIndex = 0;
168 menu ( gDanceList );
169 }
170 else if( message == "<< End" )//go to the last page
171 {
172 if( llGetListLength(gDanceList) % gCount_limit )
173 {
174 gIndex = llGetListLength(gDanceList) - (llGetListLength(gDanceList) % gCount_limit);
175 }
176 else
177 {
178 gIndex = (llGetListLength(gDanceList) - (llGetListLength(gDanceList) % gCount_limit)) - gCount_limit;
179 }
180 menu ( gDanceList );
181 }
182 else if( message == "Dance" )
183 {
184 menu ( gDanceList );
185 }
186 else if( message == "Stop" )
187 {
188 llMessageLinked(LINK_THIS, -5555, "cancel", gAvKey);//clear avatar key
189 if( llGetPermissionsKey() )//only stop the dance if they are actually dancing
190 {
191 llStopAnimation(gDance);
192 llInstantMessage(gAvKey, "Thanks for dancing " + llKey2Name(gAvKey) + ".");
193 }
195 }
196 else if( message == "Reset" )//reset everything
197 {
198 llMessageLinked(LINK_THIS, -5555, "reset", gAvKey);
200 }
201 else if( (integer)message > 0 )//dance was selected
202 {
203 string old_dance = gDance; //store the current dance
204 gDance = llList2String(gDanceList,(integer)message -1);//load the next dance
205 if( llGetPermissions() & PERMISSION_TRIGGER_ANIMATION )//if already dancing
206 {
207 llMessageLinked(LINK_THIS, -5555, "color", gAvKey);
208 llStopAnimation(old_dance);
209 llStartAnimation(gDance);
210 }
211 else //else get permission
212 {
213 llSetTimerEvent(30);//safety net in case they never accept or deny permissions
215 }
216 }
217 }
218 }
219
221 {
222 if( perms & PERMISSION_TRIGGER_ANIMATION )//have permission - start dancing
223 {
225 llMessageLinked(LINK_THIS, -5555, "color", gAvKey);
226 llStartAnimation(gDance);
227 }
228 else //cancel everything
229 {
230 llMessageLinked(LINK_THIS, -5555, "cancel", gAvKey);
232 }
233 }
234
235 timer()
236 {// if we're here something went wrong
238 llListenRemove(gListener);
239 if( llGetAgentSize(gAvKey) )//still on the sim
240 {
241 if( llGetPermissionsKey() == NULL_KEY )//they're just standing there - reset
242 {
243 llMessageLinked(LINK_THIS, -5555, "cancel", gAvKey);
244 llInstantMessage(gAvKey, "The menu has timed out.");
246 }
247 else//they're dancing - just really slow decision makers
248 {
249 llInstantMessage(gAvKey, "The menu has timed out.");
250 }
251 }
252 else//they're gone - just reset
253 {
254 llMessageLinked(LINK_THIS, -5555, "cancel", gAvKey);
256 }
257 }
258 }
259 // End Of code

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