NotASensor.lsl 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // :SHOW:1
  2. // :CATEGORY:Gaming
  3. // :NAME:Does not use a Sensor to delete or start a NPC
  4. // :AUTHOR:Ferd Frederix
  5. // :KEYWORDS:Game, Sensor
  6. // :REV:1.0
  7. // :WORLD:OpenSim
  8. // :DESCRIPTION:
  9. // A part of a controller set for NPC's
  10. // When an avatar (the owner is not counted) gets close to this, it sends a @go command to the controller. This will make it continue from an @stop.
  11. // when no one is around, it sends a @stop to remove the NPC. It sends these once per avatar presence.
  12. // Does not use a laggy sensor. Will not detect the owner.
  13. // :CODE:
  14. integer debug = FALSE; // set to TRUE or FALSE for debug chat on various actions
  15. integer iTitleText = FALSE; // set to TRUE or FALSE for debug hovertext above the prim
  16. float distance = 75; // keep this distance short - in my case, we are on a broad plain and we need to notice the avatar from a long distance, but not often.
  17. float time = 10; // keep this big - the smaller, the laggier it gets
  18. // toggle if a person is there or not so we can detect the edge condition
  19. integer isPersonDetected = FALSE;
  20. // send a link message once, when no one is detected
  21. nobodyHome() {
  22. if (isPersonDetected) {
  23. llMessageLinked(LINK_SET,1,"@stop","");
  24. }
  25. isPersonDetected = FALSE;
  26. }
  27. // send a link message once, when someone is detected
  28. somebodyHome() {
  29. if (! isPersonDetected)
  30. llMessageLinked(LINK_SET,1,"@go","");
  31. isPersonDetected = TRUE;
  32. }
  33. default {
  34. state_entry(){
  35. llSetTimerEvent(time);
  36. }
  37. timer(){
  38. list avatarsInRegion = osGetAvatarList();
  39. // A srided list of the UUID, position, and name of each avatar in the region except the owner.
  40. integer i;
  41. integer present;
  42. for (i = 0; i < llGetListLength(avatarsInRegion)/3;i++)
  43. {
  44. key avatarUUID = llList2Key(avatarsInRegion,i);
  45. if (! osIsNpc(avatarUUID)) {
  46. vector avatarLoc = llList2Vector(avatarsInRegion,i+1); // location
  47. float dist = llVecDist(llGetPos(),avatarLoc);
  48. if (dist < distance)
  49. present++;
  50. }
  51. }
  52. if (present)
  53. somebodyHome();
  54. else
  55. nobodyHome();
  56. }
  57. on_rez(integer p) {
  58. llResetScript();
  59. }
  60. changed(integer what){
  61. if (what & CHANGED_REGION_START){
  62. llResetScript();
  63. }
  64. }
  65. }