Skip to content

Instantly share code, notes, and snippets.

@TechplexEngineer
Last active March 15, 2017 02:21
Show Gist options
  • Save TechplexEngineer/044e54fbb6204969e5d4342606784192 to your computer and use it in GitHub Desktop.
Save TechplexEngineer/044e54fbb6204969e5d4342606784192 to your computer and use it in GitHub Desktop.
v1.1
//v1.1
//Settings
float SCAN_DELAY = 60; //seconds
integer DEBUG = TRUE;
string location = "";
float SCAN_RANGE = 32;
//Constants
string baseURL = "https://docs.google.com/forms/d/e/<GOOGLE_SHEET_ID>/formResponse?";
key reqid = NULL_KEY;
//Functions
string getURL(string location, key detectedUser) {
return baseURL + "entry.1716462376=" +llEscapeURL(location) +"&entry.1620137166="+llEscapeURL(detectedUser)+"&entry.1704504228="+llEscapeURL(llKey2Name(detectedUser));
}
debugSay(string msg) {
if(DEBUG) {
llOwnerSay(msg);
}
}
list avatarsInRegion = [];
send_data()
{
key avatar = llList2Key( avatarsInRegion, 0);
avatarsInRegion = llDeleteSubList(avatarsInRegion, 0, 1);
string url = getURL(location, avatar);
debugSay("URL IS: "+url);
reqid = llHTTPRequest(url, [], "");
if (reqid == NULL_KEY) //we hit the throttle
{
llSleep(45); //to clear the throttle wait at leat 40 seconds.
send_data();
}
}
start_scanner() {
llSensorRemove();
llSensorRepeat( "", "", AGENT, SCAN_RANGE, TWO_PI, SCAN_DELAY );
}
default {
on_rez(integer start_param)
{
llResetScript();
}
state_entry()
{
location = llGetObjectDesc();
if (llStringLength(location) == 0 || location == "(No Description)") {
llOwnerSay("Description is Empty, Halting. Set Description and reset script");
return;
}
llOwnerSay("Starting Logging data for location: "+location);
start_scanner();
}
sensor( integer number_detected )
{
debugSay("Detected: "+(string)number_detected);
integer i;
for( i = 0; i < number_detected; i++ )
{
key detected_key = llDetectedKey( i );
debugSay("Detected: "+(string)i +" "+(string)detected_key);
avatarsInRegion += (string)detected_key;
}
llSensorRemove();
debugSay(llDumpList2String(avatarsInRegion, ","));
send_data();
}
http_response(key request_id, integer status, list metadata, string body)
{
if (reqid == request_id)
{
reqid = NULL_KEY;
debugSay("Reply: "+(string)status);
llSleep(1); //seconds
if (llGetListLength(avatarsInRegion) != 0) {
send_data();
} else {
debugSay("Timer Set, all data sent");
start_scanner();
}
}
else
{
debugSay("Invalid Key");
}
}
}
//v1.1
//Settings
float SCAN_DELAY = 60; //seconds
integer DEBUG = FALSE;
string location = "";
//Constants
string baseURL = "https://docs.google.com/forms/d/e/<GOOGLE_SHEET_ID>/formResponse?";
key reqid = NULL_KEY;
//Functions
string getURL(string location, key detectedUser) {
return baseURL + "entry.1716462376=" +location +"&entry.1620137166="+llEscapeURL(detectedUser)+"&entry.1704504228="+llEscapeURL(llKey2Name(detectedUser));
}
debugSay(string msg) {
if(DEBUG) {
llOwnerSay(msg);
}
}
list avatarsInRegion = [];
send_data()
{
llSetTimerEvent(0);
//the first time called fill the array
if (llGetListLength(avatarsInRegion) == 0) {
avatarsInRegion = llGetAgentList(AGENT_LIST_REGION, []);
}
key avatar = llList2Key( avatarsInRegion, 0);
avatarsInRegion = llDeleteSubList(avatarsInRegion, 0, 1);
string url = getURL(location, avatar);
// debugSay("URL IS: "+url);
reqid = llHTTPRequest(url, [], "");
if (reqid == NULL_KEY) //we hit the throttle
{
llSleep(45); //to clear the throttle wait at leat 40 seconds.
send_data();
}
}
default {
on_rez(integer start_param)
{
llResetScript();
}
state_entry()
{
location = llGetObjectDesc();
if (llStringLength(location) == 0 || location == "(No Description)") {
llOwnerSay("Description is Empty, Halting. Set Description and reset script");
return;
}
llOwnerSay("Starting");
send_data(); //this will also start the timer.
}
timer()
{
send_data();
}
http_response(key request_id, integer status, list metadata, string body)
{
if (reqid == request_id)
{
reqid = NULL_KEY;
debugSay("Reply: "+(string)status);
llSleep(1); //seconds
if (llGetListLength(avatarsInRegion) != 0) {
send_data();
} else {
debugSay("Timer Set, all data sent");
llSetTimerEvent(SCAN_DELAY);
}
}
else
{
debugSay("Invalid Key");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment