Jump to content
Sign in to follow this  
Lymirah Gardner

Get Link and/or Face Numbers

Recommended Posts

This one's a two-fer -- two scripts for the price of none!  Since both scripts relate to getting link numbers of prims in a build, I'm including them in a single post.  The genesis for these was my frustration upon learning that the displayed "link number" in the edit window has no connection to the actual link number of the prim.  *sigh*  Makes you wonder, eh?

Obviously these are meant for builders.  They're of limited (no?) use for non-builders.  This is why both scripts include a scrub command to delete the script.  While anyone can trigger the chat commands, only the owner can delete the script.  I suppose one point of extensibility could be to make the chat commands only respond to the owner.  Unless it becomes a problem, I'd go with fewer checks for now.  (Building is laggy enough as it is.)

I've tested both scripts for the identified functionality and they appear to work correctly. If anyone has any recommendations, either for the existing code or additional features, please let me know!

EDIT:  Check out Rolig Loon's script in her reply below.  Renders my first one obsolete in a very elegant way.

 

(1)  GET NUMBER ON TOUCH

In response to a touch (by anyone), this script  whispers the owner with the link number and/or face number of the touched prim/face.  Script includes reset and scrub commands on channel 314 (e.g., "/314 reset" or "/314 scrub").  Scrub is only after confirmation via a dialogue window.  Everything is controlled by global variables.

 

////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Get (Face or Link) Number on Touch Script by Lymirah Gardner, Version 1.0, 01 May 2012
// (First Written 01 May 2012)
//
// Touch a face on the prim to get the face number.
// Touch a prim to get the link number.  Both reported only to the owner.
// Listens for a scrub command to delete script from prim.
// Also responds to a reset command.
//
////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Please feel free to share this script.  It's meant for anyone and everyone!  All I ask is that you
// don't sell the script on its own or as part of any package, objects or products.  It's provided
// for free - please keep it that way!  Please also keep this title box.
//
////////////////////////////////////////////////////////////////////////////////////////////////////////
//GNT314 v1.0 /314 reset-scrub

//GLOBAL CONTROL VARIABLES
integer CHANNEL = 314;
string comm_del = "SCRUB";
string comm_reset = "RESET";

//FACE AND/OR LINK NUMBER ON TOUCH?  1 = ON, 0 = OFF
integer FACE = 1;
integer LINK = 1;

//OTHER GLOBAL VARIABLES
key owner = NULL_KEY;
integer LISTEN_ID;
integer DCHANNEL;
string temp = "";
integer i;
float DTIME = 15.0;

//START HERE
default {
    state_entry() {
        llListenRemove(LISTEN_ID);
        DCHANNEL = ((integer)("0x"+llGetSubString((string)llGetKey(),-8,-1)) & 0x3FFFFFFF) ^ 0xBFFFFFFF;
        owner = llGetOwner();
        LISTEN_ID = llListen(CHANNEL,"",owner,"");
    }

    on_rez(integer param) {
        llResetScript();
    }

    touch_end(integer num_det) {
        for(i=0;i<num_det;++i)
            if(FACE == 1) llOwnerSay("Face touched is number "+(string)llDetectedTouchFace(i));
            if(LINK == 1) llOwnerSay("Link touched is number "+(string)llDetectedLinkNumber(i));
    }

    listen (integer channel, string name, key id, string command) {
        temp = llStringTrim(command,STRING_TRIM);
        command = llToUpper(temp);
        if(command == comm_reset) {
            llListenRemove(LISTEN_ID);
            llOwnerSay("Resetting script.");
            llResetScript();
        }
        else if(command == comm_del) {
            llListenRemove(LISTEN_ID);
            state delete_script;
        }
    }
}

state delete_script {
    state_entry() {
        LISTEN_ID = llListen(DCHANNEL, "", owner, "");
        llDialog(owner, "Delete this script?", ["Yes","No"], DCHANNEL);
        llSetTimerEvent(DTIME);
    }
    listen(integer channel, string name, key id, string msg) {
        if(msg == "Yes") {
            llListenRemove(LISTEN_ID);
            llOwnerSay("Goodbye!");
            llSetTimerEvent(0.0);
            llRemoveInventory(llGetScriptName());
        }
        else if(msg == "No") {
            llListenRemove(LISTEN_ID);
            llSetTimerEvent(0.0);
            state default;
        }
        else {
            llListenRemove(LISTEN_ID);
            llOwnerSay("***Something went horribly wrong!***");
            llSetTimerEvent(0.0);
            state bugged;
        }
    }
    timer() {
        llListenRemove(LISTEN_ID);
        llOwnerSay("Dialogue time expired.");
        llSetTimerEvent(0.0);
        state default;
    }
}

state bugged {
    state_entry() {
        llOwnerSay("***Script operation terminated!***");
    }
}

 

(2)  GET LINK NUMBERS

This one responds to a chat command and whispers the owner with the requested information.  Default is channel 313.  "this" gives the prim name and link number of the prim the script is in.  "all" lists the names of the prims for all link numbers in ascending numerical order (link 1 to link n) and reports the total number of prims in the linkset (at the end of the report).  "reset" resets the script.  "help" or "?" lists the commands.  "scrub" removes the script (after confirmation via a dialogue window).   Everything is controlled by global variables.

 

