corrade-lsl-templates – Diff between revs 37 and 38

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 37 Rev 38
Line 1... Line 1...
1 /////////////////////////////////////////////////////////////////////////// 1 ///////////////////////////////////////////////////////////////////////////
2 // Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 // 2 // Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 //
3 /////////////////////////////////////////////////////////////////////////// 3 ///////////////////////////////////////////////////////////////////////////
4 // -  
5 // This is an automatic grid follower for the Corrade Second Life / OpenSim -  
6 // bot. You can find more details about the bot by following the URL: -  
7 // http://was.fm/secondlife/scripted_agents/corrade -  
8 // -  
9 // The follower script works together with a "configuration" notecard and -  
10 // that must be placed in the same primitive as this script. -  
11 // You are free to use, change, and commercialize it under the GNU/GPLv3 -  
12 // license at: http://www.gnu.org/licenses/gpl.html -  
13 // -  
14 /////////////////////////////////////////////////////////////////////////// -  
Line 15... Line 4...
15   4  
16 /////////////////////////////////////////////////////////////////////////// 5 ///////////////////////////////////////////////////////////////////////////
17 // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // 6 // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 //
18 /////////////////////////////////////////////////////////////////////////// 7 ///////////////////////////////////////////////////////////////////////////
19 string wasKeyValueGet(string k, string data) { 8 string wasKeyValueGet(string k, string data) {
20 if(llStringLength(data) == 0) return ""; 9 if(llStringLength(data) == 0) return "";
21 if(llStringLength(k) == 0) return ""; 10 if(llStringLength(k) == 0) return "";
22 list a = llParseString2List(data, ["&", "="], []); 11 list a = llParseStringKeepNulls(data, ["&", "="], []);
23 integer i = llListFindList(a, [ k ]); 12 integer i = llListFindList(llList2ListStrided(a, 0, -1, 2), [ k ]);
24 if(i != -1) return llList2String(a, i+1); 13 if(i != -1) return llList2String(a, 2*i+1);
25 return ""; 14 return "";
26 } 15 }
27 16  
28 /////////////////////////////////////////////////////////////////////////// 17 ///////////////////////////////////////////////////////////////////////////
29 // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 // 18 // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 //
30 /////////////////////////////////////////////////////////////////////////// 19 ///////////////////////////////////////////////////////////////////////////
31 string wasKeyValueEncode(list data) { 20 string wasKeyValueEncode(list data) {
Line 55... Line 44...
55 // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // 44 // Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 //
56 /////////////////////////////////////////////////////////////////////////// 45 ///////////////////////////////////////////////////////////////////////////
57 integer wasIsAvatarInSensorRange(key avatar) { 46 integer wasIsAvatarInSensorRange(key avatar) {
58 return llListFindList( 47 return llListFindList(
59 llGetAgentList( 48 llGetAgentList(
60 AGENT_LIST_REGION, 49 AGENT_LIST_REGION,
61 [] 50 []
62 ), 51 ),
63 (list)((key)avatar) 52 (list)((key)avatar)
64 ) != -1 && 53 ) != -1 &&
65 llVecDist( 54 llVecDist(
66 llGetPos(), 55 llGetPos(),
67 llList2Vector( 56 llList2Vector(
68 llGetObjectDetails( 57 llGetObjectDetails(
69 avatar, 58 avatar,
70 [OBJECT_POS] 59 [OBJECT_POS]
71 ), 60 ),
72 0 61 0
73 ) 62 )
74 ) <= 96; 63 ) <= 96;
75 } 64 }
Line 100... Line 89...
100   89  
101 // corrade data 90 // corrade data
102 string CORRADE = ""; 91 string CORRADE = "";
103 string GROUP = ""; 92 string GROUP = "";
104 string PASSWORD = ""; 93 string PASSWORD = "";
Line 105... Line 94...
105 string RANGE = ""; 94 integer RANGE = 5;
106   95  
Line 107... Line 96...
107 // for holding the callback URL 96 // for holding the callback URL
108 string callback = ""; 97 string callback = "";
109   98  
110 // for notecard reading 99 // for notecard reading
111 integer line = 0; 100 integer line = 0;
112 101  
113 // key-value data will be read into this list 102 // key-value data will be read into this list
114 list tuples = []; 103 list tuples = [];
115 104  
116 default { 105 default {
117 state_entry() { 106 state_entry() {
Line 133... Line 122...
133 return; 122 return;
134 } 123 }
135 CORRADE = llList2String( 124 CORRADE = llList2String(
136 tuples, 125 tuples,
137 llListFindList( 126 llListFindList(
138 tuples, 127 tuples,
139 [ 128 [
140 "corrade" 129 "corrade"
141 ] 130 ]
142 ) 131 )
143 +1); 132 +1);
Line 146... Line 135...
146 return; 135 return;
147 } 136 }
148 GROUP = llList2String( 137 GROUP = llList2String(
149 tuples, 138 tuples,
150 llListFindList( 139 llListFindList(
151 tuples, 140 tuples,
152 [ 141 [
153 "group" 142 "group"
154 ] 143 ]
155 ) 144 )
156 +1); 145 +1);
Line 159... Line 148...
159 return; 148 return;
160 } 149 }
161 PASSWORD = llList2String( 150 PASSWORD = llList2String(
162 tuples, 151 tuples,
163 llListFindList( 152 llListFindList(
164 tuples, 153 tuples,
165 [ 154 [
166 "password" 155 "password"
167 ] 156 ]
168 ) 157 )
169 +1); 158 +1);
170 if(GROUP == "") { 159 if(GROUP == "") {
171 llOwnerSay("Error in configuration notecard: group"); 160 llOwnerSay("Error in configuration notecard: group");
172 return; 161 return;
173 } 162 }
174 RANGE = llList2String( 163 RANGE = llList2Integer(
175 tuples, 164 tuples,
176 llListFindList( 165 llListFindList(
177 tuples, 166 tuples,
178 [ 167 [
179 "range" 168 "range"
180 ] 169 ]
181 ) 170 )
182 +1); 171 +1);
183 if(RANGE == "") { 172 if(RANGE == 0) {
184 llOwnerSay("Error in configuration notecard: range"); 173 llOwnerSay("Error in configuration notecard: range");
185 return; 174 return;
186 } 175 }
187 // DEBUG 176 // DEBUG
188 llOwnerSay("Read configuration file..."); 177 llOwnerSay("Read configuration file...");
Line 195... Line 184...
195 // get rid of starting and ending quotes 184 // get rid of starting and ending quotes
196 string k = llDumpList2String( 185 string k = llDumpList2String(
197 llParseString2List( 186 llParseString2List(
198 llStringTrim( 187 llStringTrim(
199 llList2String( 188 llList2String(
200 o, 189 o,
201 0 190 0
202 ), 191 ),
203 STRING_TRIM), 192 STRING_TRIM),
204 ["\""], [] 193 ["\""], []
205 ), "\""); 194 ), "\"");
206 string v = llDumpList2String( 195 string v = llDumpList2String(
207 llParseString2List( 196 llParseString2List(
208 llStringTrim( 197 llStringTrim(
209 llList2String( 198 llList2String(
210 o, 199 o,
211 1 200 1
212 ), 201 ),
213 STRING_TRIM), 202 STRING_TRIM),
214 ["\""], [] 203 ["\""], []
215 ), "\""); 204 ), "\"");
216 if(k == "" || v == "") jump continue; 205 if(k == "" || v == "") jump continue;
217 tuples += k; 206 tuples += k;
218 tuples += v; 207 tuples += v;
Line 226... Line 215...
226 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) { 215 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) {
227 llResetScript(); 216 llResetScript();
228 } 217 }
229 } 218 }
230 } 219 }
231 220  
232 state url { 221 state url {
233 state_entry() { 222 state_entry() {
234 // DEBUG 223 // DEBUG
235 llOwnerSay("Requesting URL..."); 224 llOwnerSay("Requesting URL...");
236 llRequestURL(); 225 llRequestURL();
Line 267... Line 256...
267 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) { 256 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) {
268 llResetScript(); 257 llResetScript();
269 } 258 }
270 } 259 }
271 } 260 }
272 261  
273 state on { 262 state on {
274 state_entry() { 263 state_entry() {
275 // set color for button 264 // set color for button
276 llSetColor(<0,1,0>, ALL_SIDES); 265 llSetColor(<0,1,0>, ALL_SIDES);
277 // if Corrade is in-range then just follow 266 // if Corrade is in-range then just follow
278 if(wasIsAvatarInSensorRange(CORRADE)) state follow; 267 if(wasIsAvatarInSensorRange(CORRADE)) {
-   268 state follow;
-   269 }
279 // DEBUG 270 // DEBUG
280 llOwnerSay("Detecting if Corrade is online..."); 271 llOwnerSay("Detecting if Corrade is online...");
281 llSetTimerEvent(5); 272 llSetTimerEvent(5);
282 } 273 }
283 timer() { 274 timer() {
284 llRequestAgentData((key)CORRADE, DATA_ONLINE); 275 llRequestAgentData(CORRADE, DATA_ONLINE);
285 } 276 }
286 dataserver(key id, string data) { 277 dataserver(key id, string data) {
287 if(data != "1") { 278 if(data != "1") {
288 // DEBUG 279 // DEBUG
289 llOwnerSay("Corrade is not online, sleeping..."); 280 llOwnerSay("Corrade is not online, sleeping...");
290 llSetTimerEvent(30); 281 llSetTimerEvent(30);
291 return; 282 return;
292 } 283 }
293 llSensorRepeat("", (key)CORRADE, AGENT, (integer)RANGE, TWO_PI, 5); 284 llSensorRepeat("", CORRADE, AGENT, RANGE, TWO_PI, 5);
294 } 285 }
295 no_sensor() { 286 no_sensor() {
296 // DEBUG 287 // DEBUG
297 llOwnerSay("Teleporting Corrade..."); 288 llOwnerSay("Teleporting Corrade...");
298 llInstantMessage((key)CORRADE, 289 llInstantMessage(CORRADE,
299 wasKeyValueEncode( 290 wasKeyValueEncode(
300 [ 291 [
301 "command", "teleport", 292 "command", "teleport",
302 "group", wasURLEscape(GROUP), 293 "group", wasURLEscape(GROUP),
303 "password", wasURLEscape(PASSWORD), 294 "password", wasURLEscape(PASSWORD),
Line 308... Line 299...
308 ] 299 ]
309 ) 300 )
310 ); 301 );
311 } 302 }
312 sensor(integer num) { 303 sensor(integer num) {
313 llSetTimerEvent(0); -  
314 state follow; 304 state follow;
315 } 305 }
316 http_request(key id, string method, string body) { 306 http_request(key id, string method, string body) {
317 llHTTPResponse(id, 200, "OK"); 307 llHTTPResponse(id, 200, "OK");
318 if(wasKeyValueGet("command", body) != "teleport" || 308 if(wasKeyValueGet("command", body) == "teleport") {
319 wasKeyValueGet("success", body) != "True") { 309 integer success = wasKeyValueGet("success", body) == "True";
-   310 if(success) {
-   311 // DEBUG
-   312 llOwnerSay("Teleport succeeded...");
-   313 state follow;
-   314 }
320 // DEBUG 315 // DEBUG
321 llOwnerSay("Teleport failed..."); 316 llOwnerSay("Teleport failed...");
322 return; 317 return;
323 } 318 }
324 llSetTimerEvent(0); -  
325 state follow; -  
326 } 319 }
327 on_rez(integer num) { 320 on_rez(integer num) {
328 llResetScript(); 321 llResetScript();
329 } 322 }
330 changed(integer change) { 323 changed(integer change) {
331 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) { 324 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) {
332 llResetScript(); 325 llResetScript();
333 } 326 }
334 } 327 }
-   328 state_exit() {
-   329 llSetTimerEvent(0);
-   330 }
335 } 331 }
336 332  
337 state follow { 333 state follow {
338 state_entry() { 334 state_entry() {
339 // DEBUG 335 // DEBUG
340 llOwnerSay("In follow state..."); 336 llOwnerSay("In follow state...");
341 // check every second whether Corrade is online 337 // check every second whether Corrade is online
Line 346... Line 342...
346 } 342 }
347 dataserver(key id, string data) { 343 dataserver(key id, string data) {
348 // if Corrade is not online 344 // if Corrade is not online
349 if(data != "1") state on; 345 if(data != "1") state on;
350 // Corrade is online, so attempt to dectect 346 // Corrade is online, so attempt to dectect
351 llSensorRepeat("", CORRADE, AGENT, (integer)RANGE, TWO_PI, 1); 347 llSensorRepeat("", CORRADE, AGENT, RANGE, TWO_PI, 1);
352 } 348 }
353 no_sensor() { 349 no_sensor() {
354 // check if Corrade is in range, and if not, start detecting 350 // check if Corrade is in range, and if not, start detecting
355 if(!wasIsAvatarInSensorRange(CORRADE)) state on; 351 if(!wasIsAvatarInSensorRange(CORRADE)) {
-   352 state on;
-   353 }
356 // Corrade is in sensor range, so execute move. 354 // Corrade is in sensor range, so execute move.
357 llInstantMessage(CORRADE, 355 llInstantMessage(CORRADE,
358 wasKeyValueEncode( 356 wasKeyValueEncode(
359 [ 357 [
360 "command", "walkto", 358 "command", "walkto",
361 "group", wasURLEscape(GROUP), 359 "group", wasURLEscape(GROUP),
362 "password", wasURLEscape(PASSWORD), 360 "password", wasURLEscape(PASSWORD),
Line 376... Line 374...
376 changed(integer change) { 374 changed(integer change) {
377 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) { 375 if((change & CHANGED_INVENTORY) || (change & CHANGED_REGION_START)) {
378 llResetScript(); 376 llResetScript();
379 } 377 }
380 } 378 }
381 } -  
382   379 }
-   380