/source/grid-follow/grid-follow.lsl |
@@ -1,27 +1,16 @@ |
/////////////////////////////////////////////////////////////////////////// |
// Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 // |
/////////////////////////////////////////////////////////////////////////// |
// |
// This is an automatic grid follower for the Corrade Second Life / OpenSim |
// bot. You can find more details about the bot by following the URL: |
// http://was.fm/secondlife/scripted_agents/corrade |
// |
// The follower script works together with a "configuration" notecard and |
// that must be placed in the same primitive as this script. |
// You are free to use, change, and commercialize it under the GNU/GPLv3 |
// license at: http://www.gnu.org/licenses/gpl.html |
// |
/////////////////////////////////////////////////////////////////////////// |
|
/////////////////////////////////////////////////////////////////////////// |
// Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // |
// Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // |
/////////////////////////////////////////////////////////////////////////// |
string wasKeyValueGet(string k, string data) { |
if(llStringLength(data) == 0) return ""; |
if(llStringLength(k) == 0) return ""; |
list a = llParseString2List(data, ["&", "="], []); |
integer i = llListFindList(a, [ k ]); |
if(i != -1) return llList2String(a, i+1); |
list a = llParseStringKeepNulls(data, ["&", "="], []); |
integer i = llListFindList(llList2ListStrided(a, 0, -1, 2), [ k ]); |
if(i != -1) return llList2String(a, 2*i+1); |
return ""; |
} |
|
@@ -102,7 +91,7 @@ |
string CORRADE = ""; |
string GROUP = ""; |
string PASSWORD = ""; |
string RANGE = ""; |
integer RANGE = 5; |
|
// for holding the callback URL |
string callback = ""; |
@@ -171,7 +160,7 @@ |
llOwnerSay("Error in configuration notecard: group"); |
return; |
} |
RANGE = llList2String( |
RANGE = llList2Integer( |
tuples, |
llListFindList( |
tuples, |
@@ -180,7 +169,7 @@ |
] |
) |
+1); |
if(RANGE == "") { |
if(RANGE == 0) { |
llOwnerSay("Error in configuration notecard: range"); |
return; |
} |
@@ -275,13 +264,15 @@ |
// set color for button |
llSetColor(<0,1,0>, ALL_SIDES); |
// if Corrade is in-range then just follow |
if(wasIsAvatarInSensorRange(CORRADE)) state follow; |
if(wasIsAvatarInSensorRange(CORRADE)) { |
state follow; |
} |
// DEBUG |
llOwnerSay("Detecting if Corrade is online..."); |
llSetTimerEvent(5); |
} |
timer() { |
llRequestAgentData((key)CORRADE, DATA_ONLINE); |
llRequestAgentData(CORRADE, DATA_ONLINE); |
} |
dataserver(key id, string data) { |
if(data != "1") { |
@@ -290,12 +281,12 @@ |
llSetTimerEvent(30); |
return; |
} |
llSensorRepeat("", (key)CORRADE, AGENT, (integer)RANGE, TWO_PI, 5); |
llSensorRepeat("", CORRADE, AGENT, RANGE, TWO_PI, 5); |
} |
no_sensor() { |
// DEBUG |
llOwnerSay("Teleporting Corrade..."); |
llInstantMessage((key)CORRADE, |
llInstantMessage(CORRADE, |
wasKeyValueEncode( |
[ |
"command", "teleport", |
@@ -310,19 +301,21 @@ |
); |
} |
sensor(integer num) { |
llSetTimerEvent(0); |
state follow; |
} |
http_request(key id, string method, string body) { |
llHTTPResponse(id, 200, "OK"); |
if(wasKeyValueGet("command", body) != "teleport" || |
wasKeyValueGet("success", body) != "True") { |
if(wasKeyValueGet("command", body) == "teleport") { |
integer success = wasKeyValueGet("success", body) == "True"; |
if(success) { |
// DEBUG |
llOwnerSay("Teleport succeeded..."); |
state follow; |
} |
// DEBUG |
llOwnerSay("Teleport failed..."); |
return; |
} |
llSetTimerEvent(0); |
state follow; |
} |
on_rez(integer num) { |
llResetScript(); |
@@ -332,7 +325,10 @@ |
llResetScript(); |
} |
} |
state_exit() { |
llSetTimerEvent(0); |
} |
} |
|
state follow { |
state_entry() { |
@@ -348,11 +344,13 @@ |
// if Corrade is not online |
if(data != "1") state on; |
// Corrade is online, so attempt to dectect |
llSensorRepeat("", CORRADE, AGENT, (integer)RANGE, TWO_PI, 1); |
llSensorRepeat("", CORRADE, AGENT, RANGE, TWO_PI, 1); |
} |
no_sensor() { |
// check if Corrade is in range, and if not, start detecting |
if(!wasIsAvatarInSensorRange(CORRADE)) state on; |
if(!wasIsAvatarInSensorRange(CORRADE)) { |
state on; |
} |
// Corrade is in sensor range, so execute move. |
llInstantMessage(CORRADE, |
wasKeyValueEncode( |