/////////////////////////////////////////////////////////////////////////// // Copyright (C) Wizardry and Steamworks 2013 - License: GNU GPLv3 // // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // // rights of fair usage, the disclaimer and warranty conditions. // /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// // CONFIGURATION // /////////////////////////////////////////////////////////////////////////// // Set this to the website URL string URL_TO_WEBSITE = ""; /////////////////////////////////////////////////////////////////////////// // INTERNALS // /////////////////////////////////////////////////////////////////////////// key nQuery = NULL_KEY; integer nLine = 0; list qList = []; string question = ""; default { state_entry() { integer itra = llGetInventoryNumber(INVENTORY_NOTECARD)-1; do { if(llGetInventoryName(INVENTORY_NOTECARD, itra) == "Questions") jump found_notecard; } while(--itra>0); llOwnerSay("Failed to find notecard."); return; @found_notecard; nQuery = llGetNotecardLine("Questions", nLine); } dataserver(key id, string data) { if(id != nQuery) return; if(data == EOF) state questionnaire; if(data == "") jump next_line; qList += data; @next_line; nQuery = llGetNotecardLine("Questions", ++nLine); } changed(integer change) { if(change & CHANGED_INVENTORY) llResetScript(); } on_rez(integer num) { llResetScript(); } } state questionnaire { state_entry() { llListen(0, "", "", ""); } touch_start(integer num) { question = llList2String(qList, 0); qList = llDeleteSubList(qList, 0, 0); qList += question; llSay(0, question); } listen(integer channel, string name, key id, string message) { nQuery = llHTTPRequest("http://" + URL_TO_WEBSITE + "/radio.php?q=" + llEscapeURL(question) + "&v=" + llEscapeURL(name) + "&a=" + llEscapeURL(message), [], ""); } http_response(key request_id, integer status, list metadata, string body) { if(nQuery != request_id) return; if(body == "OK") return; llSay(DEBUG_CHANNEL, "Could not contact radio website. Please contact support."); } changed(integer change) { if(change & CHANGED_INVENTORY) llResetScript(); } on_rez(integer num) { llResetScript(); } }