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
Animation Multi-pose script  

Multi-pose script

This script offers five different methods for animating an avatar seated on an object that contains more than one animation

Category: Animation
By : Aine Caoimhe (aka Mata Hari)
Created: 2014-02-20 Edited: 2014-02-20
Worlds: Second Life

the Zip file

Download all files for Multi-pose script
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Script.lsl
1 // :SOURCE: http://forums.osgrid.org/viewtopic.php?f=5&t=4989
2
3 //This script offers five different methods for animating an avatar seated on an object
4 // that contains more than one animatio
5
6 // Paramour Multi-Method Multi-Animation Script
7 // by Aine Caolmhe (aka Mata Hari) - visit me by hypergrid at: aine.x64.me:9000:Paramour
8 // This script is full perm and can be altered, adjusted or changed any way you like
9 // (though I'd appreciate credit for having written the original)
10 //
11 // WHAT IT DOES
12 // This script offers five different methods for animating an avatar seated on an object
13 // that contains more than one animation (a far simpler script can be used if there's only 1)
14 // Assumes that all animations placed in the object play correctly using the SAME sit target
15 // If you use the dialog method (to pick which animation you want to play) it will only
16 // display the first 12 animations found in inventory.
17 //
18 // HOW TO USE IT
19 // Place this in any prim (root prim of a linkset) and set the user variables according to
20 // your requirements. You will also need to place at least one animation in the same prim.
21 // You can add or remove animations at any time (even during use) and the animation list will be updated
22 // automatically. The script will automatically reset itself in most (all?) situations that would require it.
23 //
24 // USER VARIABLES
25 // set the following to suit your needs
26 string floatyText=""; // if you want floating text to appear above your object, enter it here
27 vector floatyColour=<0.0,0.0,0.0>; // colour of the text -- black = <0,0,0>, white = <1,1,1>
28 float floatyAlpha=1.0; // transparency of the text -- 0.0 = invisible, 1.0 = opaque
29 vector sitPos=<0.0,0.0,0.0001>; // sit target position and rotation to use -- I suggest using the Magic
30 rotation sitRot=ZERO_ROTATION; // Sit Kit to determine the best position and rotation for your sit target
31 // Note: Sit target position cannot be <0,0,0>
32 // Uncomment one of the following five lines to choose your animation method:
33 string animMethod="SEQUENCE_TIMED"; // each animation will be played in sequence, cycling back to the first upon reaching the end
34 // string animMethod="RANDOM_TIMED"; // as above, except the order of animations is randomly shuffled
35 // string animMethod="SEQUENCE_TOUCH"; // each animation will be played in sequence, but only advances when the seated person touches the object
36 // string animMethod="RANDOM_TOUCH"; // as above, in random order
37 // string animMethod="DIALOG_SELECT"; // upon sitting the avatar will be asked to pick the animation they wish to play. Once seated, touching
38 // the object will display the dialog again, allowing you to pick a different animation. Maximum of 12 animations.
39 float animTimer=45.0; // if using either of the two TIMED methods, how long (in seconds) to wait before advancing to the next animation
40 // this is ignored if you are using one of the other 3 methods
41
42 // # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
43 // # DO NOT CHANGE ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING #
44 // # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
45 string currentAnim;
46 list anList;
47 integer anQty;
48 key mySitter=NULL_KEY;
49 integer handle;
50 integer myChannel;
51 float diaWait=60;
52 integer diaFirst=TRUE;
53
54 buildAnimList()
55 {
57 if(!anQty)
58 {
59 llOwnerSay("Unable to find any animations in inventory");
60 return;
61 }
62 anList=[];
63 integer i;
64 while(i<anQty)
65 {
67 i++;
68 }
69 if(llGetSubString(animMethod,0,5)=="RANDOM") anList=llListRandomize(anList,1);
70 if(mySitter==NULL_KEY) currentAnim=llList2String(anList,0);
71 }
72 startAnim()
73 {
74 llStartAnimation(currentAnim);
75 key dontStop=llGetInventoryKey(currentAnim);
76 list anToStop=llGetAnimationList(mySitter);
77 integer indexToStop=llGetListLength(anToStop);
78 while(--indexToStop>-1)
79 {
80 if(llList2Key(anToStop,indexToStop)!=dontStop) llStopAnimation(llList2Key(anToStop,indexToStop));
81 }
82 if(llSubStringIndex(animMethod,"TIMED")>-1) llSetTimerEvent(animTimer);
83 }
84 nextAnim()
85 {
86 integer curInd=llListFindList(anList,[currentAnim]);
87 if(curInd==-1) // either no animations or current was deleted
88 {
89 if(!anQty) return; // just keep playing current if there are no animations at all
90 else curInd=anQty--; // set to last so it rolls over
91 }
92 if(++curInd==anQty)
93 {
94 curInd=0;
95 if(llSubStringIndex(animMethod,"RANDOM")>-1) anList=llListRandomize(anList,1);
96 }
97 string nextAnim=llList2String(anList,curInd);
98 if(nextAnim!=currentAnim)
99 {
100 llStartAnimation(nextAnim);
101 llStopAnimation(currentAnim);
102 }
103 currentAnim=nextAnim;
104 }
105 getAnim()
106 {
107 // uses numbered buttons and a txt list in the dialogue since animation names usually don't fit on buttons
108 // and could also result in error if they exceed maximum button text length limit
109 list butR1;
110 list butR2;
111 list butR3;
112 list butR4;
113 list butDia;
114 integer i;
115 string txtDia="Please select the animation you would like to play:\n\n";
116 while(i<anQty)
117 {
118 if(i<3) butR1+=(string)(i+1);
119 else if(i<6) butR2+=(string)(i+1);
120 else if(i<9) butR3+=(string)(i+1);
121 else butR4+=(string)(i+1);
122 txtDia+=(string)(i+1)+". "+llList2String(anList,i)+"\n";
123 i++;
124 }
125 while(i<12)
126 {
127 if(i<3) butR1+=["-"];
128 else if(i==3) i=12;
129 else if(i<6) butR2+=["-"];
130 else if(i==6) i=12;
131 else if(i<9) butR3+=["-"];
132 else if(i==9) i=12;
133 else butR4+=["-"];
134 i++;
135 }
136 butDia=butR4+butR3+butR2+butR1;
137 handle=llListen(myChannel,"",mySitter,"");
138 llDialog(mySitter,txtDia,butDia,myChannel);
139 llSetTimerEvent(diaWait);
140 }
141 shutDown()
142 {
143 llSetTimerEvent(0.0);
144 llStartAnimation("stand");
145 llStopAnimation(currentAnim);
146 mySitter=NULL_KEY;
147 diaFirst=TRUE;
148 if(handle) llListenRemove(handle);
149 if(llGetSubString(animMethod,0,5)=="RANDOM") anList=llListRandomize(anList,1);
150 }
151 default
152 {
154 {
155 llSetText(floatyText,floatyColour,floatyAlpha);
156 if(sitPos==ZERO_VECTOR) sitPos=<0.0,0.0,0.00001>;
157 llSitTarget(sitPos,sitRot);
158 myChannel=(integer)("0x"+llGetSubString((string)llGetKey(),-8,-1)); // set unique channel based on key
159 buildAnimList();
160 }
161 on_rez(integer nullInt)
162 {
164 }
165 touch_end(integer num_detected)
166 {
167 if(mySitter==NULL_KEY) return; // ignore if no sitter
168 if(llDetectedKey(0)!=mySitter) return; // ignore if not current sitter
169 if(llSubStringIndex(animMethod,"TIMED")>-1) return; // ignore if using timed method
170 if(animMethod=="DIALOG_SELECT") getAnim();
171 else nextAnim();
172 }
173 timer()
174 {
175 if(llSubStringIndex(animMethod,"TIMED")>-1)
176 {
177 if(llAvatarOnSitTarget() ==NULL_KEY) shutDown(); // make sure there is actually an avatar there
178 else nextAnim();
179 }
180 else if(animMethod=="DIALOG_SELECT")
181 {
182 llRegionSayTo(mySitter,0,"Sorry, I did not hear your response to the dialog asking for your next animation. Please touch me to try again.");
183 llSetTimerEvent(0.0);
184 llListenRemove(handle);
185 }
186 else llResetScript(); // shouldn't be possible anyway
187 }
188 changed (integer change)
189 {
190 if(change & CHANGED_INVENTORY)
191 {
192 if(llGetInventoryNumber(INVENTORY_ANIMATION)!=anQty) buildAnimList();
193 return;
194 }
195 if(change & CHANGED_LINK)
196 {
197 key sitterKey=llAvatarOnSitTarget();
198 if(mySitter==NULL_KEY && sitterKey!=NULL_KEY) // someone sitting down
199 {
200 mySitter=sitterKey;
202 }
203 else if(mySitter!=NULL_KEY && sitterKey==NULL_KEY) shutDown(); // someone standing up
204 else if(mySitter!=NULL_KEY && sitterKey!=mySitter) // someone sitting but object already occupied by someone else
205 {
206 llUnSit(sitterKey);
207 llRegionSayTo(sitterKey,0,"Sorry, someone else is already sitting here");
208 }
209 return;
210 }
211 if(change & CHANGED_REGION_START) llResetScript();
212 if(change & CHANGED_OWNER) llResetScript();
213 }
215 {
217 {
218 if(animMethod=="DIALOG_SELECT") getAnim();
219 else startAnim();
220 }
221 }
222 listen(integer channel, string name, key id, string message)
223 {
224 llListenRemove(handle);
225 llSetTimerEvent(0.0);
226 string nextAnim=llList2String(anList,((integer)message) - 1);
227 if(diaFirst)
228 {
229 diaFirst=FALSE;
230 currentAnim=nextAnim;
231 startAnim();
232 }
233 else if(nextAnim!=currentAnim)
234 {
235 llStartAnimation(nextAnim);
236 llStopAnimation(currentAnim);
237 currentAnim=nextAnim;
238 }
239 }
240 }

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