corrade-lsl-templates – Blame information for rev 29

Subversion Repositories:
Rev:
Rev Author Line No. Line
2 office 1 ///////////////////////////////////////////////////////////////////////////
29 office 2 // Copyright (C) Wizardry and Steamworks 2016 - License: CC BY 2.0 //
2 office 3 ///////////////////////////////////////////////////////////////////////////
4 //
5 // This script can be used to control Corrade's movement manually using the
6 // WSAD and arrow keys on the keyboard.
7 //
8 // For more information on Corrade, please see:
9 // http://grimore.org/secondlife/scripted_agents/corrade
10 //
11 ///////////////////////////////////////////////////////////////////////////
12  
13 ///////////////////////////////////////////////////////////////////////////
29 office 14 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 //
2 office 15 ///////////////////////////////////////////////////////////////////////////
16 string wasKeyValueGet(string k, string data) {
17 if(llStringLength(data) == 0) return "";
18 if(llStringLength(k) == 0) return "";
19 list a = llParseString2List(data, ["&", "="], []);
20 integer i = llListFindList(llList2ListStrided(a, 0, -1, 2), [ k ]);
21 if(i != -1) return llList2String(a, 2*i+1);
22 return "";
23 }
24  
25 ///////////////////////////////////////////////////////////////////////////
29 office 26 // Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 //
2 office 27 ///////////////////////////////////////////////////////////////////////////
28 string wasKeyValueEncode(list data) {
29 list k = llList2ListStrided(data, 0, -1, 2);
30 list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2);
31 data = [];
32 do {
33 data += llList2String(k, 0) + "=" + llList2String(v, 0);
34 k = llDeleteSubList(k, 0, 0);
35 v = llDeleteSubList(v, 0, 0);
36 } while(llGetListLength(k) != 0);
37 return llDumpList2String(data, "&");
38 }
39  
40 ///////////////////////////////////////////////////////////////////////////
29 office 41 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 //
2 office 42 ///////////////////////////////////////////////////////////////////////////
43 // escapes a string in conformance with RFC1738
44 string wasURLEscape(string i) {
45 string o = "";
46 do {
47 string c = llGetSubString(i, 0, 0);
48 i = llDeleteSubString(i, 0, 0);
49 if(c == "") jump continue;
50 if(c == " ") {
51 o += "+";
52 jump continue;
53 }
54 if(c == "\n") {
55 o += "%0D" + llEscapeURL(c);
56 jump continue;
57 }
58 o += llEscapeURL(c);
59 @continue;
60 } while(i != "");
61 return o;
62 }
63  
64 // configuration data
65 string configuration = "";
66  
67 default {
68 state_entry() {
69 llSetTimerEvent(1);
70 }
71 link_message(integer sender, integer num, string message, key id) {
72 if(sender != 1 || id != "configuration") return;
73 configuration = message;
74 state off;
75 }
76 timer() {
77 llMessageLinked(LINK_ROOT, 0, "configuration", NULL_KEY);
78 }
79 attach(key id) {
80 llResetScript();
81 }
82 on_rez(integer num) {
83 llResetScript();
84 }
85 changed(integer change) {
86 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START) || (change & CHANGED_OWNER)) {
87 llResetScript();
88 }
89 }
90 state_exit() {
91 llSetTimerEvent(0);
92 }
93 }
94  
95 state off {
96 state_entry() {
97 llReleaseControls();
98 llSetColor(<.5,0,0>, ALL_SIDES);
99 }
100 touch_end(integer num) {
101 state on;
102 }
103 attach(key id) {
104 llResetScript();
105 }
106 on_rez(integer num) {
107 llResetScript();
108 }
109 changed(integer change) {
110 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START) || (change & CHANGED_OWNER)) {
111 llResetScript();
112 }
113 }
114 }
115  
116 state on {
117 state_entry() {
118 llSetColor(<0,.5,0>, ALL_SIDES);
119 state detect;
120 }
121 attach(key id) {
122 llResetScript();
123 }
124 on_rez(integer num) {
125 llResetScript();
126 }
127 changed(integer change) {
128 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START) || (change & CHANGED_OWNER)) {
129 llResetScript();
130 }
131 }
132 }
133  
134 state detect {
135 state_entry() {
136 // DEBUG
137 llOwnerSay("Detecting if Corrade is on the region...");
138 if(llListFindList(
139 llGetAgentList(
140 AGENT_LIST_REGION,
141 []
142 ),
143 (list)(
144 (key)wasKeyValueGet(
145 "corrade",
146 configuration
147 )
148 )
149 ) == -1) {
150 // DEBUG
151 llOwnerSay("Corrade is not in the current region.");
152 llResetScript();
153 }
154 state joy;
155 }
156 touch_start(integer num) {
157 llSetColor(<.5,0,0>, ALL_SIDES);
158 llResetScript();
159 }
160 attach(key id) {
161 llResetScript();
162 }
163 on_rez(integer num) {
164 llResetScript();
165 }
166 changed(integer change) {
167 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START) || (change & CHANGED_OWNER)) {
168 llResetScript();
169 }
170 }
171 }
172  
173 state joy {
174 state_entry() {
175 llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
176 llSetColor(<0,0.5,0>, ALL_SIDES);
177 // DEBUG
178 llOwnerSay("Joystick on...");
179 }
180 touch_start(integer num) {
181 llSetColor(<.5,0,0>, ALL_SIDES);
182 llResetScript();
183 }
184 control(key id, integer level, integer edge) {
185 if (level & CONTROL_UP) {
186 llRegionSayTo(
187 wasKeyValueGet(
188 "corrade",
189 configuration
190 ),
191 0,
192 wasKeyValueEncode(
193 [
194 // nudges Corrade up
195 "command", "nudge",
196 "group", wasURLEscape(
197 wasKeyValueGet(
198 "group",
199 configuration
200 )
201 ),
202 "password", wasURLEscape(
203 wasKeyValueGet(
204 "password",
205 configuration
206 )
207 ),
208 "direction", "up"
209 ]
210 )
211 );
212 }
213 if (level & CONTROL_DOWN) {
214 llRegionSayTo(
215 wasKeyValueGet(
216 "corrade",
217 configuration
218 ),
219 0,
220 wasKeyValueEncode(
221 [
222 // nudges Corrade down
223 "command", "nudge",
224 "group", wasURLEscape(
225 wasKeyValueGet(
226 "group",
227 configuration
228 )
229 ),
230 "password", wasURLEscape(
231 wasKeyValueGet(
232 "password",
233 configuration
234 )
235 ),
236 "direction", "down"
237 ]
238 )
239 );
240 }
241 if (level & CONTROL_FWD) {
242 llRegionSayTo(
243 wasKeyValueGet(
244 "corrade",
245 configuration
246 ),
247 0,
248 wasKeyValueEncode(
249 [
250 // nudges Corrade forward
251 "command", "nudge",
252 "group", wasURLEscape(
253 wasKeyValueGet(
254 "group",
255 configuration
256 )
257 ),
258 "password", wasURLEscape(
259 wasKeyValueGet(
260 "password",
261 configuration
262 )
263 ),
264 "direction", "forward"
265 ]
266 )
267 );
268 }
269 if (level & CONTROL_BACK) {
270 llRegionSayTo(
271 wasKeyValueGet(
272 "corrade",
273 configuration
274 ),
275 0,
276 wasKeyValueEncode(
277 [
278 // nudges Corrade back
279 "command", "nudge",
280 "group", wasURLEscape(
281 wasKeyValueGet(
282 "group",
283 configuration
284 )
285 ),
286 "password", wasURLEscape(
287 wasKeyValueGet(
288 "password",
289 configuration
290 )
291 ),
292 "direction", "back"
293 ]
294 )
295 );
296 }
297 if ((level & CONTROL_LEFT) || (level & CONTROL_ROT_LEFT)) {
298 llRegionSayTo(
299 wasKeyValueGet(
300 "corrade",
301 configuration
302 ),
303 0,
304 wasKeyValueEncode(
305 [
306 // rotates Corrade left
307 "command", "turn",
308 "group", wasURLEscape(
309 wasKeyValueGet(
310 "group",
311 configuration
312 )
313 ),
314 "password", wasURLEscape(
315 wasKeyValueGet(
316 "password",
317 configuration
318 )
319 ),
320 "direction", "left",
321 "degrees", 0.15
322 ]
323 )
324 );
325 }
326 if ((level & CONTROL_RIGHT) || (level & CONTROL_ROT_RIGHT)) {
327 llRegionSayTo(
328 wasKeyValueGet(
329 "corrade",
330 configuration
331 ),
332 0,
333 wasKeyValueEncode(
334 [
335 // rotates Corrade right
336 "command", "turn",
337 "group", wasURLEscape(
338 wasKeyValueGet(
339 "group",
340 configuration
341 )
342 ),
343 "password", wasURLEscape(
344 wasKeyValueGet(
345 "password",
346 configuration
347 )
348 ),
349 "direction", "right",
350 "degrees", 0.15
351 ]
352 )
353 );
354 }
355 }
356 run_time_permissions(integer permissions) {
357 if (permissions & PERMISSION_TAKE_CONTROLS) {
358 llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_LEFT | CONTROL_ROT_LEFT | CONTROL_RIGHT | CONTROL_ROT_RIGHT | CONTROL_UP | CONTROL_DOWN, TRUE, FALSE);
359 // DEBUG
360 llOwnerSay("Controls seized...");
361 }
362 }
363 attach(key id) {
364 llResetScript();
365 }
366 on_rez(integer num) {
367 llResetScript();
368 }
369 changed(integer change) {
370 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START) || (change & CHANGED_OWNER)) {
371 llResetScript();
372 }
373 }
374 }