Difference between revisions of "Basic Target Scanner HUD"

From Second Life Wiki
Jump to navigation Jump to search
m (Switched deprecated <source> tag with the current, official tag <syntaxhighlight>)
 
(14 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{LSL Header}}
{{LSL Header}}[[Category:LSL Library]]


This single prim HUD is just a button that scrolls through nearby players names, photos and user key.
This single prim HUD is just a button that scrolls through nearby players names, photos and user key.
Line 6: Line 6:
--[[User:Ackley Bing|Ackley Bing]]
--[[User:Ackley Bing|Ackley Bing]]


<lsl>
<syntaxhighlight lang="lsl2">
// Basic Target Scanner HUD
// Basic Target Scanner HUD
// by Ackley Bing
// by Ackley Bing
//
// v.2.0 now using llGetAgentList() instead of sensor().  Added a missing profile photo texture. fixed a lot of issues.
// Drop this in a prim and touch


integer index;
key HUDtarget;
key HUDtarget;
integer HUDattachpoint=35;
integer senseindex;
key photoReq;
key photoReq;
 
integer HUDattachpoint=ATTACH_HUD_CENTER_1;
TargetInfo(key id)
string missingtexture="1a6e02aa-23a8-7a5f-0525-44d724144f89";
Target()
{
{
     llSetText(llToLower(llGetDisplayName(id))+"\n"+(string)id, <0.0, 1.0, 0.0>, 1.0);
    list agents=llGetAgentList(AGENT_LIST_REGION,[]);
     if ( id!=NULL_KEY )
    integer ownerindex=llListFindList( agents, (list)llGetOwner() );
    {
    integer num_agents;
        photoReq=llHTTPRequest("http://world.secondlife.com/resident/" + (string)id, [], "");
    agents=llDeleteSubList( agents, ownerindex, ownerindex );
        llOwnerSay("Current Target: secondlife:///app/agent/" + (string)id + "/inspect " + (string)id );
    num_agents = llGetListLength(agents);
    }
    index=((index<0)*(num_agents-1))+((index>=0)*(index*(index!=num_agents)));
    else
    HUDtarget=llList2Key(agents, index);
    {
     llSetText(llKey2Name(HUDtarget)+" ("+llGetDisplayName(HUDtarget)+")\n"+(string)HUDtarget, <0.0, 1.0, 0.0>, 1.0);
        llSetTexture("8dcd4a48-2d37-4909-9f78-f7a9eb4ef903", 0);
     photoReq=llHTTPRequest("http://world.secondlife.com/resident/" + (string)HUDtarget, [], "");
        llOwnerSay("No Target");
    llOwnerSay("("+(string)(index+1)+"/"+(string)(num_agents) +") Current Target: secondlife:///app/agent/" + (string)HUDtarget + "/inspect " + (string)HUDtarget );
    }
}
}
default
default
{
{
     state_entry()
     state_entry()
     {
     {
         llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS | PERMISSION_ATTACH);
         llRequestPermissions(llGetOwner(),PERMISSION_ATTACH);
     }
     }
     attach(key id)
     attach(key id)
Line 46: Line 43:
             llRotateTexture(270.0*DEG_TO_RAD,0);
             llRotateTexture(270.0*DEG_TO_RAD,0);
             HUDattachpoint=llGetAttached();
             HUDattachpoint=llGetAttached();
             senseindex=0;
             Target();
             llSensor("", "", AGENT, 128, TWO_PI);
             llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
         }
         }
     }
     }
     on_rez(integer param)
     on_rez(integer param)
     {
     {
         if ( !(llGetAttached()) ) llAttachToAvatar(HUDattachpoint);
         if ( !llGetAttached() )
    }
        {
    touch_start(integer tsn)
            index=0;
    {
            HUDtarget=NULL_KEY;
        if ( !(llGetAttached()) ) llAttachToAvatar(HUDattachpoint);
            llSetText("", <0.0, 1.0, 0.0>, 1.0);
        senseindex=senseindex+(llDetectedTouchFace(0)==1)-(llDetectedTouchFace(0)==3);
            llSetTexture(missingtexture, 0);
        llSensor("", "", AGENT, 128, TWO_PI);
            llRequestPermissions(llGetOwner(),PERMISSION_ATTACH);
        }
     }
     }
     sensor(integer num)
     touch_start(integer n)
     {
     {
         senseindex=((senseindex<0)*(num-1))+((senseindex>=0)*(senseindex*(senseindex!=num)));
         index=index+(llDetectedTouchFace(0)==1)-(llDetectedTouchFace(0)==3);
        HUDtarget=llDetectedKey(senseindex);
         Target();
         TargetInfo(HUDtarget);
    }
    no_sensor()
    {
        senseindex=0;
        HUDtarget=NULL_KEY;
        TargetInfo(HUDtarget);
     }
     }
     http_response(key request_id, integer status, list metadata, string body)
     http_response(key request_id, integer status, list metadata, string body)
