Sensor.lsl 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // :SHOW:1
  2. // :CATEGORY:Gaming
  3. // :NAME: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 gets near this (75 meters, a looong way, it sends a @pause command to the controller. This will make it continue from an @stop.
  11. // when no one is araound, it sends a @delete to remove the NPC. It sends these once per avatar presence.
  12. // :CODE:
  13. 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.
  14. float time = 30; // keep this long.
  15. // toggle if a person is there or not so we can detect the edge condition
  16. integer isperson = FALSE;
  17. default
  18. {
  19. state_entry()
  20. {
  21. llSensorRepeat("","",AGENT,distance,PI, time);
  22. }
  23. sensor(integer n)
  24. {
  25. if (! isperson)
  26. llMessageLinked(LINK_SET,1,"@pause=1","");
  27. isperson = TRUE;
  28. }
  29. no_sensor()
  30. {
  31. if (isperson)
  32. llMessageLinked(LINK_SET,1,"@delete","");
  33. isperson = FALSE;
  34. }
  35. on_rez(integer p) {
  36. llResetScript();
  37. }
  38. changed(integer what)
  39. {
  40. if (what & CHANGED_REGION_START)
  41. {
  42. llResetScript();
  43. }
  44. }
  45. }