Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Script by Gayngel of The Script Yard.
- //Join The Script Yard Group: secondlife:///app/group/4921b4f0-c21e-7866-c0c2-791d10bb5502/about
- //Visit The Script Yard Marketplace: https://marketplace.secondlife.com/stores/149734
- // This is a simple dropbox system. Redelivery systems will request redeliveries of the object you have stored in it and the drop box will deliver the object to avatar who requested a redelivery.
- // The drop box saves it's url to a Google Sheet via Google App Script. The redelivery client will request the url of the drop box from the spreadsheet and then request a redeivery from the drop box.
- // Get the Google App Script from https://pastebin.com/Cc9ZbYyj and follow the instructions in the app script to setup.
- // Once set up paste the app url below.
- string app_url = "https://script.google.com/macros/s/AKfycbyX-qKC0mpHFSa8iMDMBQyQtKzGQMdtxyICF5-pF2cebpm_HmU/exec"; // place the url of Google App Script here.
- string spreadsheet = ""; // The Google App Script will create a spreadsheet in your Google Drive to store the url of the drop box. You can write a name here or leave it blank. If you leave the string blank the spreadsheet will automatically be called the "NameOfParcelDropBoxIsOn Dropbox".
- list parceldetails;
- string parcelname;
- string url;
- key reqURL;
- key http_req;
- key sheet_req;
- integer allow =FALSE;
- default
- {
- on_rez(integer start_param)
- {
- llSetObjectDesc("");
- llResetScript();
- }
- state_entry()
- {
- allow = FALSE; // verbosity just in case
- llReleaseURL(url); // verbosity just in case
- parceldetails = llGetParcelDetails(llGetPos(),[PARCEL_DETAILS_NAME]);
- parcelname = llList2String(parceldetails,0);
- reqURL =llRequestURL();
- }
- http_request(key id, string method, string body)
- {
- if (id == reqURL)
- {
- if (method == URL_REQUEST_DENIED)
- llOwnerSay("The following error occurred while attempting to get a free URL for this device:\n \n" + body);
- else if (method == URL_REQUEST_GRANTED)
- {
- url = body;
- }
- if(app_url != "")
- {
- http_req = llHTTPRequest(app_url+"?server_url="+url+"&obj_key="+(string)llGetKey(),[HTTP_METHOD,"GET"],""); // send the server's url to the spreadsheet to be stored.
- }
- else
- llOwnerSay("Please add the URL of the Google App Script at the top of the script");
- } // if (id == reqURL)
- else if (method == "POST")
- {
- list tmp = llParseString2List(body,["="],[""]);
- string cmd = llToLower(llList2String(tmp,0));
- string ref = llList2String(tmp,1);
- if(cmd == "url_ok")
- {
- string ssID = llGetObjectDesc();
- if(ssID == "") // if the spreadsheet doesn't exist create one
- {
- if(spreadsheet == "")
- {
- spreadsheet = parcelname + " drop box.";
- }
- llOwnerSay("Creating spreadsheet named " + spreadsheet);
- if(app_url != "")
- sheet_req = llHTTPRequest(app_url+ "?url="+url+"&spreadsheet=" + llEscapeURL(spreadsheet),[HTTP_METHOD,"POST"],"Create"); // instruct the App Script to create a spreadsheet
- }
- else if(ssID != "") // if the spreadsheet exists
- {
- llOwnerSay("The spreadsheet database is ready.");
- llOwnerSay("This drop box will now allow redeliveries");
- allow = TRUE;
- sheet_req = llHTTPRequest(app_url+ "?url="+url,[HTTP_METHOD,"POST"],"Send_URL"); // update the url of the server and store in the spreadsheet
- }
- } //if(cmd == "url_ok")
- else if(cmd == "url_invalid")
- {
- llSetObjectDesc("");
- llOwnerSay("Can not save this server's URL to the spreadsheet as the Google App Script is tied to another server. Please create a new app script and paste it's url at the top of the script.");
- }
- else if(cmd == "spreadsheetready")
- {
- llSetObjectDesc(ref);
- llOwnerSay("The spreadsheet database has been created.");
- allow = TRUE;
- sheet_req = llHTTPRequest(app_url+ "?url="+url,[HTTP_METHOD,"POST"],"Send_URL");
- llOwnerSay("This drop box will now allow redeliveries");
- }
- else if(cmd == "url_added")
- {
- llOwnerSay("The url of your server has been updated in the spreadsheet database.");
- }
- else if(cmd == "request_redelivery")
- {
- key av = (key)ref;
- if(allow == TRUE)
- {
- if(llGetInventoryNumber(INVENTORY_OBJECT) > 0) // if the drop box contains an object
- {
- llInstantMessage(av,"Redelivering your object.");
- string obj = llGetInventoryName(INVENTORY_OBJECT,0);
- llGiveInventory(av,obj);
- llHTTPResponse(id,200,"redelivery_complete");
- }
- else
- llInstantMessage(av,"Sorry there is nothing to redeliver");
- }
- } //else if(cmd == "request_redelivery")
- } // method is post
- }
- changed(integer change)
- {
- if(change & CHANGED_REGION_START || change & CHANGED_REGION || change & CHANGED_INVENTORY || change & CHANGED_TELEPORT)
- {
- llReleaseURL(url); // verbosity just in case
- llResetScript();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement