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 Paramour Multi-Purpose NPC Rez & Pose  

Paramour Multi-Purpose NPC Rez & Pose

NPC Controller

Category: NPC
By : Aine Caoimhe (Mata Hari)
Created: 2015-11-24 Edited: 2015-11-23
Worlds: OpenSim

the Zip file

Download all files for Paramour Multi-Purpose NPC Rez & Pose
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Readme.txt
Get file # 2. Script.lsl
1 Paramour Multi-Purpose NPC Rez & Pose
2 by Aine Caoimhe (Mata Hari)(c. LACM) April 2015
3
4 Provided under Creative Commons Attribution-Non-Commercial-ShareAlike 4.0 International license.
5 Please be sure you read and adhere to the terms of this license: https://creativecommons.org/licenses/by-nc-sa/4.0/
6
7 INSTRUCTIONS
8
9 This item is designed as a multi-purpose NPC utility for a wide variety of general uses. You can place the script in any object you want, then adjust its settings to whatever general application you have in mind. For more complex situations you may need to make additions or alterations to the script which you are free to do provided you adhere to the license.
10
11 1. Either rez this object to ground or place the script into another object you'd like to use as your controller. If you wear it, it will be deactivated although if you have a bit of scripting knowledge you could alter the script to allow this but then you're responsible for making sure you don't rez a NPC that then attempts to sit on a worn object and then ends up stranded.
12
13 2. If you want this script to handle basic animation for you, you'll need to add at least 1 animation to the object's inventory. If you prefer, you can have another script handle animations instead provided it's designed to work for a sitting NPC. Most basic furniture sit scripts can do this but more complicated systems may not (unless modified).
14
15 3. If you want to use a NPC that you've already stored as an appearance notecard, you can simply place a copy of that notecard into the object's inventory and rename it to meet the name requirements of this script (see below).
16
17 4. Now open the script and adjust the user settings, then save. Depending on your settings and whether you've supplied a NPC notecard, resetting the script will either rez a NPC or wait for you to touch it.
18
19 5. If the object is controlling a NPC, touching the object will remove the NPC. If it isn't currently controlling a NPC, touching it will rez one.
20
21 6. If you change the inventory (add/remove animations or notecards) you should reset the script as well to have the changes picked up. I don't do it automatically in case you wish to add/remove many items at once which can result in extremely long processing and is a PITA.
22
23 NPC APPEARANCE NOTECARD NAMING
24
25 This item is quite flexible but it's best to use the same naming format as the PMAC system where the name must be in the form:
26 .NPCxxp Firstname Lastname
27 - it must begin with .NPC (dot and then capital letters NPC)
28 - it is then immediately followed by two more letters or numbers that only affect its sort order in inventory. For use with this script they are optional
29 - then one final letter which is also optional for this script but in PMAC is used for permission check
30 - then a space
31 - then the first name to use for the NPC
32 - then a space
33 - then the last name to use for the NPC
34 - for this script if no names are supplied a generic name will be used
35
36 So for this script you just need a card that starts with ".NPC" but it might be a good idea to get into the habit of using PMAC formatting for added convenience should use use that system at some point in the future.
37
38 When this script creates an appearance notecard it is automatically named using the source avatar's name and is correctly formatted for PMAC with sort order 00 and permission set to A (all).
39
40
41 USER SETTINGS
42
43 ownerOnly
44 can be set to either TRUE or FALSE
45 - if TRUE, only the owner can touch the object to rez/remove the NPC
46 - if FALSE, anyone can do so
47
48 hideInUse
49 can be set to either TRUE or FALSE
50 - if TRUE, when the NPC is rezzed the prim containing the script will be set to alpha = 0 to hide it, and any floaty text will also be hidden. The object and floaty text will re-appear when touched. This is very handy when using this as an invisible poseball for NPCs to sit on...you just need to remember where you put it so you can locate it again to touch it while it's invisible. when made visible the alpha is set to 1.0 which might not be suitable for your object so you may need to change this value inside the script itself for custom applications == just search for "llSetLinkAlpha" and adjust as appropriate)
51 - if FALSE, the alpha of the object won't be changed and no text will be applied
52
53 target
54 can be left at "" or you can supply the key (UUID) of any object in the region that you want the NPC to sit on when it is rezzed
55 - if no key is supplied, the object containing this script will be the object the NPC sits on
56 - if you supply a key but the object isn't in the region or isn't valid, it will revert to use the object containing this script instead
57 - if the object is more than 10m from the object containing this script, the NPC will first be teleported to the location of the object. There is no distance limit (provided the target remains in the region)
58
59 animateNpc
60 can be set to either TRUE or FALSE
61 - if FALSE, the NPC will be rezzed and sit on the target and then it's assumed that another script will handle animations (if any) and this script's function will simply be to control rezzing and removing the NPC
62 - if TRUE, this script will handle basic animation of the NPC provided you place one or more animations in the script object's inventory (even if the NPC is sitting on a different target!). If more than 1 animation is supplied it will cycle through all available animations
63
64 animationTimer
65 can be any value greater than 0.0
66 This determines how often to change animation if there is more than 1 animation in inventory and if animateNpc is TRUE. If there is only a single animation (or you set animateNpc to FALSE) it is ignored
67
68 randomAnim
69 can be set to either TRUE or FALSE
70 - if TRUE, the list of animations will play in random order. After each animation has played once, the list is re-shuffled so it's possible that the same animation could play twice in a row
71
72 autoRez
73 can be set to TRUE or FALSE
74 - if TRUE and there's a NPC appearance notecard in inventory, the NPC will automatically rez and sit on the target when the script is reset or if the region restarts -- highly useful for populating your region with NPCs even if you aren't there when the region restarts
75 - if FALSE, or if there is no appearance notecard in inventory, the object will wait for you to touch it before rezzing the NPC
76
77 storeToucher
78 can be set to TRUE or FALSE
79 - if TRUE and if the object does not already contain a NPC appearance notecard, the toucher will be asked whether they are willing to be cloned and have that appearance stored as a notecard in the prim's inventory. If they agree, the script will do so using the correct naming format. If they decline, the script will abort.
80 - if FALSE, and if there is no appearance notecard in inventory, the toucher will be cloned and rezzed directly to the NPC without a permission check but the appearance is NOT stored
81 - in either case, if there is one or more appearance notecard in inventory the first one found will be used instead
82
83 floatyText and floatyTextColour
84 You can set text to display above the object or leave it blank ( "" ). The colour uses standard LSL vector values.

