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 = "https://script.google.com/macros/s/AKfycbyX-qKC0mpHFSa8iMDMBQyQtKzGQMdtxyICF5-pF2cebpm_HmU/exec"; // place the url of Google App Script here.
- string url;
- key reqURL;
- key server_req;
- key app_req;
- integer allow =FALSE;
- integer wait = FALSE; // if someone is using the terminal the next user must wait their turn
- integer listen_chan;
- integer listen_handle;
- key recipient;
- default
- {
- on_rez(integer start_param)
- {
- llResetScript();
- }
- state_entry()
- {
- allow = FALSE; // verbosity just in case
- llReleaseURL(url); // verbosity just in case
- 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 != "")
- {
- llOwnerSay("This terminal can now request redeliveries");
- allow = TRUE;
- }
- else
- llOwnerSay("Please add the URL of the Google App Script at the top of the script");
- }
- }
- else if(id == server_req)
- {
- if(body == "redelivery_ok")
- {
- wait = TRUE; // verbosity just in case
- allow = TRUE; // verbosity just in case
- llListenRemove(listen_handle); // verbosity just in case
- }
- }
- else if(method == "POST")
- {
- list tmp = llParseString2List(body,["="],[""]);
- string cmd = llToLower(llList2String(tmp,0));
- string ref = llList2String(tmp,1);
- if(cmd == "server_url")
- {
- server_req = llHTTPRequest(llUnescapeURL(ref),[HTTP_METHOD,"POST"],"request_redelivery="+(string)recipient); // instruct server to redeliver object
- llOwnerSay("Requesting redelivery from server please wait...");
- llSetTimerEvent(0.0);
- llSetTimerEvent(10.0);
- }
- }
- }
- http_response(key id, integer status, list metadata ,string body)
- {
- if(body == "redelivery_complete")
- {
- llOwnerSay("Delivery successful");
- llSetTimerEvent(0.0);
- // redelivery was successful
- // do other stuff here
- }
- }
- touch_end(integer num)
- {
- key toucher = llDetectedKey(0);
- if(allow == TRUE)
- {
- if(wait == FALSE)
- {
- wait = TRUE; // other users must wait their turn
- llListenRemove(listen_handle);
- listen_chan = ((integer)("0x"+llGetSubString((string)toucher,-8,-1)) - 723) | 0x8000000;
- listen_handle = llListen(listen_chan,"",toucher,"");
- llDialog(toucher,"\nSelect redeliver to redeliver your object.",["Redeliver"],listen_chan);
- }
- else
- {
- llRegionSayTo(toucher,0,"Someone is already using this terminal, please wait.");
- }
- }
- else
- {
- llRegionSayTo(toucher,0,"This redelivery terminal is currently offline.");
- }
- }
- listen(integer chan, string name, key id, string msg)
- {
- if(chan == listen_chan)
- {
- if(msg == "Redeliver")
- {
- llListenRemove(listen_handle);
- wait = FALSE; //allow next user to use the terminal
- allow = TRUE; // verbosity just in case
- //http request to google app script to get url of drop box
- recipient = id;
- app_req = llHTTPRequest(app+"?client_url="+url,[HTTP_METHOD,"GET"],""); // request url of server from spreadsheet database
- }
- }
- }
- timer()
- {
- llSetTimerEvent(0.0);
- llInstantMessage(recipient,"There was no response from the server. Please try again.");
- }
- 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