Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Script by Gayngel.
- // A way to detect avatars in range without using the llSensor() functions.
- // Gets a list of avatars in the region with llGetAgentList()
- // On a timer loops through the list and checks position of each avatar and compares distance between avatar pos and object pos using llVecDist()
- float range_limit = 10.0; // change the range of detection as needed // must be a float
- list avs; // A list of avatars in the region.
- vector objectpos; // Object position.
- default
- {
- state_entry()
- {
- llSetTimerEvent(1.0); // Start a timer.
- }
- timer()
- {
- llSetTimerEvent(0.0); // Stop timer until loop is complete.
- 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.
- if(avs != []) // If the list is not empty i.e. avatars detected. Equivalent to the sensor event.
- {
- integer i = 0;
- integer tot = llGetListLength(avs);
- for(;i < tot;++i)
- {
- list tmp = llGetObjectDetails(llList2Key(avs,i),[OBJECT_POS]); //Get the position of the avatar in the list.
- vector avpos = llList2Vector(tmp,0); // Declare a vector variable and set to the avatar's position.
- objectpos = llGetPos(); // Get the position of the object.
- 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.
- {
- llWhisper(0,"Avatar detected: " + llKey2Name(llList2Key(avs,i))); // If avatar is in range do something.
- }
- else // if no avatars in range do something. Sort of equivalent to the no_sensor event.
- {
- // do stuff if no avatars in range.
- }
- }
- }
- else // If the list is empty i.e. avatars not detected in the region. Equivalent to the no_sensor event.
- {
- // do stuff if no avatars detected in region.
- }
- avs = []; // Clears avatar list Redundancy just in case.
- llSetTimerEvent(1.0); // Start timer again. Equivalent to llSensorRepeat time.
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement