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
NPC NPC General Utility Rez and Pose Dancer  

NPC General Utility Rez and Pose Dancer

This was written as a "dancer" script for a club.

Category: NPC
By : Aine Caoimhe (aka Mata Hari)
Created: 2014-02-20 Edited: 2014-02-20
Worlds: OpenSim

the Zip file

Download all files for NPC General Utility Rez and Pose Dancer
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Script V1.lsl
Get file # 2. Script V2.lsl
Get file # 3. Script V3.lsl
1 // :SOURCE: http://forums.osgrid.org/viewtopic.php?f=5&t=4989
2
3 // Place this in a prim along with at least 1 animation.
4 // When you first touch it you will be cloned to notecard, then an NPC will rez, jump on the poseball and
5 // begin to play the animation(s) in its inventory. Subsequent touched of the prim will rez/unrez the dancer.
6 // On region restart, the dancer will auto-rez by default. You can add more animations or delete them during use
7 // (but it will reset the NPC's dance queue). Deleting the appearance notecard will disable the ball until you touch it again.
8 // Note that this script uses a very handy "orphan checker" that helps to prevent the accidentaly orphaning of a dancer.
9 // If an unexpected NPC is detected as already being on the poseball the ball will "take control" of that NPC instead of rezzing a new one.
10
11
12 // NPC General Utility Rez & Pose Dancer
13 // Written by Aine Caoimhe (aka Mata Hari) 2012/2013
14 //
15 // OVERVIEW
16 //
17 // This basic script is designed to be placed in any object (usually a poseball) along with at least one animation.
18 // When the owner touches the poseball for the first time their appearance will be cloned and stored to use for
19 // an NPC who will then rez, sit on the poseball, and begin to play the animation. Subsequent touches of the poseball
20 // will remove or restore the NPC. The script doesn't provide any "advanced" features such as variable timers, variable NPCs,
21 // dance selection/controls, etc.
22 //
23 // Because this was written by special request, several default behaviours are part of the script but can be altered
24 // easily either by changing the settings in the USE VARIABLES section below (even a novice can do this!) or more
25 // drastic changes can be made by altering the main body of the script.
26 //
27 // This script requires a region that is configured to allow the OSSL functions necessary to create and animate NPC
28 // (uses osAvatarPlayAnimation() and osAvatarStopAnimation() rather than the NPC versions of those functions because
29 // at the time I wrote most of it the NPC versions didn't work correctly).
30 //
31 // TERMS OF USE
32 //
33 // This script is provided as a courtesy to other users of OpenSim on an as-is basis. I'll try to help you if you ask nicely
34 // but I won't promise to fix or resolve any issues you might encounter or further customize it for your uses.
35 // You are free to use and modify it as desired, provided you:
36 // - also provide it free of charge with full perms as per GPU General Public Licence 3.0
37 // - never alter the script to allow it to clone another avatar appearance without that owner's explicit and informed consent (avi theft)
38 //
39 //
40 // -----------------------------------------------------------------------
41 // USER VARIABLES
42 // you can change these default values to suit your preferences
43 // -----------------------------------------------------------------------
44
45 // The name of your dancer...this is the name she will show in world
46 string dancerFirstName="Club";
47 string dancerLastName="Dancer";
48
49 // How she changes dances...one of the two following lines must be commented (disabled using // at the start of the line) and the
50 // other line must be active (no // at the start)
51
52 string danceSeq="random"; // dancer will pick the next animation randomly
53 // string danceSeq="seq"; // dancer will pick the next animation in the poseball
54
55 // How often she changes dances -- set a value here in seconds that you want her to play each dance before advancing to the next
56 float danceTimer=120.0;
57
58 // Is the poseball active? Set this to TRUE to have her automatically rezzed whenever the region is restarted. Otherwise set to FALSE.
59 integer active=TRUE;
60
61 // Positioning...how far from the ball to place the dancer (essentially this is her sit target) as a (x,y,z) vector
62 vector offSet=<0.0, 0.0, 1.0>;
63
64 // -----------------------------------------------------------------------
65 // DON'T CHANGE ANYTHING BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING :)
66 // -----------------------------------------------------------------------
67
68 string npcCard="My Dancer";
69 key dancerID;
70 integer danceIndex;
71 list danceList;
72
73 updateDanceList()
74 {
75 // build list of animations in inventory
77 while(--anims>-1)
78 {
80 }
81 if(danceSeq=="seq") danceList=llListSort(danceList,1,TRUE);
82 else danceList=llListRandomize(danceList,1);
83 danceIndex=0;
84 }
85 rezDancer()
86 {
87 // make sure there are animations
88 if(!llGetListLength(danceList))
89 {
90 llOwnerSay("Cannot create the dancer because there are no animations in the poseball inventory for her to play");
91 return;
92 }
93 // make sure there is a dancer to rez (shouldn't be possible to get this result but included just in case
95 {
96 llOwnerSay("Cannot create the dancer because there is no stored appearance in inventory for her.");
97 return;
98 }
99 // see if an npc is already sitting...helps to recover from accidental script reset with active NPC
100 if(checkForSitter()) startDancing();
101 // safe to proceed with rezzing new NPC if we get to this point
102 else
103 {
104 dancerID=osNpcCreate(dancerFirstName,dancerLastName,llGetPos()+<0,0,1>,npcCard);
105 llSleep(0.5);
106 osNpcSit(dancerID,llGetKey(),OS_NPC_SIT_NOW);
107 }
108 }
109 removeDancer()
110 {
111 // kill active npc
112 osNpcRemove(dancerID);
113 dancerID=NULL_KEY;
114 }
115 integer checkForSitter()
116 {
117 // a safety net to try to catch stray NPCs cause by script edit/reset while an NPC is active
118 // if an NPC is detected already on the ball but no dancerID is set...this is only called at
119 // a time when a new NPC would otherwise be created
120 key sitterID=llAvatarOnSitTarget();
121 if(sitterID!=NULL_KEY)
122 {
123 if(osIsNpc(sitterID))
124 {
125 llOwnerSay("Detected an NPC already using the ball...setting this as my npc");
126 dancerID=sitterID;
127 return TRUE;
128 }
129 else
130 {
131 llOwnerSay("Unexpectedly found an avatar sitting on the poseball...it's going to get crowded!");
132 return FALSE;
133 }
134 }
135 else return FALSE;
136 }
137 startDancing()
138 {
139 // called when an NPC first sits
140 string dance=llList2String(danceList,danceIndex);
141 // start currently indexed dance
142 osAvatarPlayAnimation(dancerID,dance);
143 llSleep(0.25);
144 // now stop any other animations the NPC is playing (sit, etc)
145 list animToStop=llGetAnimationList(dancerID);
146 integer stop=llGetListLength(animToStop);
147 key dontStop=llGetInventoryKey(dance);
148 while(--stop)
149 {
150 if(llList2Key(animToStop,stop)!=dontStop) osAvatarStopAnimation(dancerID,llList2Key(animToStop,stop));
151 }
152 // set the timer for advancing to next dance
153 llSetTimerEvent(danceTimer);
154 }
155 playNextDance()
156 {
157 // play the next dance
158 osAvatarStopAnimation(dancerID,llList2String(danceList,danceIndex));
159 danceIndex++;
160 if(danceIndex==llGetListLength(danceList)) danceIndex=0; // cycle back to beginning when reaching the end
161 osAvatarPlayAnimation(dancerID,llList2String(danceList,danceIndex));
162 }
163 default
164 {
166 {
167 // ensure sit target set
168 if(offSet==ZERO_VECTOR) offSet.z+=0.0001;
170 // update the animations list
171 updateDanceList();
172 // rez dancer automatically if set to do so
173 if(active && (llGetInventoryType(npcCard)==INVENTORY_NOTECARD)) rezDancer();
174 }
175 timer()
176 {
177 // time to advance to next dance...make sure there is a dancer first
178 if((dancerID==NULL_KEY) || (llAvatarOnSitTarget()!=dancerID)) llSetTimerEvent(0.0); // kill timer if NPC unrezzed
179 else playNextDance();
180 }
181 on_rez(integer start)
182 {
183 // always reset on rez
185 }
186 changed(integer change)
187 {
188 // reset script if owner changes or region restarts
189 if(change & CHANGED_OWNER) llResetScript();
190 else if(change & CHANGED_REGION_START) llResetScript();
191 // handle changes in inventory that might affect operation
192 else if(change & CHANGED_INVENTORY)
193 {
194 // safety check on deleting notecard during use
195 if((llGetInventoryType(npcCard)!=INVENTORY_NOTECARD) && (dancerID==NULL_KEY))
196 {
197 llOwnerSay("You have deleted the dancer notecard. Removing the dancer");
198 removeDancer();
199 return;
200 }
201 // else see if it's a change in animations
203 if(!anims && (dancerID!=NULL_KEY))
204 {
205 // user deleted the last animation...kill active dancer
206 llOwnerSay("There are no animations in the poseball...removing your dancer");
207 removeDancer();
208 }
209 else if(anims!=llGetListLength(danceList))
210 {
211 updateDanceList();
212 if(dancerID!=NULL_KEY) startDancing();
213 }
214 }
215 // handle changes in link...will usually be triggered by the NPC sitting or being removed
216 else if(change & CHANGED_LINK)
217 {
218 // start dancing when an npc sits
219 if(dancerID!=NULL_KEY && llAvatarOnSitTarget()==dancerID) startDancing();
220 // can ignore npc standing (derez) because key reset is handled by the remove routine
221 // also ignoring any non-npc who sits here
222 }
223 }
225 {
226 // only owner can play with this
227 if(llDetectedKey(0)!=llGetOwner()) return;
228 // first, clone owner if no appearance card has been stored
230 {
231 llOwnerSay("One moment while your appearance is saved for the npc to use");
232 osOwnerSaveAppearance(npcCard);
233 llSleep(2.0);
234 }
235 // if no dancer, rez one
236 if(dancerID==NULL_KEY)
237 {
238 if(checkForSitter()) startDancing();
239 else rezDancer();
240 }
241 // else there's a dancer so this touch means we want to remove it
242 else removeDancer();
243 }
244 }

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