Difference between revisions of "Display Names Radar"

From Second Life Wiki
Jump to navigation Jump to search
m
m
Line 3: Line 3:
First you will need to create a suitable HUD object. Use this first script to do that. It will ask for link permission, grant it.
First you will need to create a suitable HUD object. Use this first script to do that. It will ask for link permission, grant it.


=== build script ===
<lsl>
<lsl>
/**************************************************
/**************************************************
Line 124: Line 125:
--[[User:Cerise Sorbet|Cerise Sorbet]] 00:30, 6 November 2010 (UTC)
--[[User:Cerise Sorbet|Cerise Sorbet]] 00:30, 6 November 2010 (UTC)


=== radar script ===
<lsl>
<lsl>
//  display names avatar radar
//  display names avatar radar
 
integer gCommandChannel = 44;          // Listen for commands on this channel
integer gCommandChannel = 44;          // Listen for commands on this channel
float gMaxSensorRange = 96.0;          // Default maximum scanner range
float gMaxSensorRange = 96.0;          // Default maximum scanner range
float gInterval = 5.0;                  // Default seconds between checks
float gInterval = 5.0;                  // Default seconds between checks
 
integer gCommandListener;              // llListen results go here
integer gCommandListener;              // llListen results go here
float gSensorRange = gMaxSensorRange;  // sensor range in use right now
float gSensorRange = gMaxSensorRange;  // sensor range in use right now
 
integer gWasNone = FALSE;
integer gWasNone = FALSE;
 
list gTextLines;
list gTextLines;
list gPrims;
list gPrims;
float gTextAlpha = .5;
float gTextAlpha = .5;
 
Setup() {
Setup() {
     gPrims = ["", ""];
     list prims;
     integer i;
     integer i;
     for (i = 2; i <= llGetNumberOfPrims(); i++) {
     for (i = 2; i <= llGetNumberOfPrims(); i++)
         gPrims += llList2Integer(llGetLinkPrimitiveParams(i, [PRIM_DESC]), 0);
    {
         prims += llList2Integer(llGetLinkPrimitiveParams(i, [PRIM_DESC]), 0);
    }
    gPrims = [];
    for (i = 0; i < 16; i++)
    {
        integer index = llListFindList(prims, [i]);
        if (index == -1)
        {
            llOwnerSay("no prim with description \"" + (string)i + "\", display will be incomplete");
            gPrims += "";
        }
        else
        {
            gPrims += index + 2;
        }
     }
     }
 
     llListenRemove(gCommandListener);
     llListenRemove(gCommandListener);
     gCommandListener = llListen(gCommandChannel, "", llGetOwner(), "");
     gCommandListener = llListen(gCommandChannel, "", llGetOwner(), "");
     if (llGetAttached()) {
     if (llGetAttached())
         llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
         llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
    }
 
     llSetTimerEvent(gInterval);
     llSetTimerEvent(gInterval);
}
}
 
 
default
default
{
{
Line 162: Line 180:
         Setup();
         Setup();
     }
     }
   
     on_rez(integer start_param)
     on_rez(integer start_param)
     {
     {
         Setup();
         Setup();
     }
     }
   
     attach(key id)
     attach(key id)
     {
     {
         Setup();
         Setup();
     }
     }
 
     changed(integer change)
     changed(integer change)
     {
     {
Line 180: Line 198:
             Setup();
             Setup();
     }
     }
 
     // Terrible handy no script area hack.
     // Terrible handy no script area hack.
     run_time_permissions (integer perm)
     run_time_permissions (integer perm)
Line 191: Line 209:
         }
         }
     }
     }
 
     listen(integer channel, string name, key id, string message)
     listen(integer channel, string name, key id, string message)
     {
     {
         list command = llParseString2List(message, [" "], []);
         list command = llParseString2List(message, [" "], []);
 
         if (llGetListLength(command) != 2)
         if (llGetListLength(command) != 2)
             return;
             return;
 
         string verb = llList2String(command, 0);
         string verb = llList2String(command, 0);
         string argument = llList2String(command, 1);
         string argument = llList2String(command, 1);
 
         if (verb == "range")
         if (verb == "range")
         {
         {
Line 214: Line 232:
         }
         }
     }
     }
 
 
     no_sensor()
     no_sensor()
     {
     {
Line 221: Line 239:
         {
         {
             llSetText("0 in " + (string)((integer) gSensorRange) + "m", <0.,0.,0.>, gTextAlpha);
             llSetText("0 in " + (string)((integer) gSensorRange) + "m", <0.,0.,0.>, gTextAlpha);
             llSetLinkPrimitiveParamsFast(LINK_ALL_CHILDREN, [PRIM_TEXT, "", <1., 1., 1.>, 1.]);
             llSetLinkPrimitiveParamsFast(LINK_ALL_CHILDREN, [
                PRIM_TEXT,
                "",
                <1., 1., 1.>,
                1.
            ]);
             gWasNone = TRUE;
             gWasNone = TRUE;
         }
         }
 
     }
     }
 
     timer() {
     timer()
    {
         llSensor("", "", AGENT, gSensorRange, PI);
         llSensor("", "", AGENT, gSensorRange, PI);
     }
     }
 
     sensor(integer num) {
     sensor(integer num)
    {
         gWasNone = FALSE;
         gWasNone = FALSE;
         list statList = [];
         list statList = [];  
         vector myPos = llGetPos();
         vector myPos = llGetPos();
          
         list status;
         integer i;
         integer i;
        list status;
         for (i = 0; i < num; i++)
         for (i = 0; i < num; i++) {
        {
             if (i > 15)
             if (i > 15)
                 jump endloop;
                 jump endloop;
Line 251: Line 275:
                 else
                 else
                     status = [dn, " (", llGetUsername(k), ") ", (integer)theirDistance];
                     status = [dn, " (", llGetUsername(k), ") ", (integer)theirDistance];
   
                 llSetLinkPrimitiveParamsFast(llListFindList(gPrims, [i]), [PRIM_TEXT, llDumpList2String(status, ""), <1., 1., 1.>, gTextAlpha]);
                 llSetLinkPrimitiveParamsFast(llList2Integer(gPrims, i), [
 
                    PRIM_TEXT,
                        llDumpList2String(status, ""),
                        <1., 1., 1.>,
                        gTextAlpha
                ]);
             }
             }
         }
         }  
 
         @endloop;
         @endloop;
 
         for (; i < 16; i++)
         for (; i < 16; i++)
                    llSetLinkPrimitiveParamsFast(llListFindList(gPrims, [i]), [PRIM_TEXT, "", <1., 1., 1.>, 1.]);
        {
 
            llSetLinkPrimitiveParamsFast(llList2Integer(gPrims, i), [
                PRIM_TEXT,
                    "", <1., 1., 1.>,
                    1.
            ]);
        }
         llSetText("(" + (string)((integer)gSensorRange) + "m) " + (string)num,  <1.0, 1.0, 1.0>, gTextAlpha);
         llSetText("(" + (string)((integer)gSensorRange) + "m) " + (string)num,  <1.0, 1.0, 1.0>, gTextAlpha);
     }
     }  
 
}
}
</lsl>
</lsl>


[[Category:LSL Library]]
[[Category:LSL Library]]

Revision as of 20:47, 5 November 2010

Here is a simple HUD type avatar radar that can show display names. This can be useful while some viewers support them and others do not.

First you will need to create a suitable HUD object. Use this first script to do that. It will ask for link permission, grant it.

build script

<lsl> /**************************************************

   This is the script that creates the radar object.
   1. Rez a cube and take it to your inventory.
   2. Drag the cube from your inventory back on to to ground.
   3. Go back to your inventory, this time ctrl+drag the same cube to inside the one you just rezzed.
   4. Edit the first cube, create a new script, paste in this code, and save.
   5. Touch to create the object.
   4. Edit the radar object again, create a new script, paste in the second script (the actual radar), and save.
   7. Take the result to your inventory, it should be ready.
   To use, attach it to your HUD. By default it expects to be worn on the bottom. If you want to
   wear it near the top of the screen, it will be good to flip the object 180 degrees.
   The text spacing could be too big or small, resize the object with the editor
   until it looks how you want.
                                                                                                    • /

string gWorkPrim; integer gNewChild; float gCubeSize = .02;

default {

   state_entry()
   {
       llSetText("Rez a generic cube, take it to your inventory,\n"
           + "ctrl+drag it to inside this prim, then touch to begin", <1., 1., 1.>, 1.);
   }
   touch_start(integer num)
   {
       if (llDetectedKey(0) != llGetOwner())
           return;
       gWorkPrim = llGetInventoryName(INVENTORY_OBJECT, 0);
       if (gWorkPrim == "")
       {
           llSetText("No object found in object inventory. Rez a generic cube, take it to your\n"
               + "inventory, ctrl+drag it to inside this prim, then touch to try again.", <1., 1., 0.>, 1.);
           return;
       }
       llRequestPermissions(llGetOwner(), PERMISSION_CHANGE_LINKS);
   }
   run_time_permissions(integer perm)
   {
       if (perm & PERMISSION_CHANGE_LINKS)
       {
           llSetLinkPrimitiveParamsFast(LINK_THIS, [
               PRIM_NAME,
                   "display names radar",
               PRIM_ROTATION,
                   ZERO_ROTATION,
               PRIM_SIZE,
                   <gCubeSize, gCubeSize, gCubeSize>,
               PRIM_TEXTURE,
                   ALL_SIDES,
                   TEXTURE_BLANK,
                   <1., 1., 0.>,
                   ZERO_VECTOR,
                   .5,
               PRIM_COLOR,
                   ALL_SIDES,
                   ZERO_VECTOR,
                   .5
           ]);
           gNewChild = 0;
           llRezObject(gWorkPrim, llGetPos() + <.5, 0., 0.>, ZERO_VECTOR, ZERO_ROTATION, 0);
       }
   }
   object_rez(key id)
   {
       llCreateLink(id, LINK_ROOT);
       llSetLinkPrimitiveParamsFast(2, [
           PRIM_POSITION,
               <0., 0., gCubeSize * (gNewChild + 1)>,
           PRIM_ROTATION,
               ZERO_ROTATION,
           PRIM_SIZE,
               <gCubeSize, gCubeSize, gCubeSize>,
           PRIM_TEXTURE,
               ALL_SIDES,
               TEXTURE_BLANK,
               <1., 1., 0.>,
               ZERO_VECTOR,
               0.,
           PRIM_COLOR,
               ALL_SIDES,
               ZERO_VECTOR,
               0.,
           PRIM_DESC,
               (string)gNewChild
       ]);
       
       gNewChild++;
       if (gNewChild < 16)
       {
           llRezObject(gWorkPrim, llGetPos() + <.5, 0., 0.>, ZERO_VECTOR, ZERO_ROTATION, 0);
       }
       else
       {
           llRemoveInventory(gWorkPrim);
           llSetText("Object created, you can drag in the radar script now.", <0., 1., 0.>, 1.);
           llRemoveInventory(llGetScriptName());
       }
   }

} </lsl>

When the object is created, here is the radar script that will do the real work.

To use, attach it to your HUD. By default it expects to be worn on the bottom. If you want to wear it near the top of the screen, it will be good to flip the object 180 degrees.

The text spacing could be too big or small, resize the object with the editor until it looks how you want.

Have fun, --Cerise Sorbet 00:30, 6 November 2010 (UTC)

radar script

<lsl> // display names avatar radar

integer gCommandChannel = 44; // Listen for commands on this channel float gMaxSensorRange = 96.0; // Default maximum scanner range float gInterval = 5.0; // Default seconds between checks

integer gCommandListener; // llListen results go here float gSensorRange = gMaxSensorRange; // sensor range in use right now

integer gWasNone = FALSE;

list gTextLines; list gPrims; float gTextAlpha = .5;

Setup() {

   list prims;
   integer i;
   for (i = 2; i <= llGetNumberOfPrims(); i++)
   {
       prims += llList2Integer(llGetLinkPrimitiveParams(i, [PRIM_DESC]), 0);
   }

   gPrims = [];
   for (i = 0; i < 16; i++)
   {
       integer index = llListFindList(prims, [i]);
       if (index == -1)
       {
           llOwnerSay("no prim with description \"" + (string)i + "\", display will be incomplete");
           gPrims += "";
       }
       else
       {
           gPrims += index + 2;
       }
   }

   llListenRemove(gCommandListener);
   gCommandListener = llListen(gCommandChannel, "", llGetOwner(), "");
   if (llGetAttached())
       llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
   llSetTimerEvent(gInterval);

}


default {

   state_entry()
   {
       Setup();
   }

   on_rez(integer start_param)
   {
       Setup();
   }

   attach(key id)
   {
       Setup();
   }

   changed(integer change)
   {
       if (change & CHANGED_TELEPORT)
           llSensor("", "", AGENT, gSensorRange, PI);
       else if (change & CHANGED_OWNER)
           Setup();
   }

   // Terrible handy no script area hack.
   run_time_permissions (integer perm)
   {
       if (perm & PERMISSION_TAKE_CONTROLS)
       {
           // Take all the controls ALL the scripts in the same
           // object want to use or SVC-3187 will break them.
           llTakeControls(CONTROL_FWD, FALSE, TRUE);
       }
   }

   listen(integer channel, string name, key id, string message)
   {
       list command = llParseString2List(message, [" "], []);

       if (llGetListLength(command) != 2)
           return;

       string verb = llList2String(command, 0);
       string argument = llList2String(command, 1);

       if (verb == "range")
       {
           gSensorRange = llListStatistics(LIST_STAT_MIN, [(float)argument, gMaxSensorRange]);
           llOwnerSay("The sensor range is " + (string)gSensorRange + " meters now.");
       }
       else if (verb == "interval")
       {
           gInterval = llListStatistics(LIST_STAT_MAX, [(float)argument, 1.0]);
           llOwnerSay("The sensor poll interval is " + (string)gInterval + " seconds now.");
           llSetTimerEvent(gInterval);
       }
   }


   no_sensor()
   {
       if (!gWasNone)
       {
           llSetText("0 in " + (string)((integer) gSensorRange) + "m", <0.,0.,0.>, gTextAlpha);
           llSetLinkPrimitiveParamsFast(LINK_ALL_CHILDREN, [
               PRIM_TEXT,
               "",
               <1., 1., 1.>,
               1.
           ]);
           gWasNone = TRUE;
       }

   }

   timer()
   {
       llSensor("", "", AGENT, gSensorRange, PI);
   }

   sensor(integer num)
   {
       gWasNone = FALSE;
       list statList = []; 
       vector myPos = llGetPos();
       list status;
       integer i;
       for (i = 0; i < num; i++)
       {
           if (i > 15)
               jump endloop;
           float theirDistance = llVecDist(myPos, llDetectedPos(i));
           if (theirDistance <= gSensorRange) {
               key k = llDetectedKey(i);
               string dn = llGetDisplayName(k);
               string ln = llDetectedName(i);
               if (ln == dn || dn == "")
                   status = [ln, " ", (integer)theirDistance];
               else
                   status = [dn, " (", llGetUsername(k), ") ", (integer)theirDistance];

               llSetLinkPrimitiveParamsFast(llList2Integer(gPrims, i), [
                   PRIM_TEXT,
                       llDumpList2String(status, ""),
                       <1., 1., 1.>,
                       gTextAlpha
               ]);
           }
       } 
       @endloop;

       for (; i < 16; i++)
       {
           llSetLinkPrimitiveParamsFast(llList2Integer(gPrims, i), [
               PRIM_TEXT,
                   "", <1., 1., 1.>,
                   1.
           ]);
       }
       llSetText("(" + (string)((integer)gSensorRange) + "m) " + (string)num,  <1.0, 1.0, 1.0>, gTextAlpha);
   } 

} </lsl>