Gayngel

Detected avatars without sensor functions.

Dec 21st, 2019
714
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Script by Gayngel.
  2. // A way to detect avatars in range without using the llSensor functions.
  3.  
  4. list avs; // A list of avatars in the region.
  5. vector objectpos; // Object position.
  6.  
  7. default
  8. {
  9.     state_entry()
  10.     {
  11.         objectpos = llGetPos();  // Get the position of the object.
  12.         llSetTimerEvent(1.0);   // Start a timer.
  13.     }
  14.    
  15.     timer()
  16.     {
  17.      llSetTimerEvent(0.0);    // Stop timer until loop is complete.
  18.       avs = llGetAgentList(AGENT_LIST_PARCEL,[]); //Gets list o avatars on current parcel. Change to AGENT_LIST_PARCEL_OWNER or AGENT_LIST_REGION if needed.
  19.      
  20.      
  21.       if(avs != [])  // If the list is not empty i.e. no avatars detected. Equivalent to the no_sensor event.
  22.       {
  23.       integer i = 0;
  24.       integer tot = llGetListLength(avs);
  25.       for(;i < tot;++i)
  26.       {
  27.        
  28.         list tmp = llGetObjectDetails(llList2Key(avs,i),[OBJECT_POS]); //Get the position of the avatar in the list.
  29.         vector avpos = llList2Vector(tmp,0);  // Declare a vector variable and set to the avatar's position.
  30.        
  31.         if(llVecDist(objectpos,avpos) < 10.0) // Compare the distance between the object and the avatar. Equivalent to the range of the sensor. Distance should be a float.
  32.         {
  33.          
  34.           llWhisper(0,"Avatar detected: " + llKey2Name(llList2Key(avs,i)));   // If avatar is in range do something.
  35.            
  36.         }
  37.        }
  38.          
  39.       }
  40.      
  41.       llSetTimerEvent(1.0); // Start timer again. Equivalent to llSensorRepeat time.
  42.        
  43.        
  44.      
  45.        
  46.     }
  47.  
  48.    
  49. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×