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
Positioning Simple_Path_Script  

Simple_Path_Script

Path Setting Script //
In 'edit' mode, user moves the object and 'saves' various positions
over time, then the positions can be replayed. This either uses the physical
move functions to create smooth movement or non-physical movements
for a slightly more jerky movement! //
NOTE: Positions and rotations are relative to the region, so if you
move the prim, then the positions won't move with it - you'd have to
reset the script (using the 'reset' button) and store a new path. //
Depending on the settings, the system can either loop forever
or play just once. //
It also has the option of resetting if you change owners, which
might be useful if you want new owners to be able to store their
own paths. //
Kimm Paulino
Oct 2010

Copyright © 2009 Linden Research, Inc. Licensed under Creative Commons Attribution-Share Alike 3.0 From the Sl wiki at http://wiki.secondlife.com/wiki/User:Kimm_Paulino/Scripts#Simple_Path_Script

Category: Positioning
By : Kimm Paulino
Created: 2013-06-24 Edited: 2013-06-24
Worlds: Second Life

the Zip file

Download all files for Simple_Path_Script
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. Simple_Path_Script_1.lsl
1
2
3 integer gDebug = FALSE;
4 integer gPhysics = FALSE; // Set to use physical movements
5 integer gLoop = TRUE; // Set to continually loop through the movements
6 integer gResetOnOwnerChange = TRUE; // Set if want script to auto reset when changing owners
7
8 list gPositionData; // Always assume that there are the same numbers
9 list gRotationData; // of position and rotation data points
10 integer gCurrentIdx;
11 float gTimePeriod = 2.0;
12 float gTau = 5.0;
13 key gOwnerId;
14 integer gListen;
15 integer gTimeHandle;
16 integer gTauHandle;
17 string gHelpMsg = "Use EDIT mode to move your object, selecting 'Save' to save each position. Select 'Done' once complete. Don't forget to save your first position too!";
18 string gErrorMsg = "Something unexpected went wrong, suggest you reset the script!";
19 string SAVE_BTN = "Save";
20 string DONE_BTN = "Done";
21 string TIME_BTN = "Time Adjust";
22 string TAU_BTN = "Tau Adjust";
23 string RESET_BTN = "Reset";
24 string START_BTN = "Start";
25 string STOP_BTN = "Stop";
26 string START_MSG = "start"; // What a passer by can type in via chat
27 integer LISTEN_CH = 600;
28 integer TIME_CH = 900;
29 integer TAU_CH = 901;
30
31 doDebug (string msg)
32 {
33 if(gDebug)
34 {
35 llOwnerSay(msg);
36 }
37 }
38
39 doMove()
40 {
41 integer num_points = llGetListLength(gPositionData);
42 if(num_points != llGetListLength(gRotationData))
43 {
44 llOwnerSay(gErrorMsg);
45 disableMove();
46 return;
47 }
48
49 if(gCurrentIdx >= num_points)
50 {
51 if(gLoop)
52 {
53 // Loop around for another go
54 gCurrentIdx = 0;
55 }
56 else
57 {
58 // All complete
59 disableMove();
60 return;
61 }
62 }
63
64 doDebug ("Moving to position " + (string)gCurrentIdx);
65
66 vector next_pos = llList2Vector(gPositionData, gCurrentIdx);
67 rotation next_rot = llList2Rot(gRotationData, gCurrentIdx);
68
69 if(next_pos == ZERO_VECTOR && next_rot == ZERO_ROTATION)
70 {
71 // ignore
72 }
73 else
74 {
75 if(gPhysics)
76 {
77 llMoveToTarget(next_pos, gTau);
78 llLookAt(next_pos,1,1);
79 llRotLookAt(next_rot,1,1);
80 }
81 else
82 {
83 // doDebug ("moving to: " + (string)next_pos);
84 llSetRot(next_rot);
85 llSetPos(next_pos);
86 }
87 }
88
89 // Move on to the next point
90 gCurrentIdx ++;
91 }
92
93 dialog ()
94 {
95 list buttons;
96 if(gPhysics)
97 {
98 buttons = [SAVE_BTN, DONE_BTN, RESET_BTN, START_BTN, STOP_BTN, TIME_BTN, TAU_BTN];
99 }
100 else
101 {
102 buttons = [SAVE_BTN, DONE_BTN, RESET_BTN, START_BTN, STOP_BTN, TIME_BTN];
103 }
104 llDialog(gOwnerId, gHelpMsg, buttons, LISTEN_CH);
105 }
106
107 enableMove ()
108 {
109 if(gPhysics)
110 {
111 doDebug ("Enabling physical move");
113 }
114 else
115 {
116 doDebug ("Enabling non-physical move");
118 }
119 llSetTimerEvent(gTimePeriod);
120 gCurrentIdx = 0;
121 doMove ();
122 }
123
124 disableMove ()
125 {
126 doDebug ("Disabling move");
128 llSetTimerEvent(0.0);
129 }
130
131 default
132 {
133 on_rez (integer start_param)
134 {
135 // if we reset on rez, then a user can't take an object into
136 // inventory have rerez it with the same path stored.
137 //
138 // Means that if they do want to clear the path, say because
139 // the position in the Sim has changed, then they have to use
140 // the 'reset' option.
141 }
142
144 {
145 llOwnerSay("Ready to start saving positions. Touch for menu, then go to SL Edit mode to move the object and use 'save' on the menu to save each position.");
146 gOwnerId = llGetOwner();
147 }
148
150 {
151 gListen = llListen(LISTEN_CH,"",NULL_KEY,"");
152 if(llDetectedKey(0) == gOwnerId)
153 {
154 dialog();
155 }
156 else
157 {
158 if(!gLoop)
159 {
160 // Let nearby users start the moving
161 llWhisper(0, "To start the movement, please type the following into local chat: /" + (string)LISTEN_CH + " " + START_MSG);
162 }
163 }
164 }
165
166 listen (integer channel, string name, key id, string msg)
167 {
168 vector pos = llGetPos();
169 rotation rot = llGetRot();
170
171 if(channel == LISTEN_CH)
172 {
173 if(msg == START_BTN || msg == START_MSG)
174 {
175 enableMove();
176 }
177
178 // non-owners can't do anything else
179 if(id != gOwnerId)
180 {
181 return;
182 }
183
184 if(msg == SAVE_BTN)
185 {
186 gPositionData += pos;
187 gRotationData += rot;
188 dialog ();
189 }
190 else if(msg == STOP_BTN)
191 {
192 disableMove();
193 }
194 else if(msg == RESET_BTN)
195 {
197 }
198 else if(msg == TIME_BTN)
199 {
200 gTimeHandle = llListen(TIME_CH, "", gOwnerId, "");
201 llOwnerSay("Adjust time using: /" + (string)TIME_CH + " <float seconds>");
202 }
203 else if(msg == TAU_BTN)
204 {
205 gTauHandle = llListen(TAU_CH, "", gOwnerId, "");
206 llOwnerSay("Adjust Tau using: /" + (string)TAU_CH + " <float value>");
207 }
208 else if(msg == DONE_BTN)
209 {
210 llOwnerSay("To reset use: /" + (string)LISTEN_CH + " reset");
211 llOwnerSay("To start use: /" + (string)LISTEN_CH + " start");
212 }
213 }
214
215 if(channel == TIME_CH)
216 {
217 gTimePeriod = (float)msg;
218 llListenRemove(gTimeHandle);
219 llOwnerSay("Time period set to " + msg);
220 }
221
222 if(channel == TAU_CH)
223 {
224 gTau = (float)msg;
225 llListenRemove(gTauHandle);
226 llOwnerSay("Tau set to " + msg);
227 }
228 }
229
231 {
232 if(ch & CHANGED_OWNER)
233 {
234 if(gResetOnOwnerChange)
235 {
236 // This will clear out all stored positions of course!
238 }
239 }
240 }
241
242 timer()
243 {
244 doMove();
245 }
246 }

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