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 rotator  

NPC rotator

makes a set of NPC's walk in a circle

Category: NPC
By : Ferd Frederix
Created: 2014-09-24 Edited: 2014-09-24
Worlds: Second Life

the Zip file

Download all files for NPC rotator
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. NPC controller.lsl
Get file # 2. Rotate.lsl

This script by Ferd Frederix may be used in any manner, modified, and republished.  Unless specified otherwise, my scripts are always free and open source.  Objects made with these scripts may be sold with no restrictions.  All I ask is that you point others to this location should they ask you about it and to not sell this script, unless it is for $0 L. Please help improve my work by reporting bugs and improvements.

1 XML goes here from touching the prim

NPC rotator

Makes a set of NPC's walk in a circle

Category: NPC
By : Ferd Frederix
Created: 2014-09-24 Edited: 2014-09-24
Worlds: Second Life


This script by Ferd Frederix may be used in any manner, modified, and republished.  Unless specified otherwise, my scripts are always free and open source.  Objects made with these scripts may be sold with no restrictions.  All I ask is that you point others to this location should they ask you about it and to not sell this script, unless it is for $0 L. Please help improve my work by reporting bugs and improvements.

1 // The name of your dancer...this is the name she will show in world
2 string dancerFirstName="Club";
3 string dancerLastName="Dancer";
4
5 // How she changes dances...one of the two following lines must be commented (disabled using // at the start of the line) and the
6 // other line must be active (no // at the start)
7
8 string danceSeq="random"; // dancer will pick the next animation randomly
9 // string danceSeq="seq"; // dancer will pick the next animation in the poseball
10
11 // How often she changes dances -- set a value here in seconds that you want her to play each dance before advancing to the next
12 float danceTimer=120.0;
13
14 // Is the poseball active? Set this to TRUE to have her automatically rezzed whenever the region is restarted. Otherwise set to FALSE.
15 integer active=TRUE;
16
17 // Positioning...how far from the ball to place the dancer (essentially this is her sit target) as a (x,y,z) vector
18 vector offSet=<0.0, 0.0, 1.0>;
19
20
21 // V1.1 Ferd Frederix - remote control - Link messages to the prim animator are captured here.
22 // any NPC Options?
23 // OS_NPC_CREATOR_OWNED will create an 'owned' NPC that will only respond to osNpc* commands issued from scripts that have the same owner as the one that created the NPC.
24 // OS_NPC_NOT_OWNED will create an 'unowned' NPC that will respond to any script that has OSSL permissions to call osNpc* commands.
25 integer NPCOptions = OS_NPC_CREATOR_OWNED; // only the owner of this box can control this NPC.
26
27 integer NPCControllerchannel = 32468;
28
29 // -----------------------------------------------------------------------
30 // DON'T CHANGE ANYTHING BELOW HERE UNLESS YOU KNOW WHAT YOU ARE DOING :)
31 // -----------------------------------------------------------------------
32
33 string npcCard="My Dancer";
34 key dancerID;
35 integer danceIndex;
36 list danceList;
37
38 updateDanceList()
39 {
40 // build list of animations in inventory
42 while(--anims>-1)
43 {
45 }
46 if(danceSeq=="seq") danceList=llListSort(danceList,1,TRUE);
47 else danceList=llListRandomize(danceList,1);
48 danceIndex=0;
49 }
50 rezDancer()
51 {
52 // make sure there are animations
53 if(!llGetListLength(danceList))
54 {
55 llOwnerSay("Cannot create the dancer because there are no animations in the poseball inventory for her to play");
56 return;
57 }
58 // make sure there is a dancer to rez (shouldn't be possible to get this result but included just in case
60 {
61 llOwnerSay("Cannot create the dancer because there is no stored appearance in inventory for her.");
62 return;
63 }
64 // see if an npc is already sitting...helps to recover from accidental script reset with active NPC
65 if(checkForSitter()) startDancing();
66 // safe to proceed with rezzing new NPC if we get to this point
67 else
68 {
69 dancerID= osNpcCreate(dancerFirstName,dancerLastName,llGetPos()+<0,0,1>,npcCard,NPCOptions);
70 llSetObjectDesc(dancerID); // Rev 1.1 save dancer ID persistently.
71 llSleep(0.5);
72 osNpcSit(dancerID,llGetKey(),OS_NPC_SIT_NOW);
73 }
74 }
75 removeDancer()
76 {
77 // kill active npc
78 osNpcRemove(dancerID);
79 dancerID=NULL_KEY;
80 }
81 integer checkForSitter()
82 {
83 // a safety net to try to catch stray NPCs cause by script edit/reset while an NPC is active
84 // if an NPC is detected already on the ball but no dancerID is set...this is only called at
85 // a time when a new NPC would otherwise be created
86 key sitterID=llAvatarOnSitTarget();
87 if(sitterID!=NULL_KEY)
88 {
89 if(osIsNpc(sitterID))
90 {
91 llOwnerSay("Detected an NPC already using the ball...setting this as my npc");
92 dancerID=sitterID;
93 return TRUE;
94 }
95 else
96 {
97 llOwnerSay("Unexpectedly found an avatar sitting on the poseball...it's going to get crowded!");
98 return FALSE;
99 }
100 }
101 else return FALSE;
102 }
103 startDancing()
104 {
105 // called when an NPC first sits
106 string dance=llList2String(danceList,danceIndex);
107 // start currently indexed dance
108 osAvatarPlayAnimation(dancerID,dance);
109 llSleep(0.25);
110 // now stop any other animations the NPC is playing (sit, etc)
111 list animToStop=llGetAnimationList(dancerID);
112 integer stop=llGetListLength(animToStop);
113 key dontStop=llGetInventoryKey(dance);
114 while(--stop)
115 {
116 if(llList2Key(animToStop,stop)!=dontStop) osAvatarStopAnimation(dancerID,llList2Key(animToStop,stop));
117 }
118 // set the timer for advancing to next dance
119 llSetTimerEvent(danceTimer);
120 }
121 playNextDance()
122 {
123 // play the next dance
124 osAvatarStopAnimation(dancerID,llList2String(danceList,danceIndex));
125 danceIndex++;
126 if(danceIndex==llGetListLength(danceList)) danceIndex=0; // cycle back to beginning when reaching the end
127 osAvatarPlayAnimation(dancerID,llList2String(danceList,danceIndex));
128 }
129
130
131
132
133
134
135 default
136 {
138 {
139 // ensure sit target set
140 if(offSet==ZERO_VECTOR) offSet.z+=0.0001;
142 // update the animations list
143 updateDanceList();
144
145 // Rev 1.1 remove old dancwers if we are reset or re-rezzed.
146 dancerID = llGetObjectDesc();
147 removeDancer();
148
149 // rez dancer automatically if set to do so
150 if(active && (llGetInventoryType(npcCard)==INVENTORY_NOTECARD))
151 rezDancer();
152
153 llListen(NPCControllerchannel,"","","");
154 }
155 timer()
156 {
157 // time to advance to next dance...make sure there is a dancer first
158 if((dancerID==NULL_KEY) || (llAvatarOnSitTarget()!=dancerID)) llSetTimerEvent(0.0); // kill timer if NPC unrezzed
159 else playNextDance();
160 }
161 on_rez(integer start)
162 {
163 // always reset on rez
165 }
166 changed(integer change)
167 {
168 // reset script if owner changes or region restarts
169 if(change & CHANGED_OWNER) llResetScript();
170 else if(change & CHANGED_REGION_START) llResetScript();
171 // handle changes in inventory that might affect operation
172 else if(change & CHANGED_INVENTORY)
173 {
174 // safety check on deleting notecard during use
175 if((llGetInventoryType(npcCard)!=INVENTORY_NOTECARD) && (dancerID==NULL_KEY))
176 {
177 llOwnerSay("You have deleted the dancer notecard. Removing the dancer");
178 removeDancer();
179 return;
180 }
181 // else see if it's a change in animations
183 if(!anims && (dancerID!=NULL_KEY))
184 {
185 // user deleted the last animation...kill active dancer
186 llOwnerSay("There are no animations in the poseball...removing your dancer");
187 removeDancer();
188 }
189 else if(anims!=llGetListLength(danceList))
190 {
191 updateDanceList();
192 if(dancerID!=NULL_KEY) startDancing();
193 }
194 }
195 // handle changes in link...will usually be triggered by the NPC sitting or being removed
196 else if(change & CHANGED_LINK)
197 {
198 // start dancing when an npc sits
199 if(dancerID!=NULL_KEY && (llAvatarOnSitTarget()==dancerID))
200 startDancing();
201 // can ignore npc standing (derez) because key reset is handled by the remove routine
202 // also ignoring any non-npc who sits here
203 }
204 }
205
206 link_message(integer sender, integer num, string str, key id)
207 {
208 if(str == "go"){
209 rezDancer();
210 } else if(str== "quit"){
211 removeDancer();
212 }
213 }
214
216 {
217 // only owner can play with this
218 if(llDetectedKey(0)!=llGetOwner()) return;
219 // first, clone owner if no appearance card has been stored
221 {
222 llOwnerSay("One moment while your appearance is saved for the npc to use");
223 osOwnerSaveAppearance(npcCard);
224 llSleep(2.0);
225 }
226 // if no dancer, rez one
227 if(dancerID==NULL_KEY)
228 {
229 if(checkForSitter()) startDancing();
230 else rezDancer();
231 }
232 // else there's a dancer so this touch means we want to remove it
233 else removeDancer();
234 }
235
236
237
238
239
240 }