Line 84: Line 75:
                 if(tempIndex>17)photoID=llGetSubString(body,tempIndex,tempIndex+35);
                 if(tempIndex>17)photoID=llGetSubString(body,tempIndex,tempIndex+35);
             }
             }
             if ( photoID==NULL_KEY || photoID=="" ) photoID="8dcd4a48-2d37-4909-9f78-f7a9eb4ef903";
             if ( photoID==NULL_KEY || photoID=="" ) photoID=missingtexture;
             llSetTexture(photoID, 0);
             llSetTexture(photoID, 0);
         }
         }
Line 90: Line 81:
     run_time_permissions(integer perms)
     run_time_permissions(integer perms)
     {
     {
        if ( perms & PERMISSION_ATTACH ) llAttachToAvatar(HUDattachpoint);
         if ( perms & PERMISSION_TAKE_CONTROLS ) llTakeControls(CONTROL_BACK, FALSE, TRUE);
         if ( perms & PERMISSION_TAKE_CONTROLS ) llTakeControls(CONTROL_BACK, FALSE, TRUE);
        if ( perms & PERMISSION_ATTACH ) llAttachToAvatar(HUDattachpoint);
     }
     }
}
}
</lsl>
</syntaxhighlight>

Latest revision as of 13:26, 6 April 2022

This single prim HUD is just a button that scrolls through nearby players names, photos and user key. Drop it in a prim and touch the prim and you are set to go. Modify it to suit your particular use in another Hud, weapon, or whatever you want. <3 --Ackley Bing

// Basic Target Scanner HUD
// by Ackley Bing
// v.2.0 now using llGetAgentList() instead of sensor().  Added a missing profile photo texture. fixed a lot of issues.

integer index;
key HUDtarget;
key photoReq;
integer HUDattachpoint=ATTACH_HUD_CENTER_1;
string missingtexture="1a6e02aa-23a8-7a5f-0525-44d724144f89";
Target()
{
    list agents=llGetAgentList(AGENT_LIST_REGION,[]);
    integer ownerindex=llListFindList( agents, (list)llGetOwner() );
    integer num_agents;
    agents=llDeleteSubList( agents, ownerindex, ownerindex );
    num_agents = llGetListLength(agents);
    index=((index<0)*(num_agents-1))+((index>=0)*(index*(index!=num_agents)));
    HUDtarget=llList2Key(agents, index);
    llSetText(llKey2Name(HUDtarget)+" ("+llGetDisplayName(HUDtarget)+")\n"+(string)HUDtarget, <0.0, 1.0, 0.0>, 1.0);
    photoReq=llHTTPRequest("http://world.secondlife.com/resident/" + (string)HUDtarget, [], "");
    llOwnerSay("("+(string)(index+1)+"/"+(string)(num_agents) +") Current Target: secondlife:///app/agent/" + (string)HUDtarget + "/inspect " + (string)HUDtarget );
}
default
{
    state_entry()
    {
        llRequestPermissions(llGetOwner(),PERMISSION_ATTACH);
    }
    attach(key id)
    {
        if (id)
        {
            llSetScale(<0.1, 0.15, 0.1>);
            llSetPrimitiveParams([PRIM_TYPE, PRIM_TYPE_BOX, PRIM_HOLE_DEFAULT, <0.0, 1.0, 0.0>, 0.0, <0.0, 0.0, 0.0>, <2.0, 0.5, 1.0>, <0.0, 0.0, 0.0>, PRIM_ROT_LOCAL, <0.000000, -0.707107, 0.000000, 0.707107>, PRIM_COLOR, 0, <1.0,1.0,1.0>, 1.0, PRIM_COLOR, 1, <0.0,1.0,0.0>, 1.0, PRIM_COLOR, 3, <0.0,1.0,0.0>, 1.0, PRIM_COLOR, 2, <1.0,1.0,1.0>, 0.0, PRIM_COLOR, 4, <1.0,1.0,1.0>, 0.0]);
            llRotateTexture(270.0*DEG_TO_RAD,0);
            HUDattachpoint=llGetAttached();
            Target();
            llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS);
        }
    }
    on_rez(integer param)
    {
        if ( !llGetAttached() )
        {
            index=0;
            HUDtarget=NULL_KEY;
            llSetText("", <0.0, 1.0, 0.0>, 1.0);
            llSetTexture(missingtexture, 0);
            llRequestPermissions(llGetOwner(),PERMISSION_ATTACH);
        }
    }
    touch_start(integer n)
    {
        index=index+(llDetectedTouchFace(0)==1)-(llDetectedTouchFace(0)==3);
        Target();
    }
    http_response(key request_id, integer status, list metadata, string body)
    {
        if( request_id == photoReq )
        {
            string photoID;
            integer StartIndex=llSubStringIndex(body,"<title>");
            integer EndIndex=llSubStringIndex(body,"</title>");
            if( StartIndex!=-1)
            {
                integer tempIndex=llSubStringIndex(body,"imageid")+18;
                if(tempIndex>17)photoID=llGetSubString(body,tempIndex,tempIndex+35);
            }
            if ( photoID==NULL_KEY || photoID=="" ) photoID=missingtexture;
            llSetTexture(photoID, 0);
        }
    }
    run_time_permissions(integer perms)
    {
        if ( perms & PERMISSION_ATTACH ) llAttachToAvatar(HUDattachpoint);
        if ( perms & PERMISSION_TAKE_CONTROLS ) llTakeControls(CONTROL_BACK, FALSE, TRUE);
    }
}