////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Get Link Numbers Script by Lymirah Gardner, Version 1.0, 05 April 2012
// (First Written 05 April 2012)
//
// Obtains and reports link numbers (to owner) for individual prim or all prims in link set.
// Can delete scrip on command and dialogue confirmation.
//
////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Please feel free to share this script.  It's meant for anyone and everyone!  All I ask is that you
// don't sell the script on its own or as part of any package, objects or products.  It's provided
// for free - please keep it that way!  Please also keep this title box.
//
////////////////////////////////////////////////////////////////////////////////////////////////////////
//GLN313 v1.0 /313 all-this-reset-scrub-help-?

//GLOBAL VARIABLES
integer CCHANNEL = 313;                     //chat channel
string comm_all = "ALL";                    //command to indicate report for all prims in linkset
string comm_this = "THIS";                  //command to indicate report for only this prim
string comm_reset = "RESET";                //command to reset script
string comm_del = "SCRUB";                  //command to delete script
string comm_help1 = "HELP";                 //command to get help/commands
string comm_help2 = "?";                    //command to get help/commands

float SLEEP = 0.2;                          //time pause when reporting for a linkset (comm_all)
key owner = NULL_KEY;
integer LISTEN_ID;
integer NUM_PRIMS;
string temp = "";
integer i;

//These are only used to confirm script removal
integer DCHANNEL;
float DTIME = 15.0;

//START HERE
default {
    state_entry() {
        llListenRemove(LISTEN_ID);
        NUM_PRIMS = llGetNumberOfPrims();
        if(NUM_PRIMS < 2) {      //also could have used: if(llGetLinkNumber() == 0)
            llOwnerSay("***This is not a linkset.***");
            state bugged;
        }
        DCHANNEL = ((integer)("0x"+llGetSubString((string)llGetKey(),-8,-1)) & 0x3FFFFFFF) ^ 0xBFFFFFFF;
        owner = llGetOwner();
        LISTEN_ID = llListen(CCHANNEL,"",owner,"");
    }
    on_rez(integer param) {
        llResetScript();
    }
    listen (integer channel, string name, key id, string command) {
        temp = llStringTrim(command,STRING_TRIM);
        command = llToUpper(temp);
        if(command == comm_this) {
            i = llGetLinkNumber();
            temp = llGetLinkName(i);
            llOwnerSay("Name of This Prim: "+temp);
            llOwnerSay("Link Number of This Prim: "+(string)i);
        }
        else if(command == comm_all) {
            for(i=1;i<=NUM_PRIMS;++i) {
                temp = llGetLinkName(i);
                if(i<10) llOwnerSay("Link No. "+(string)i+":   "+temp);
                if(i>9 && i<100) llOwnerSay("Link No. "+(string)i+":  "+temp);
                if(i>99) llOwnerSay("Link No. "+(string)i+": "+temp);
                llSleep(SLEEP);
            }
            llOwnerSay("Total Number of Prims: "+(string)NUM_PRIMS);
        }
        else if(command == comm_reset) {
            llListenRemove(LISTEN_ID);
            llOwnerSay("Resetting script.");
            llResetScript();
        }
        else if(command == comm_help1 || command == comm_help2) {
            llOwnerSay("/313 all – get link numbers for all prims in the linkset\n/313 this – get link number for this prim only (the one the script is in)\n/313 reset – reset script\n/313 scrub – delete this script\n/313 help or /313 ? – display this help text");
        }
        else if(command == comm_del) {
            llListenRemove(LISTEN_ID);
            state delete_script;
        }
    }
}

state delete_script {
    state_entry() {
        LISTEN_ID = llListen(DCHANNEL, "", owner, "");
        llDialog(owner, "Delete this script?", ["Yes","No"], DCHANNEL);
        llSetTimerEvent(DTIME);
    }
    listen(integer channel, string name, key id, string msg) {
        if(msg == "Yes") {
            llListenRemove(LISTEN_ID);
            llOwnerSay("Goodbye!");
            llSetTimerEvent(0.0);
            llRemoveInventory(llGetScriptName());
        }
        else if(msg == "No") {
            llListenRemove(LISTEN_ID);
            llSetTimerEvent(0.0);
            state default;
        }
        else {
            llListenRemove(LISTEN_ID);
            llOwnerSay("***Something went horribly wrong!***");
            llSetTimerEvent(0.0);
            state bugged;
        }
    }
    timer() {
        llListenRemove(LISTEN_ID);
        llOwnerSay("Dialogue time expired.");
        llSetTimerEvent(0.0);
        state default;
    }
}

state bugged {
    state_entry() {
        llOwnerSay("***Script operation terminated!***");
    }
}

 

  • Thanks 1

Share this post


Link to post
Share on other sites

Or ...

key gOwner;default{    state_entry()    {        gOwner = llGetOwner();    }        on_rez(integer start)    {        gOwner = llGetOwner();    }        touch_start(integer num)    {        llResetTime();    }        touch_end(integer num)    {        if ((llDetectedKey(0) == gOwner) &&(llGetTime() > 2.0)) //Owner has held left mouse button for more than 2 seconds        {            llSay(0,"Script deleted.");            llRemoveInventory(llGetScriptName()); //Kill this script        }        else        {            llSay(0, "You have just touched face #" + (string) llDetectedTouchFace(0) + " on prim #" + (string)llDetectedLinkNumber(0)+".");        }    }}

 

  • Thanks 2

Share this post


Link to post
Share on other sites

Thanks, Rolig!  I keep forgetting about non-chat controls.  I wrote the listing one first, but then realized that I wanted the face number, too.  I'll edit the main post to indicate yours.

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...