Person spier

From The SchomEmunity Wiki
Revision as of 17:34, 8 January 2008 by Rebecca (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This script will tell you the names and distances to all people within 96m every time you say 'detect' on channel 1. Unfortunately, there's a 255 character limit on the amount of floating text, so beyond about four or five people stuff starts disappearing off the end of the string.

How about less useless information then? And fewer hyphens. >.> - Katharine Berry 19:28, 23 July 2007 (BST)
 :p --Decimus 20:07, 23 July 2007 (BST)
float DRANGE = 96.0; // LSL does not optimise. Using ints as floats results in extra typecasts being added during compilation.
string SDRANGE;

string getpos()
{
    vector p = llGetPos();
    return "(" + (string)llRound(p.x) + ", " + (string)llRound(p.y) + ", " + (string)llRound(p.z) + ")";
}

string gmtime()
{
    float f = llGetGMTclock();
    integer h = llRound(f) / 3600;
    integer m = (llRound(f) / 60) % 60;
    integer s = llRound(f) % 60;
    return (string)h + ":" + (string)m + ":" + (string)s + " (+0000)";
}

default
{
    state_entry()
    {
        SDRANGE = (string)((integer)DRANGE);
    }

    sensor(integer num)
    {
        vector pos = llGetPos();
        string text = "Nearby avatars and distances from:\n" + getpos() + " at " + gmtime() + "\n---------------------------------\n";
        integer s = FALSE; // Initialise variables!
        integer i = -1;
        while(++i < num)
        {
            integer dist = llRound(llVecDist(pos, llDetectedPos(i)));
            if(dist <= DRANGE) // Don't assume that the distance limits actually work. They don't, at least not reliably... :p
            {
                if (!s && dist > 20)
                {
                    text = text + "---------------------------------\n-- Max speech range (=20m) --\n";
                    s = TRUE;
                }
                text = text + llDetectedName(i) + " - " + (string)dist + "m\n";
            }
        }
        text = text + "---------------------------------\n-- Max detect range (=" + SDRANGE + "m) --";
        llSetText(text, <0.0,0.0,1.0>, 1.0);
    }
    
    touch_start(integer num)
    {
        llSensor("", NULL_KEY, AGENT, DRANGE, PI); // You want PI, not 2*PI. Sensors are odd like that. Even if you did, you should use TWO_PI and PI_BY_TWO.
    }
    
    no_sensor() // Eww. Why did you have a timer?
    {
        llSetText("Nearby avatars and distances from:\n" + getpos() + " at " + gmtime() + "\n---------------------------------\n ---Max detect range (=" + SDRANGE + "m)---", <0.0,0.0,1.0>, 1.0);
    }
}