query.lsl 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. string queryRequestURL = "[Insert your full URL here]";
  2. integer listener = 0;
  3. integer CHAT_CHANNEL = 5;
  4. key http_request_id;
  5. key avatar;
  6. default
  7. {
  8. state_entry()
  9. {
  10. llSetText("Touch to get an avatar UUID from Second Life®", <1,1,1>, 1);
  11. }
  12. touch_start(integer howmany)
  13. {
  14. if (listener == 0)
  15. {
  16. avatar = llDetectedKey(0);
  17. listener = llListen(CHAT_CHANNEL, "", avatar, "");
  18. llSetText("In use by " + llDetectedName(0), <1,1,1>,1);
  19. llWhisper(0, "Say an avatar name in chat prefixing it with /" + (string)CHAT_CHANNEL + "; touch to reset");
  20. llSetTimerEvent(60.0);
  21. }
  22. else if (avatar == llDetectedKey(0))
  23. {
  24. llResetScript();
  25. }
  26. else
  27. llWhisper(0, "In use");
  28. }
  29. timer()
  30. {
  31. llResetScript();
  32. }
  33. listen(integer channel, string name, key id, string message)
  34. {
  35. http_request_id = llHTTPRequest(queryRequestURL + "?name=" + llEscapeURL(message) + "&compat=false", [], "");
  36. llSetTimerEvent(60.0);
  37. }
  38. http_response(key request_id, integer status, list metadata, string body)
  39. {
  40. if (request_id == http_request_id)
  41. {
  42. if (status == 200)
  43. llInstantMessage(avatar, body);
  44. else
  45. llInstantMessage(avatar, "Error " + (string)status + ": " + body);
  46. }
  47. llSetTimerEvent(0.0);
  48. }
  49. }