NPC rotator

Script ot make a NPC rotate and walk in a circle

Category: NPC
By : Ferd Frederix
Created: 2014-09-24 Edited: 2014-09-24
Worlds: Second Life


This script by Ferd Frederix may be used in any manner, modified, and republished.  Unless specified otherwise, my scripts are always free and open source.  Objects made with these scripts may be sold with no restrictions.  All I ask is that you point others to this location should they ask you about it and to not sell this script, unless it is for $0 L. Please help improve my work by reporting bugs and improvements.

1 float RANGE = 5; // how far to sense
2 float RATE = 5; // how often
3 float SPEED = 0.1; // how fast to spin
4
5 integer running = FALSE;
6
7 doIt()
8 {
9 if(running) {
10 llTargetOmega(<0,0,1>,SPEED,1);
11 llMessageLinked(LINK_SET,1,"go","");
12 } else {
13 llTargetOmega(<0,0,0>,0,1);
14 llMessageLinked(LINK_SET,1,"quit","");
15 }
16 }
17 default
18 {
19
20 state_entry() {
21 llSensorRepeat("","", AGENT, RANGE, PI, RATE);
22 }
23
25 {
26 if(running == TRUE)
27 return; // no need to do anything
28 integer i;
29 for ( i = 0; i < n; i++) {
30 key aviKey = llDetectedKey(i);
31 if(! osIsNpc(aviKey)) {
32 running = TRUE;
33 }
34 }
35
36 doIt();
37
38 }
39
40 no_sensor() {
41 if(running == FALSE)
42 return; // no need to do anything
43
44 running = FALSE;
45 doIt();
46
47 }
48
50 {
51 running = ~ running;
52 doIt();
53
54 }
55
56 }

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