aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/media/Test sim/objects/onefang%27s%20test%20bed.5cb927d5-1304-4f1a-9947-308251ef2df0/~poser 5.lsl
blob: fc976c42fca8cfe54562a49f4109c24d40a5d003 (plain)
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
// MPLV2 2.3 by Learjeff Innis, based on
// MLP MULTI-LOVE-POSE V1.2 - Copyright (c) 2006, by Miffy Fluffy (BSD License)
// OpenSim port by Jez Ember
// Meta 7 fixes by onefang Rejected

integer ch;
string animation = "stand";
key avatar;

integer ExprEnabled = TRUE;
string  Expression;
float   ExprTimer;

integer BallNum;

list Expressions = [
      ""
    , "express_open_mouth"          // 1
    , "express_surprise_emote"      // 2
    , "express_tongue_out"          // 3
    , "express_smile"               // 4
    , "express_toothsmile"          // 5
    , "express_wink_emote"          // 6
    , "express_cry_emote"           // 7
    , "express_kiss"                // 8
    , "express_laugh_emote"         // 9
    , "express_disdain"             // 10
    , "express_repulsed_emote"      // 11
    , "express_anger_emote"         // 12
    , "express_bored_emote"         // 13
    , "express_sad_emote"           // 14
    , "express_embarrassed_emote"   // 15
    , "express_frown"               // 16
    , "express_shrug_emote"         // 17
    , "express_afraid_emote"        // 18
    , "express_worry_emote"         // 19
    , "SLEEP"                       // 20
];


stopAnim() {
    key id = llGetPermissionsKey();
    list anims = llGetAnimationList(id); 
    integer ix; 
    for (ix = 0; ix < llGetListLength(anims); ++ix) {
        string anim = llList2String(anims, ix);
        if (anim != "") {
            llStopAnimation(anim);
        }
    }
    llSetTimerEvent(0.0);
}

startAnim(string anim) {
    if (Expression != "") {
        if (Expression == "SLEEP") {
            llStartAnimation("express_disdain");
            llStartAnimation("express_smile");
        } else {
            llStartAnimation(Expression);
        }
        if (ExprEnabled) {
            llSetTimerEvent(ExprTimer);
        }
    } else {
        stopAnim();
    }
    if (anim != "") {
        llStartAnimation(anim);
    }
}    

// Animation names with a "*" suffix get open mouth
// Those with a suffix of "::" followed by a number
//   get the expression associated with that number.
//   This can optionally be followed by another "::" delim,
//   with a timer value following.
// Return the anim name without the suffix.
string getExpression(string anim) {
    if (llGetSubString(anim,-1,-1) == "*") {
        Expression = llList2String(Expressions, 1);
        ExprTimer = 0.5;
        return llGetSubString(anim, 0, -2);
    }
    integer ix = llSubStringIndex(anim, "::");
    if (ix == -1) {
        Expression = "";
        ExprTimer = 0.5;
        return anim;
    }
    
    list parms = llParseString2List(anim, ["::"], []);
    anim = llList2String(parms, 0);
    integer exprIx = (integer) llList2String(parms, 1);
    Expression = llList2String(Expressions, exprIx);
    ExprTimer  = (float) llList2String(parms,2);
    
    if (ExprTimer <= 0.0) {
        ExprTimer = 0.5;
    }
    
    return anim;
}

getChan() {
    BallNum = (integer) llGetSubString(llGetScriptName(),-1,-1);          //offset from script name suffix
    ch = BallNum
        + (integer)("0x"+llGetSubString((string)llGetKey(),-4,-1)); //fixed channel for prim
}

default {
    state_entry() {
        state s_on;
    }
}

state s_on {
    state_entry() {
        getChan();
        llListen(ch+8,"",NULL_KEY,"");
    }
    
    on_rez(integer arg) {
        state default;
    }

    link_message(integer from, integer num, string an, key id) {        //an animation is set
        if (an == "PRIMTOUCH") {
            return;
        }
        
        if (num != ch) return;
        an = getExpression(an);     // get & save expression, and return unadorned anim

        if (avatar == llGetPermissionsKey()
            && avatar != NULL_KEY
            && animation != "") {
            llStopAnimation(animation);
            llMessageLinked(LINK_SET, -11002, (string)BallNum + "|" + an, avatar);
            startAnim(an);
        }
        animation = an;
    }

    timer() {  // timer to keep mouth open
        if (Expression == "SLEEP") {
            llStartAnimation("express_disdain");
            llStartAnimation("express_smile");
        } else if (Expression != "") {
            llStartAnimation(Expression);
        }
    }

    listen(integer channel, string name, key id, string str) {           
        if (str == "ALIVE" || str == "DIE") {
            llMessageLinked(LINK_THIS,2,str,"");                        //send msg from ball to menu
            if (str == "DIE") {
                avatar = NULL_KEY;
                llSetTimerEvent(0.0);
            }
            return;
        }
            
        avatar = (key) str;     //avatar (sit) or NULL_KEY (stand up)
        if (avatar == NULL_KEY) {
            if (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION) {
                stopAnim();
                llMessageLinked(LINK_SET, -11001, (string)BallNum, llGetPermissionsKey());
            }
            // llReleaseControls();
            return;
        }
        
        if (avatar != llGetPermissionsKey()
            || ! (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION)) {
            ExprEnabled = TRUE;
            llRequestPermissions(avatar, PERMISSION_TRIGGER_ANIMATION);
        } else {
            stopAnim();
            llMessageLinked(LINK_SET, -11000, (string)BallNum + "|" + animation, avatar);
            startAnim(animation);
        }
    }

    run_time_permissions(integer perm) {
        if (avatar != llGetPermissionsKey()) {
            llWhisper(DEBUG_CHANNEL, "avatar != perm key");
            return;
        }

        if (perm & PERMISSION_TRIGGER_ANIMATION) {
            stopAnim();
            llMessageLinked(LINK_SET, -11000, (string)BallNum + "|" + animation, avatar);
            startAnim(animation);
        } else {
            llMessageLinked(LINK_SET, -11001, (string)BallNum, avatar);
            llSetTimerEvent(0.0);
        }
    }
}