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 Appearance Sorter  

NPC Appearance Sorter

Preview a series of NPC appearance notecards.

Category: NPC
By : Aine Caoimhe (Mata Hari)
Created: 2016-02-26 Edited: 2016-02-26
Worlds: OpenSim

the Zip file

Download all files for NPC Appearance Sorter
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Script.lsl
1 //UTILITY SCRIPT: NPC Appearance Sorter
2 //I had a request from someone for a simple script to let you look through NPC appearance notecards to figure out what they were so I wrote this little utility which could be useful for others.
3
4 //To use it:
5 //Rez a prim in a region where NPCs and the necessary OSSL functions are enabled
6 //Add one or more appearance notecards to the prim
7 //(Optional) add an animation to the prim -- otherwise the NPC will play the default SL stand.
8 //Add a new script and copy the script, below, into it, and save
9 //Touch the prim to begin
10 //* * * * * * * COPY EVERYTHING BELOW HERE INTO THE SCRIPT * * * * * * *
11
12 // PARAMOUR NPC SORTER
13 // by Aine Caoimhe (Mata Hari)(c. LACM) February 2016
14 // Provided under Creative Commons Attribution-Non-Commercial-ShareAlike 4.0 International license.
15 // Please be sure you read and adhere to the terms of this license: https://creativecommons.org/licenses/by-nc-sa/4.0/
16 //
17 // *** THIS SCRIPT REQUIRES (AND WILL ONLY WORK) IN REGIONS WHERE THE SCRIPT OWNER HAS NPC ENABLED AND OSSL FUNCTION PERMISSIONS ***
18 //
19 // This is a simple script for previewing a series of NPC appearance notecards.
20 // The NPC is rezzed and sits on the object containing the script. Using the dialog you can scroll through appearances and (optionally) delete any you don't want.
21 //
22 // INSTRUCTIONS
23 //
24 // - Place this script in a prim (I use a generic prim sphere)
25 // - Add appearance notecards to its inventory (names don't matter...just don't add any notecards that aren't appearances)
26 // - Optional: add one animation to the prim that you want the NPC to play...if you don't, it will use the generic SL "stand" instead
27 // - Touch the prim and follow the dialog instructions
28 // - Adding a new appearance notecard or changing the animation inside it requires a script reset to pick up the changes
29 //
30 // KNOWN BUG:
31 // There is a known bug currently in Opensim (I reported it in Sept 2014 http://opensimulator.org/mantis/view.php?id=7325) where NPCs will often not display
32 // the animation until some time after told to. They will eventually display it if you wait, or you can also trigger it by changing them to a different appearance.
33 // There are other work-arounds but for this script I kept it simple.
34 //
35 // * * * * * * * * *
36 // USER SETTINGS
37 // * * * * * * * * *
38 integer ownerOnly=TRUE; // TRUE = only owner can activate it...FALSE = anyone can...I recommend restricting to owner so nobody else can delete any of your notecards
39 vector sitPos=<0.0, 0.0, 2.0>; // sit target offset to use..adjust to whatever suits the object
40 float dialogTimeout=120.0; // time (in seconds) to wait before removing the dialog listener if no response has been received
41 integer showFloatyText=TRUE; // TRUE = display the current appearance name as floaty text above the prim...FALSE = only show it in the dialog menu
42 vector textColour=<0.0,1.0,0.0>; // vector colour to use for the floaty text (if being used)
43 //
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
45 // DON'T CHANGE ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
47 key user;
48 key npc;
49 integer myChannel;
50 integer handle;
51 string anim;
52 list appear=[];
53 integer ind;
54
55 showMenu()
56 {
57 handle=llListen(myChannel,"",user,"");
58 llSetTimerEvent(dialogTimeout);
59 string txtDia="Currently showing: "+llList2String(appear,ind)+"\n("+(string)(ind+1)+" of "+(string)llGetListLength(appear)+")";
60 list butDia=["< PREV","DONE","NEXT >"];
61 if(npc==NULL_KEY)
62 {
63 txtDia="\n\nREZ rezzes an NPC";
64 butDia=[]+butDia+["REZ"];
65 }
66 else
67 {
68 txtDia+="\n\nKILL removes the NPC";
69 butDia=[]+butDia+["KILL"];
70 }
71 txtDia+="\n\nDELETE will delete the current appearance notecard and advance to the next one\n\nGIVE hands you a copy of the appearance notecard";
72 butDia=[]+butDia+["DELETE","GIVE"];
73 llDialog(user,txtDia,butDia,myChannel);
74 }
75 rezNpc()
76 {
77 string show=llList2String(appear,ind);
78 if(show=="")
79 {
80 llRegionSayTo(user,0,"ERROR! There are no apperanaces in inventory!");
81 user=NULL_KEY;
82 return;
83 }
84 npc=osNpcCreate("NPC","Model",llGetPos()+<0,0,2>,show,8); //flag 8 = access perms compatible with both Opensim 0,9 parcel perm changes and all previous Opensim versions
85 llSleep(0.25); // ugly but necessary delay before sitting...give NPC time to register properly
86 osNpcSit(npc,llGetKey(),OS_NPC_SIT_NOW);
87 }
88 setAppearance()
89 {
90 if(osIsNpc(npc)) osNpcLoadAppearance(npc,llList2String(appear,ind));
91 llSetText(llList2String(appear,ind)+"\n("+(string)(ind+1)+" of "+(string)llGetListLength(appear)+")",textColour,(float)showFloatyText);
92 }
93 startAnimation()
94 {
95 if(!osIsNpc(npc)) return;
96 llSleep(0.25); // need to sleep for 0.25 just to give the sit animation a chance to register, but this may still not be long enough to work around the long-standing Opensim bug
97 list anToStop=llGetAnimationList(npc);
98 osAvatarPlayAnimation(npc,anim);
99 integer stop=llGetListLength(anToStop);
100 while(--stop>=0) { osAvatarStopAnimation(npc,llList2String(anToStop,stop));}
101 }
102 buildAppear()
103 {
104 appear=[];
106 while(--ind>=0) { appear = []+[llGetInventoryName(INVENTORY_NOTECARD,ind)]+appear;}
107 if(llGetListLength(appear)) ind=0;
108 else ind=-1;
109 }
110 default
111 {
113 {
115 else anim="stand";
117 myChannel=0x80000000 | (integer)("0x"+(string)llGetKey());
118 user=NULL_KEY;
119 buildAppear();
120 if(ind==-1)
121 {
122 llOwnerSay("WARNING: No appearance notecards found in inventory. Disabling script.");
123 return;
124 }
125 if(sitPos==ZERO_VECTOR) sitPos=<0,0,0.00001>;
127 // if NPC found sitting, make this my NPC
129 if(npc!=NULL_KEY)
130 {
131 if(!osIsNpc(npc))
132 {
133 llRegionSayTo(npc,0,"Sorry, this item is for NPCs to sit on only");
134 llUnSit(npc);
135 npc=NULL_KEY;
136 }
137 else
138 {
139 setAppearance();
140 startAnimation();
141 }
142 }
143 }
144 timer()
145 {
146 llSetTimerEvent(0.0);
147 llRegionSayTo(user,0,"Dialog timed out.");
148 llListenRemove(handle);
149 user=NULL_KEY;
150 }
151 on_rez(integer foo)
152 {
154 }
155 changed(integer change)
156 {
157 if(change & CHANGED_OWNER) llResetScript();
158 else if(change & CHANGED_REGION_START) llResetScript();
159 }
161 {
162 key who=llDetectedKey(0);
163 if(ownerOnly && (who!=llGetOwner())) llRegionSayTo(who,0,"Sorry, only the owner can use this");
164 else if(ind==-1) llRegionSayTo(who,0,"ERROR: no appearance notecards found. Please add some, then reset the script.");
165 else if(user!=NULL_KEY)
166 {
167 if(who==user) showMenu();
168 else llRegionSayTo(who,0,"Sorry, this item is already in use.");
169 }
170 else
171 {
172 user=who;
173 if(npc==NULL_KEY)
174 {
175 rezNpc();
176 startAnimation();
177 }
178 if(user!=NULL_KEY) showMenu(); // can become null key if no appearance were found in inventory
179 }
180 }
181 listen (integer channel,string name, key who, string message)
182 {
183 llListenRemove(handle);
184 llSetTimerEvent(0.0);
185 if(message=="DONE")
186 {
187 user=NULL_KEY;
188 return;
189 }
190 if(message=="REZ")
191 {
192 rezNpc();
193 if(user==NULL_KEY) return; // user becomes null key when no appearances exist
194 }
195 else if(message=="KILL")
196 {
197 if(osIsNpc(npc)) osNpcRemove(npc);
198 npc=NULL_KEY;
199 }
200 else if(message=="GIVE")
201 {
202 string card=llList2String(appear,ind);
203 if((card=="") || (llGetInventoryType(card)!=INVENTORY_NOTECARD))
204 {
205 llRegionSayTo(user,0,"ERROR: unable to find the expected card...resetting the script to pick up the necessary inventory changes");
207 return;
208 }
209 llRegionSayTo(user,0,"Give you the appearance notecard: "+card+"\nYou will find it in your notecards folder or your suitcase's notecard folder depending on whether you're in your home grid or not");
210 llGiveInventory(user,card);
211 }
212 else if(message=="DELETE")
213 {
214 string card=llList2String(appear,ind);
215 if((card=="") || (llGetInventoryType(card)!=INVENTORY_NOTECARD))
216 {
217 llRegionSayTo(user,0,"ERROR: unable to find the expected card...resetting the script to pick up the necessary inventory changes");
219 return;
220 }
222 llRegionSayTo(user,0,"Appearance notecard deleted: "+card);
223 appear=[]+llDeleteSubList(appear,ind,ind);
224 if(llGetListLength(appear)==0)
225 {
226 llRegionSayTo(user,0,"There are no more appearance notecards in inventory. Removing NPC (if any) and resetting script");
227 if(osIsNpc(npc)) osNpcRemove(npc);
228 npc=NULL_KEY;
230 return;
231 }
232 if(ind>=llGetListLength(appear)) ind=0;
233 setAppearance();
234 }
235 else
236 {
237 if(llGetListLength(appear)==1) llRegionSayTo(user,0,"There is only one appearance in inventory...can't change appearance");
238 else
239 {
240 if(message=="< PREV") ind--;
241 else if(message=="NEXT >") ind++;
242 else
243 {
244 llOwnerSay("ERROR! Unexpected menu response: "+message);
245 return;
246 }
247 if(ind<0) ind=llGetListLength(appear)-1;
248 else if(ind>=llGetListLength(appear)) ind=0;
249 setAppearance();
250 }
251 }
252 showMenu();
253 }
254 }

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