corrade-lsl-templates

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 37  →  ?path2? @ 38
/source/grid-follow/grid-follow.lsl
@@ -1,30 +1,19 @@
///////////////////////////////////////////////////////////////////////////
// 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 "";
}
 
///////////////////////////////////////////////////////////////////////////
// Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 //
///////////////////////////////////////////////////////////////////////////
@@ -57,18 +46,18 @@
integer wasIsAvatarInSensorRange(key avatar) {
return llListFindList(
llGetAgentList(
AGENT_LIST_REGION,
AGENT_LIST_REGION,
[]
),
),
(list)((key)avatar)
) != -1 &&
) != -1 &&
llVecDist(
llGetPos(),
llGetPos(),
llList2Vector(
llGetObjectDetails(
avatar,
avatar,
[OBJECT_POS]
),
),
0
)
) <= 96;
@@ -102,7 +91,7 @@
string CORRADE = "";
string GROUP = "";
string PASSWORD = "";
string RANGE = "";
integer RANGE = 5;
 
// for holding the callback URL
string callback = "";
@@ -109,10 +98,10 @@
 
// for notecard reading
integer line = 0;
 
// key-value data will be read into this list
list tuples = [];
 
default {
state_entry() {
// set color for button
@@ -135,7 +124,7 @@
CORRADE = llList2String(
tuples,
llListFindList(
tuples,
tuples,
[
"corrade"
]
@@ -148,7 +137,7 @@
GROUP = llList2String(
tuples,
llListFindList(
tuples,
tuples,
[
"group"
]
@@ -161,7 +150,7 @@
PASSWORD = llList2String(
tuples,
llListFindList(
tuples,
tuples,
[
"password"
]
@@ -171,16 +160,16 @@
llOwnerSay("Error in configuration notecard: group");
return;
}
RANGE = llList2String(
RANGE = llList2Integer(
tuples,
llListFindList(
tuples,
tuples,
[
"range"
]
)
+1);
if(RANGE == "") {
if(RANGE == 0) {
llOwnerSay("Error in configuration notecard: range");
return;
}
@@ -197,10 +186,10 @@
llParseString2List(
llStringTrim(
llList2String(
o,
o,
0
),
STRING_TRIM),
),
STRING_TRIM),
["\""], []
), "\"");
string v = llDumpList2String(
@@ -207,10 +196,10 @@
llParseString2List(
llStringTrim(
llList2String(
o,
o,
1
),
STRING_TRIM),
),
STRING_TRIM),
["\""], []
), "\"");
if(k == "" || v == "") jump continue;
@@ -228,7 +217,7 @@
}
}
}
 
state url {
state_entry() {
// DEBUG
@@ -269,19 +258,21 @@
}
}
}
 
state on {
state_entry() {
// 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,8 +325,11 @@
llResetScript();
}
}
state_exit() {
llSetTimerEvent(0);
}
}
 
state follow {
state_entry() {
// DEBUG
@@ -348,13 +344,15 @@
// 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,
llInstantMessage(CORRADE,
wasKeyValueEncode(
[
"command", "walkto",
@@ -378,4 +376,4 @@
llResetScript();
}
}
}
}