Display Names Radar
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.
<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)
<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() {
gPrims = ["", ""]; integer i; for (i = 2; i <= llGetNumberOfPrims(); i++) { gPrims += llList2Integer(llGetLinkPrimitiveParams(i, [PRIM_DESC]), 0); }
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(); integer i; list status; 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(llListFindList(gPrims, [i]), [PRIM_TEXT, llDumpList2String(status, ""), <1., 1., 1.>, gTextAlpha]);
} }
@endloop;
for (; i < 16; i++) llSetLinkPrimitiveParamsFast(llListFindList(gPrims, [i]), [PRIM_TEXT, "", <1., 1., 1.>, 1.]);
llSetText("(" + (string)((integer)gSensorRange) + "m) " + (string)num, <1.0, 1.0, 1.0>, gTextAlpha); }
} </lsl>