Advertisement
Gayngel

Detected avatars in range without sensor functions.

Dec 21st, 2019 (edited)
1,370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Script by Gayngel.
  2.  
  3. // A way to detect avatars in range without using the llSensor() functions.
  4.  
  5. // Gets a list of avatars in the region with llGetAgentList()
  6.  
  7. // On a timer loops through the list and checks position of each avatar and compares distance between avatar pos and object pos using llVecDist()
  8.  
  9. float range_limit = 10.0; // change the range of detection as needed // must be a float
  10.  
  11. list avs; // A list of avatars in the region.
  12.  
  13. vector objectpos; // Object position.
  14.  
  15. default
  16. {
  17.     state_entry()
  18.     {
  19.        
  20.         llSetTimerEvent(1.0);   // Start a timer.
  21.     }
  22.    
  23.     timer()
  24.     {
  25.      llSetTimerEvent(0.0);    // Stop timer until loop is complete.
  26.    
  27.      
  28.      avs = llGetAgentList(AGENT_LIST_PARCEL,[]); //Gets list o avatars on current parcel. Change to AGENT_LIST_PARCEL_OWNER for all owned parcels in the region or AGENT_LIST_REGION for the whole region if needed.
  29.      
  30.      
  31.       if(avs != [])  // If the list is not empty i.e. avatars detected. Equivalent to the sensor event.
  32.       {
  33.       integer i = 0;
  34.       integer tot = llGetListLength(avs);
  35.       for(;i < tot;++i)
  36.       {
  37.        
  38.         list tmp = llGetObjectDetails(llList2Key(avs,i),[OBJECT_POS]); //Get the position of the avatar in the list.
  39.         vector avpos = llList2Vector(tmp,0);  // Declare a vector variable and set to the avatar's position.
  40.         objectpos = llGetPos();  // Get the position of the object.
  41.        
  42.        
  43.         if(llVecDist(objectpos,avpos) < range_limit) // Compare the distance between the object and the avatar. Equivalent to the range of the sensor. Distance should be a float.
  44.         {
  45.          
  46.           llWhisper(0,"Avatar detected: " + llKey2Name(llList2Key(avs,i)));   // If avatar is in range do something.
  47.            
  48.         }
  49.        
  50.        
  51.         else  // if no avatars in range do something. Sort of equivalent to the no_sensor event.
  52.         {
  53.              // do stuff if no avatars in range.
  54.            
  55.         }
  56.        
  57.        }
  58.          
  59.       }
  60.  
  61.     else // If the list is empty i.e. avatars not detected in the region. Equivalent to the no_sensor event.
  62.     {
  63.    
  64.         // do stuff if no avatars detected in region.
  65.  
  66.     }
  67.      
  68.       avs = [];  // Clears avatar list Redundancy just in case.
  69.       llSetTimerEvent(1.0); // Start timer again. Equivalent to llSensorRepeat time.
  70.        
  71.        
  72.      
  73.        
  74.     }
  75.  
  76.    
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement