sloodle_tracker_scanner.lslp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //
  2. // The line above should be left blank to avoid script errors in OpenSim.
  3. // This file is part of SLOODLE Tracker.
  4. // Copyright (c) 2009-11 Sloodle community (various contributors)
  5. // SLOODLE Tracker is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. // SLOODLE Tracker is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // You should have received a copy of the GNU General Public License.
  14. // If not, see <http://www.gnu.org/licenses/>
  15. //
  16. // Contributors:
  17. // Peter R. Bloomfield
  18. // Julio Lopez (SL: Julio Solo)
  19. // Michael Callaghan (SL: HarmonyHill Allen)
  20. // Kerri McCusker (SL: Kerri Macchi)
  21. // A project developed by the Serious Games and Virtual Worlds Group.
  22. // Intelligent Systems Research Centre.
  23. // University of Ulster, Magee
  24. integer CHANNEL = 447851; // Channel for the tasks to comunicate
  25. string MY_TYPE = "scanner"; // What type of tracker tool is this?
  26. float RANGE = 20.0; // How far should we scan?
  27. integer REPORT_SCANS = FALSE; // TRUE means every avatar who is scanned will be reported in local chat. FALSE disables this.
  28. // Used to know who has already been detected and sent to Moodle.
  29. list recorded = [];
  30. list not_reported = [];
  31. key httpchat = NULL_KEY; // Request used to send/receive chat
  32. default
  33. {
  34. state_entry()
  35. {
  36. llSetTimerEvent(30.0);
  37. llSensorRepeat("", NULL_KEY, AGENT, RANGE, PI,5);
  38. }
  39. state_exit()
  40. {
  41. llSetTimerEvent(0.0);
  42. }
  43. sensor(integer total_number)
  44. {
  45. // Go through each detected avatar to see if it has been recorded yet
  46. integer i = 0;
  47. for (i = 0; i < total_number; i++)
  48. {
  49. key id = llDetectedKey(i);
  50. if (llListFindList(recorded, [id]) < 0)
  51. {
  52. not_reported += [id];
  53. recorded += [id];
  54. }
  55. }
  56. // Report each new avatar
  57. if (not_reported != [])
  58. {
  59. key id_object = llGetKey();
  60. string name_object = llGetObjectName();
  61. i = 0;
  62. integer numNotReported = llGetListLength(not_reported);
  63. for (i = 0; i < numNotReported; i++)
  64. {
  65. llMessageLinked(LINK_THIS, CHANNEL, "INTERACTION|"+MY_TYPE+"|1", llList2Key(not_reported,i));
  66. llSleep(1.0);
  67. }
  68. not_reported = [];
  69. }
  70. }
  71. link_message(integer sender_num, integer num, string sval, key kval)
  72. {
  73. // Was this an interaction response?
  74. if (sval == "INTERACTION_RESPONSE" && kval != NULL_KEY)
  75. {
  76. if (REPORT_SCANS) llSay(0, "Avatar detected: " + llKey2Name(kval));
  77. }
  78. }
  79. touch_start(integer total_number)
  80. {
  81. if (llDetectedKey(0) == llGetOwner())
  82. {
  83. llSensorRemove();
  84. state off;
  85. } else {
  86. string name = llDetectedName(0);
  87. llSay(0, "Sorry, " + name + ", you can't control this object.");
  88. }
  89. }
  90. timer()
  91. {
  92. recorded = [];
  93. not_reported = [];
  94. }
  95. }
  96. state off
  97. {
  98. state_entry()
  99. {
  100. llSetText("Scanner OFF", <0.0, 1.0, 0.0>, 0.8);
  101. }
  102. state_exit()
  103. {
  104. llSetText("", <0.0, 1.0, 0.0>, 0.8);
  105. }
  106. touch_start(integer total_number)
  107. {
  108. if (llDetectedKey(0) == llGetOwner())
  109. {
  110. recorded = [];
  111. not_reported = [];
  112. state default;
  113. } else {
  114. string name = llDetectedName(0);
  115. llSay(0, "Sorry, " + name + ", you can't control this object.");
  116. }
  117. }
  118. }
  119. // Please leave the following line intact to show where the script lives in Git:
  120. // SLOODLE LSL Script Git Location: mod/tracker-1.0/objects/scanner/assets/sloodle_tracker_scanner.lslp