Paramour Multi-Purpose NPC Rez & Pose

Paramour Multi-Purpose NPC Rez & Pose//:...

Category: NPC
By : Aine Caoimhe (Mata Hari)
Created: 2015-11-24 Edited: 2015-11-23
Worlds: OpenSim

1 //:AUTHOR: Aine Caoimhe (Mata Hari)
2 //:DESCRIPTION:Paramour Multi-Purpose NPC Rez & Pose
3 //:License: Creative Commons Attribution-Non-Commercial-ShareAlike 4.0 International license.
4 //CODE:
5 // Paramour Multi-Purpose NPC Rez & Pose
6 // by Aine Caoimhe (Mata Hari)(c. LACM) April 2015
7 // Provided under Creative Commons Attribution-Non-Commercial-ShareAlike 4.0 International license.
8 // Please be sure you read and adhere to the terms of this license: https://creativecommons.org/licenses/by-nc-sa/4.0/
9 //
10 // - Place this script in any object
11 // - Optionally set a different target for the NPC to sit on when rezzed
12 // - Optionally set the script to auto-rez an NPC if there is a notecard in inventory to use for the NPC's appearance (autorez will occur on script reset or region restart)
13 // - Optionally, add one or more animations for the NPC to use if controlling animations from this object. If more than one is found the NPC will cycle through them
14 // - Optionally, add one NPC notecard with the name ".NPCxxp Firstname Lastname" to the object. If more than one is found, the first one will be used. If none are
15 // found the toucher's appearance is used and (optionally) stored to the object
16 // The name conforms to the PMAC sytem NPC naming convensions where xx is used to sort the card order and p is the permission seting where A=all, G=group, and O=owner
17 // but these permission settings are ignored by this script nor is there any error-checking for them -- your card will work as long as it is 3 words where the first word
18 // begins with ".NPC" (dot then capital letters N P C)
19 //
20 // If you change the contents of the object (add/remove animations or notecards) you MUST reset the script to pick up those changes
21 // If the object containing the script is worn, it is disabled
22 // If the script is controlling a NPC, touching the object will remove the NPC
23 // If the script isn't controlling a NPC, touching the object will rez the NPC either from notecard or via cloning the toucher
24 // If a NPC is found standing on this object when reset, the script will assume control of that NPC. It can't do that for NPCs on other targets so remember
25 // to remove one before resetting this script. If you accidentally strand a NPC, use the Paramour NPC Manager to remove it.
26 //
27 // OSSL functions required:
28 // osIsUUID()
29 // osIsNpc()
30 // osNpcCreate()
31 // osNpcRemove()
32 // osTeleportAgent() if rezzing to a target that is more than 10m away from the object containing this script
33 // osAvatarPlayAnimation() if the option to animate the NPC is being used
34 // osAvatarStopAnimation() if the option to animate the NPC is being used
35 // osAgentSaveAppearance() if the option to store toucher appearance is being used
36 //
37 // USER SETTINGS
38 integer ownerOnly=TRUE; // TRUE = only owner can touch to rez/remove NPC; FALSE = anyone can
39 integer hideInUse=TRUEE; // TRUE = set this object to invisible when a NPC is being controlled by it (useful when using this as a hidden poseball though then you'll have to
40 // remember where you placed it); FALSE = don't hide this object. Note if this is part of a linkset only this prim is hidden
41 key target=1b600ed6-c416-457c-bae0-7f3397befa42""; // supply the key of the object you want the NPC to sit on or leave empty ("") to have the NPC sit on this object
42 integer animateNpc=FALSE; // TRUE = this object will handle animations if one or more are found in inventory; FALSE = another script will handle aniamtions
43 float animationTimer=60.0; // If this script is handling animations and more than one is found, how often to switch to the next animation (it also does a presense check)
44 integer randomAnim=TRUE; // If more than 1 animation is found in inventory, play animations in random order (list will be re-randomized after each has played once)
45 integer autoRez=TRUE; // TRUE = if there is an appearance notecard in inventory, auto-rez that NPC any time the region restarts or this script is reset; FALSE = only rez on touch
46 integer storeToucher=TRUE; // TRUE = if there is no appearance notecard in inventory, store the toucher's appearance when cloning them (subject to permission from the target)
47 string floatyText="Paramour Multi-Purpose NPC Rez & Pose"; // text to have floating above the object or supply an empty string ( "") for none
48 vector floatyTextColour=<1.000, 0.906, 0.502>; // LSL vector colour to use for the text (<0.0, 0.0, 0.0> = black, <1.0, 1.0, 1.0> = white)
49 //
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
51 // DON'T CHANGE ANYTHING BELOW HERE UNLESS YOU KNOW WHAT YOU'RE DOING
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
53 list anims;
54 integer indAnim;
55 key npc=NULL_KEY;
56 string npcToRez;
57 string firstName;
58 string lastName;
59 integer myChannel;
60 integer handle;
61
62 startAnimation()
63 {
64 buildAnimList();
65 if(llGetListLength(anims)==0) return;
66 string anToPlay=llList2String(anims,indAnim);
67 key dontStop=llGetInventoryKey(anToPlay);
68 osAvatarPlayAnimation(npc,anToPlay);
69 list anToStop=llGetAnimationList(npc);
70 integer stop=llGetListLength(anToStop);
71 while(--stop>=0) { if(llList2Key(anToStop,stop)!=dontStop) osAvatarStopAnimation(npc,llList2String(anToStop,stop)); }
72 if(llGetListLength(anims)>1) llSetTimerEvent(animationTimer);
73 }
74 doRezNpc(key clone, integer perm)
75 {
76 if(npcToRez=="")
77 {
78 if(storeToucher)
79 {
80 if(!perm)
81 {
82 myChannel=0x80000000|(integer)("0x"+(string)llGetKey());
83 handle=llListen(myChannel,"",clone,"");
84 llSensorRepeat("",clone,AGENT,32.0,PI,60.0);
85 llDialog(clone,"This object would like your permission to clone and store your appearance to a NPC notecard. Will you permit this?\nA no response will be assumed if you don't respond within 60 seoncds",["YES","NO","CANCEL"],myChannel);
86 return;
87 }
88 else
89 {
90 getNameData(clone);
91 osAgentSaveAppearance(clone,npcToRez);
92 llSleep(0.25); // give a little time to store the data and have it register to prim's inventory
93 }
94 }
95 else
96 {
97 getNameData(clone);
98 npcToRez=clone;
99 }
100 }
102 {
103 llRegionSayTo(clone,0,"Unable to locate the expected appearance notecard in inventory. Perhaps you deleted it without resetting the script? Resetting the script now. Please wait a moment, then touch me again to resume");
105 return;
106 }
107 npc=osNpcCreate(firstName,lastName,llGetPos()+<0.0,0.0,2.0>,npcToRez,OS_NPC_SENSE_AS_AGENT);
108 if(hideInUse)
109 {
111 llSetText(floatyText,floatyTextColour,0.0);
112 }
113 vector targetPos=llGetPos();
114 if(target=="") target=llGetKey();
115 else if(target==NULL_KEY) target=llGetKey();
116 else if(osIsUUID(target))
117 {
118 list data=llGetObjectDetails(target,[OBJECT_POS]);
119 if(data==[])
120 {
121 llRegionSayTo(clone,0,"Unable to find the target specified in the script in this region. Using this object as the target instead");
122 target=llGetKey();
123 }
124 else targetPos=llList2Vector(data,0);
125 }
126 else
127 {
128 llRegionSayTo(clone,0,"Your target does not appear to be a valid key. Using this object as the target instead");
129 target=llGetKey();
130 }
131 if(llVecDist(targetPos,llGetPos())>10.0) osTeleportAgent(npc,targetPos+<0.0,0.0,2.0>,ZERO_VECTOR);
132 osNpcSit(npc,target,OS_NPC_SIT_NOW);
133 if(animateNpc)
134 {
135 llSleep(0.25); // have to wait for the LSL sit animation to register to the npc's animation list
136 startAnimation();
137 }
138 }
139 getNameData(key name)
140 {
141 list nameParsed=llParseString2List(llKey2Name(name),["."," "],[]);
142 firstName=llList2String(nameParsed,0);
143 lastName=llList2String(nameParsed,1);
144 if(firstName=="") firstName="Noname";
145 if(lastName=="") lastName="NPC";
146 npcToRez=".NPC00A "+firstName+" "+lastName;
147 }
148 buildAnimList()
149 {
150 anims=[];
152 while(--i>=0){ anims=[]+[llGetInventoryName(INVENTORY_ANIMATION,i)]+anims; }
153 if(randomAnim) anims=[]+llListRandomize(anims,1);
154 indAnim=0;
155 if(llGetListLength(anims)==0) llOwnerSay("WARNING! Script is set to handle animations but none could be found in inventory. NPC will play stock SL sit animation");
156 }
157 findNpcToRez()
158 {
159 npcToRez="";
160 firstName="";
161 lastName="";
162 integer i;
163 while((npcToRez=="") && (i<llGetInventoryNumber(INVENTORY_NOTECARD)))
164 {
166 if(llSubStringIndex(cardName,".NPC")==0)
167 {
168 list split=llParseString2List(cardName,[" "],[]);
169 npcToRez=cardName;
170 firstName=llList2String(split,1);
171 lastName=llList2String(split,2);
172 if(firstName=="") firstName="Noname";
173 if(lastName=="") lastName="NPC";
174 }
175 i++;
176 }
177 }
178 default
179 {
181 {
182 if(hideInUse)
183 {
184 llSetText(floatyText,floatyTextColour,1.0);
186 }
187 if(llGetAttached()) return;
188 findNpcToRez();
190 if(osIsNpc(llGetLinkKey(last)))
191 {
192 npc=llGetLinkKey(last);
193 if(animateNpc) startAnimation();
194 }
195 else npc=NULL_KEY;
196 if((autoRez) && (npc==NULL_KEY) && (npcToRez!="")) doRezNpc(llGetOwner(),FALSE);
197 }
198 no_sensor()
199 {
201 }
202 sensor(integer foo)
203 {
204 llRegionSayTo(llDetectedKey(0),0,"Dialog timed out. Assuming your response is NO so aborting the request to rez a NPC");
206 }
207 listen (integer channel, string name, key who, string message)
208 {
210 if(message=="YES") doRezNpc(who,TRUE);
211 else llRegionSayTo(who,0,"Aborting the request to rez a NPC");
212 }
213 on_rez(integer foo)
214 {
216 }
217 changed (integer change)
218 {
219 if(change & CHANGED_OWNER) llResetScript();
220 else if(change & CHANGED_REGION_START) llResetScript();
221 }
222 timer()
223 {
225 {
226 llOwnerSay("Unable to find NPC");
227 npc=NULL_KEY;
228 llSetTimerEvent(0.0);
230 return;
231 }
232 string animToStop=llList2String(anims,indAnim);
233 indAnim++;
234 if(indAnim>llGetListLength(anims))
235 {
236 indAnim=0;
237 if(randomAnim) anims=[]+llListRandomize(anims,1);
238 }
239 string animToStart=llList2String(anims,indAnim);
240 if(animToStart!=animToStop)
241 {
242 osAvatarPlayAnimation(npc,animToStart);
243 osAvatarStopAnimation(npc,animToStop);
244 }
245 }
247 {
248 if(llGetAttached()) return;
249 key toucher=llDetectedKey(0);
250 if(ownerOnly && (toucher!=llGetOwner()))
251 {
252 llRegionSayTo(toucher,0,"Sorry, you don't have permission to use this");
253 return;
254 }
255 if(npc==NULL_KEY) doRezNpc(toucher,FALSE);
257 {
258 npc=NULL_KEY;
259 llSetTimerEvent(0.0);
260 doRezNpc(toucher,FALSE);
261 }
262 else
263 {
264 osNpcRemove(npc);
265 npc=NULL_KEY;
266 llSetTimerEvent(0.0);
267 llRegionSayTo(toucher,0,"NPC removed");
268 if(hideInUse)
269 {
271 llSetText(floatyText,floatyTextColour,1.0);
272 }
274 }
275 }
276 }

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