-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnPose Facial-Layering Plugin.lsl
312 lines (297 loc) · 14.8 KB
/
nPose Facial-Layering Plugin.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
/*
The nPose scripts are licensed under the GPLv2 (http://www.gnu.org/licenses/gpl-2.0.txt), with the following addendum:
The nPose scripts are free to be copied, modified, and redistributed, subject to the following conditions:
- If you distribute the nPose scripts, you must leave them full perms.
- If you modify the nPose scripts and distribute the modifications, you must also make your modifications full perms.
"Full perms" means having the modify, copy, and transfer permissions enabled in Second Life and/or other virtual world platforms derived from Second Life (such as OpenSim). If the platform should allow more fine-grained permissions, then "full perms" will mean the most permissive possible set of permissions allowed by the platform.
*/
integer LAYER_POSE = -218;
list AnimsList; //[string command, string animation name] use a list to layer multiple animations.
list Lastanim;
integer Primcount;
integer Newprimcount;
list Faceanims;
integer GotFaceAnim = 0;
integer Seatcount;
integer OPTIONS = -240;
integer SEAT_UPDATE = 251;
integer MENU_USAGE = 34334;
list FaceTimes = [];
list Slots;
key ThisAV;
integer Stop;
integer FACIALS_FLAG = -241;
integer FacialEnable = 1;
list SeatedAvs() {
list avs = [];
integer n;
for(n = llGetNumberOfPrims(); n >= llGetObjectPrimCount(llGetKey()); --n) {
key id = llGetLinkKey(n);
if(llGetAgentSize(id) != ZERO_VECTOR) {
avs = [id] + avs;
}
}
return avs;
}
doSeats(integer slotNum, key avKey) {
llSetTimerEvent(0.0);
if(avKey != "") {
Stop = llGetListLength(Slots)/8;
llRequestPermissions(avKey, PERMISSION_TRIGGER_ANIMATION);
}
}
integer AvLinkNum(key av) {
integer linkcount = llGetNumberOfPrims();
while(av != llGetLinkKey(linkcount)) {
if(llGetAgentSize(llGetLinkKey(linkcount)) == ZERO_VECTOR) {
return -1;
}
linkcount--;
}
return linkcount;
}
default {
state_entry() {
Primcount = llGetNumberOfPrims();
Newprimcount = Primcount;
}
link_message(integer sender, integer num, string str, key id) {
if(num == LAYER_POSE) {
key av;
list tempList = llParseString2List(str, ["/"], []);
if(llListFindList(SeatedAvs(), [(key)llList2String(tempList, 0)]) != -1) {
av = (key)llList2String(tempList, 0);
}
if(av) {
llRequestPermissions(av, PERMISSION_TRIGGER_ANIMATION);
av = llGetPermissionsKey();
list tempList1 = llParseString2List(llList2String(tempList, 1), ["~"], []);
integer instruction;
integer layerStop = llGetListLength(tempList1);
for(instruction = 0; instruction < layerStop; ++instruction) {
tempList = llParseString2List(llList2String(tempList1, instruction), [","],[]);
if(llList2String(tempList,0)=="stopAll") {
AnimsList = [av, llList2String(tempList, 0), llList2String(tempList, 1)] + AnimsList;
}
else {
integer index = llListFindList(AnimsList, [llList2String(tempList, 1)]);
if(index>=1 & (key)llList2String(AnimsList, index - 2) == av) {
AnimsList = llDeleteSubList(AnimsList, index-2, index);
}
AnimsList += [av, llList2String(tempList, 0), llList2String(tempList, 1)];
}
}
integer n;
layerStop = llGetListLength(AnimsList)/3;
for(n=0; n<layerStop; ++n) {
if((key)llList2String(AnimsList, n*3) == av) {
if(llList2String(AnimsList, n*3+1) == "stopAll") {
AnimsList = llDeleteSubList(AnimsList, n*3, n*3+2);
n-=1;
layerStop-=1;
integer x;
integer animsStop = llGetListLength(AnimsList)/3;
if(animsStop > 0) {
for(x = 0; x<animsStop; ++x) {
if ((key)llList2String(AnimsList, x*3) == av && llList2String(AnimsList, x*3+2) != ""){
llStopAnimation(llList2String(AnimsList, x*3+2));
AnimsList = llDeleteSubList(AnimsList, x*3, x*3+2);
x-=1;
animsStop-=1;
}
}
}
}
else if(llList2String(AnimsList, n*3+1) == "start" && llList2String(AnimsList, n*3) == av
&& llList2String(AnimsList, n*3+2) != "") {
if(llGetPermissions() & PERMISSION_TRIGGER_ANIMATION) {
llStartAnimation(llList2String(AnimsList, n*3+2));
}
}
else if(llList2String(AnimsList, n*3+1) == "stop") {
if (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION){
llStopAnimation(llList2String(AnimsList, n*3+2));
AnimsList = llDeleteSubList(AnimsList, n*3, n*3+2);
n-=1;
layerStop-=1;
}
}
}
}
}
// llSay(0, "anim list:\n" + llList2CSV(llGetAnimationList(av)));
}
else if(num == SEAT_UPDATE){
Slots = [];
list slotsList=llParseStringKeepNulls(str, ["^"], []);
str="";
integer slotsStride=(integer)llList2String(slotsList, 0);
integer preambleLength=(integer)llList2String(slotsList, 1);
slotsList=llDeleteSubList(slotsList, 0, preambleLength-1);
integer stop = llGetListLength(slotsList)/8;
FaceTimes = [];
GotFaceAnim = 0;
for(Seatcount = 1; Seatcount <= stop; ++Seatcount) {
Slots = Slots + [llList2String(slotsList, (Seatcount-1)*slotsStride+2), (vector)llList2String(slotsList, (Seatcount-1)*slotsStride+3),
(rotation)llList2String(slotsList, (Seatcount-1)*slotsStride+4), llList2String(slotsList, (Seatcount-1)*slotsStride+5),
(key)llList2String(slotsList, (Seatcount-1)*slotsStride+8), llList2String(slotsList, (Seatcount-1)*slotsStride+5),
llList2String(slotsList, (Seatcount-1)*slotsStride+6), llList2String(slotsList, (Seatcount-1)*slotsStride+7)];
if(llList2String(slotsList, (Seatcount-1)*slotsStride+3) != "") {
//we need a list consisting of sitter key followed by each face anim and the associated time of each
//put face anims for this slot in a list
list faceanimsTemp = llParseString2List(llList2String(slotsList, (Seatcount-1)*slotsStride+3), ["~"], []);
integer facecount = llGetListLength(faceanimsTemp);
list faces = [];
integer nFace;
integer hasNewFaceTime = 0;
for(nFace=0; nFace<facecount; ++nFace) {
//parse this face anim for anim name and time
list temp = llParseString2List(llList2String(faceanimsTemp, nFace), ["="], []);
//time must be optional so we will make default a zero
//queue on zero to revert to older stuff
if(llList2String(temp, 1)) {
//collect the name of the anim and the time
faces += [llList2String(temp, 0), (integer)llList2String(temp, 1)];
hasNewFaceTime = 1;
}
else {
faces += [llList2String(temp, 0), -1];
}
}
GotFaceAnim=1;
//add sitter key and flag if timer defined followed by a stride 2 list containing face anim name and associated time
FaceTimes += [(key)llList2String(slotsList, (Seatcount-1)*8+4), hasNewFaceTime, facecount] + faces;
}
}
//we have our new list of AV's and positions so put them where they belong. fire off the first seated AV and run time will do the rest.
for(Seatcount = 0; Seatcount < stop; ++Seatcount) {
if(llList2Key(Slots, Seatcount*8+4) != "") {
if(llListFindList(SeatedAvs(), [llList2Key(Slots, Seatcount*8+4)]) != -1) {
doSeats(Seatcount, llList2String(Slots, (Seatcount)*8+4));
return;
}
}
}
}
else if(num == OPTIONS) {
//save new option(s) from LINKMSG
list optionsToSet = llParseStringKeepNulls(str, ["~","|"], []);
integer length = llGetListLength(optionsToSet);
integer index;
for(index=0; index<length; ++index) {
list optionsItems = llParseString2List(llList2String(optionsToSet, index), ["="], []);
string optionItem = llToLower(llStringTrim(llList2String(optionsItems, 0), STRING_TRIM));
string optionString = llList2String(optionsItems, 1);
string optionSetting = llToLower(llStringTrim(optionString, STRING_TRIM));
integer optionSettingFlag = optionSetting=="on" || (integer)optionSetting;
if(optionItem == "facialexp") {
FacialEnable = optionSettingFlag;
}
}
}
}
run_time_permissions(integer perm) {
ThisAV = llGetPermissionsKey();
//start timer if we have face anims for any slot
if(GotFaceAnim==1) {
llSetTimerEvent(1.0);
}
else {
llSetTimerEvent(0.0);
}
}
timer() {
integer n;
integer SlotStop = llGetListLength(Slots)/8;
key av;
integer facecount;
integer faceindex;
if(FacialEnable) {
for(n=0; n<SlotStop; ++n) {
//doing each seat
av = (key)llList2String(Slots, n*8+4);
faceindex = 0;
//locate our stride in FaceTimes list
integer keyHasFacial = llListFindList(FaceTimes, [av]);
//get number of face anims for this seat
integer newFaceTimeFlag = llList2Integer(FaceTimes, keyHasFacial+1);
if(newFaceTimeFlag == 0) {
//need to know if someone seated in this seat, if not we won't do any facials
if(av != "") {
Faceanims = llParseString2List(llList2String(Slots, n*8+3), ["~"], []);
facecount = llGetListLength(Faceanims);
if(facecount > 0 && (llListFindList(SeatedAvs(), [ThisAV]) != -1)) {//modified cause face anims were being imposed after AV stands.
ThisAV = llGetPermissionsKey();
llRequestPermissions(av, PERMISSION_TRIGGER_ANIMATION);
}
}
integer x;
for(x=0; x<facecount; ++x){
if (facecount>0) {
if(faceindex < facecount) {
if(AvLinkNum(av) != -1) {
llStartAnimation(llList2String(Faceanims, faceindex));
}
}
faceindex++;
}
}
}
else if(av != ""){
//need to know if someone seated in this seat, if not we won't do any facials
//do our stuff with defined facial times
facecount = llList2Integer(FaceTimes, keyHasFacial+2);
//if we have facial anims make sure we have permissions for this av
if((facecount > 0) && (llListFindList(SeatedAvs(), [ThisAV]) != -1)) { //modified cause face anims were being imposed after AV stands.
ThisAV = llGetPermissionsKey();
llRequestPermissions(av, PERMISSION_TRIGGER_ANIMATION);
}
integer x;
for(x=1; x<=facecount; ++x) {
//non looping we check if anim has run long enough
if(faceindex < facecount) {
integer faceStride = keyHasFacial+1+(x*2);
string animName = llList2String(FaceTimes, faceStride);
if(llList2Integer(FaceTimes, faceStride+1) > 0) {
FaceTimes = llListReplaceList(FaceTimes, [llList2Integer(FaceTimes, faceStride+1)-1],
faceStride+1, faceStride+1);
}
if(facecount>0) {
if(AvLinkNum(av) != -1 && llList2Integer(FaceTimes, faceStride+1) > 0) {
llStartAnimation(animName);
}
else if(AvLinkNum(av) != -1 && llList2Integer(FaceTimes, faceStride+1) == -1) {
llStartAnimation(animName);
}
faceindex++;
}
}
}
}
}
if(llGetListLength(SeatedAvs())<1) {
llSetTimerEvent(0.0);
}
}
}
changed(integer change) {
if(change & CHANGED_LINK) {
integer newPrimCount1 = llGetNumberOfPrims();
if(Newprimcount>newPrimCount1) {
//we have lost a sitter so find out who and remove them from the list.
integer n;
integer LaStop = llGetListLength(Lastanim)/2;
for(n=0; n<LaStop; ++n) {
if(AvLinkNum((key)llList2String(Lastanim, n*2)) == -1) {
integer index = llListFindList(AnimsList, [(key)llList2String(Lastanim, n*2)]);
if(index != -1) {
AnimsList = llDeleteSubList(AnimsList, index, index + 2);
}
Lastanim = llDeleteSubList(Lastanim, n*2, n*2+1);
}
}
}
Newprimcount = newPrimCount1;
}
}
}