Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

on touch is an AV within 3 meters

Tarak Voss
Meanderer
Join date: 14 Oct 2006
Posts: 330
10-26-2008 18:05
I want to know if an specific avatar (by key) is within a set distance (x.y.z) of a prim when the prim is touched - any ideas?
AnnMarie Otoole
Addicted scripter
Join date: 6 Jan 2007
Posts: 162
10-26-2008 19:54
llVecDist(llGetPos(),llDetectedPos(0)); will give you the distance when they touch.
You will have to do an llDetectedKey(0) test to see if it is the desired avatar.
Tarak Voss
Meanderer
Join date: 14 Oct 2006
Posts: 330
10-26-2008 20:00
I answered my own question:

float range = 3.0; // metres
key reader_key;
key reader_name_query;
integer online = FALSE;
string whotocheck= "";

default
{
//====== Gather info ======
touch(integer touch_num)
{
reader_key = (key)llGetObjectDesc ();
//Who is the current reader
whotocheck = llDetectedKey(0);
//Who wants to read

//====== Check if 'Whoto check' is the curret reader ======

if(reader_key != whotocheck)
//check if current reader and new reader are the same person
{
llSay(0,"You are not the current reader reader.";);//Test value
//====== Check if current reader is offline ======
llRequestAgentData(reader_key, DATA_ONLINE);
}
}
dataserver(key queryid, string data)//Get the result of the request
{
llSay(0,data); //Test value
if (data == "1";)// If reader is online
//====== Check if reader is within 3 meters ======
{
llSensor("", reader_key, AGENT, range, PI); //see float range varaible)
}
}
sensor (integer numberDetected)//Get scan result
{
string msg = "Detected " + llDetectedName(0);//turn result into a string
integer i = 0;//Garbbage collection
{
msg += ", " + llDetectedName(i);//cleaning out the string
}
llSay(0, msg);//Test value
llSetText("Go to Bookmark", <0,1,0>, 1);
}

no_sensor()//If not within 3 meters
{
llSay(0, "Previous reader is not near me.";);//Test value
llSetText("Closed Book", <0,1,0>, 1);
}
}
Tarak Voss
Meanderer
Join date: 14 Oct 2006
Posts: 330
10-26-2008 20:02
Thanks AnnMarie - I didn't see your reply before I posted my code - I'll check your suggestion out
Kaluura Boa
Polygon Project
Join date: 27 Mar 2007
Posts: 194
10-26-2008 20:04
llGetObjectDetails() is your friend...

// key Avatar;
// float Limit;
//
//
vector pos = llList2Vector(llGetObjectDetails(Avatar, [OBJECT_POS]), 0);
if (pos != ZERO_VECTOR) // Avatar in sim
{
if (llVecDist(llGetPos(), pos) < Limit) // Within limit
{
llSay(0, "Gotcha!";);
}
}
Tarak Voss
Meanderer
Join date: 14 Oct 2006
Posts: 330
10-26-2008 20:15
There was a reply by Kaluura ?? but it dropped off before I got to read it!
Kaluura Boa
Polygon Project
Join date: 27 Mar 2007
Posts: 194
10-27-2008 01:34
Sorry... There was a burst of answers when I finished so I just deleted mine. I'm re-posting because I was proposing a lag free alternative to a server request plus a sensor.

I honestly don't understand what you're trying to do with that script so I just imitated the behavior of yours...

float range = 3.0; // metres
key reader_key;

default
{
touch_start(integer touch_num)
{
reader_key = (key)llGetObjectDesc ();
if (reader_key != llDetectedKey(0))
{
llSay(0,"You are not the current reader.";);
vector pos = llList2Vector(llGetObjectDetails(reader_key, [OBJECT_POS]), 0);
if ( (pos != ZERO_VECTOR) // In the sim
&& (llVecDist(llGetPos(), pos) < range) ) // Within range
{
string msg = "Detected " + llKey2Name(reader_key);
integer i = llGetRegionAgentCount() - 1;
if (i)
{
msg += " and " + llList2String(["another avatar", (string)i + " avatars"], (i > 1)) + " in the region";
}
llSay(0, msg);//Test value
llSetText("Go to Bookmark", <0,1,0>, 1);
}
else
{
// Out of range
}
}
} // touch
} // default
Tarak Voss
Meanderer
Join date: 14 Oct 2006
Posts: 330
10-27-2008 02:24
Thanks for that - it is a real help.
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
10-27-2008 08:43
You might also want to test to see if the result of llGetObjectDetails() is an empty list. If so, the target avatar is offline or not present in the vicinity.
Kaluura Boa
Polygon Project
Join date: 27 Mar 2007
Posts: 194
10-27-2008 11:46
It's done in a certain way when I check if (pos != ZERO_VECTOR).

llList2Vector([], 0) == ZERO_VECTOR

No need to manipulate lists more than necessary.