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

Subversion Repositories:
Rev:
Show entire fileRegard 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 "";
Line 26... Line 15...
26 } 15 }
27 16  
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
Line 169... Line 158...
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 273... Line 262...
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 }
Line 336... Line 332...
336 332  
337 state follow { 333 state follow {
338 state_entry() { 334 state_entry() {
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",