Difference between revisions of "Remove all scripts from a linkset"

From Second Life Wiki
Jump to: navigation, search
m (<lsl> tag to <source>)
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
This simple script removes all scripts contained in a linkset. I had found one on the Internet but for an unknown reason, it moves the linkset (see [http://community.secondlife.com/t5/LSL-Library/Script-Remover-for-Linksets/td-p/721141]) ?! This one is simple, and works for attachments and rezzed objects. Just drop the script in the linkset (so in the root prim). If the linkset is one single prim, there is nothing else to do. Otherwise, when the script tells you that it is ready, unrez/re-rez the object and set all scripts to running using the menu of the viewer. That's all. An hovertext shows the number of remaining scripts to be cleaned up. This script is very useful for example for Firestorm's users: indeed when this page is being written down, the feature is still missing in Firestorm.
+
This simple script removes all scripts contained in a linkset. I had found one on the Internet but for an unknown reason, it moves the linkset (see [http://community.secondlife.com/t5/LSL-Library/Script-Remover-for-Linksets/td-p/721141]) ?! This one is simple, and works for attachments and rezzed objects. Just drop the script in the linkset (so in the root prim). If the linkset is one single prim, there is nothing else to do. Otherwise, when the script tells you that it is ready, unrez/re-rez the object and set all scripts to running using the menu of the viewer. That's all. An hovertext shows the number of remaining prims to be cleaned up. This script is very useful for example for Firestorm's users: indeed when this page is being written down, the feature is still missing in Firestorm.
  
<lsl>
+
<source lang="lsl2">
// Script eraser by Dahlia Orfan (2012)  
+
// Script eraser by Dahlia Orfan (2012)
// Drop this script in a linkset (rezzed on the ground or attachment)
+
// Drop this script in a linkset (rezzed on the ground or attachment)
// When the script tells that it is ready, unrez and rerez the linkset
+
// When the script tells that it is ready, unrez and rerez the linkset
// Set all scripts to running using the menu of the viewer
+
// Set all scripts to running using the menu of the viewer
// Wait until it is done.  http://pastebin.com/gqi7mKFE
+
// Wait until it is done.  http://pastebin.com/gqi7mKFE
  
 
integer prims;
 
integer prims;
 
integer DELETE;
 
integer DELETE;
  
erase()
+
//  remove all other scripts, then this one
 +
remove_scripts()
 
{
 
{
     integer n = llGetInventoryNumber(INVENTORY_SCRIPT);
+
    string thisScript = llGetScriptName();
     while(n)
+
 
 +
     integer index = llGetInventoryNumber(INVENTORY_SCRIPT);
 +
     string scriptName;
 +
 
 +
    //  start with last script which has the index (numberOfScripts - 1)
 +
    do
 
     {
 
     {
         --n;
+
         --index;
         if (llGetInventoryName(INVENTORY_SCRIPT,n) != llGetScriptName())
+
         scriptName = llGetInventoryName(INVENTORY_SCRIPT, index);
             llRemoveInventory(llGetInventoryName(INVENTORY_SCRIPT,n));
+
 
 +
        if (scriptName != thisScript)
 +
             llRemoveInventory(scriptName);
 
     }
 
     }
 +
    while (index);
 +
 +
    //  at last remove this script
 +
    llRemoveInventory(thisScript);
 
}
 
}
  
 +
default
 +
{
 +
    state_entry()
 +
    {
 +
        //  set an ident number code
 +
        DELETE = (integer) ("0x" + (string) llGetOwner() );
 +
        integer link = llGetLinkNumber();
  
  default
+
        // the root prim has link number 0 for single prim objects and 1 for linksets
{
+
        if (link < 2)
    link_message(integer sender_num, integer num, string str, key id)
+
        {
    {
+
            prims = llGetObjectPrimCount(llGetKey() );       // Get number of prims excluding seated avatars
        if (num == DELETE)
+
        {
+
            --prims;
+
            llSetText((string)prims + " prims to clean up.",<1.0,1.0,1.0>,1.0);
+
            if (prims == 1)
+
            {
+
                erase();
+
                llOwnerSay("done.");
+
                llSetText("",<1.0,1.0,1.0>,1.0);
+
                llRemoveInventory(llGetScriptName());
+
            }
+
        }
+
    }
+
  
    state_entry()
+
            //  if single prim, else linkset
    {
+
            if (prims == 1)
        DELETE = (integer)("0x"+llGetSubString(llMD5String((string)llGetOwner(),31415),0,6));
+
            {
        if (llGetLinkNumber() <= 1)
+
                llSay(0, "Done removing scripts.");
        {
+
                remove_scripts();
            prims = llGetNumberOfPrims();
+
            }
            if(1 < prims)
+
            else
                while(llGetAgentSize(llGetLinkKey(prims)))
+
            {
                    --prims;
+
                integer n = prims;
           
+
                while(n > 1)
            if (prims >= 2)
+
                {
            {
+
                    llGiveInventory(llGetLinkKey(n), llGetScriptName());
                llOwnerSay("Duplication of the script in all child prims.");
+
                    --n;
                integer n = prims;
+
                }
                while(n > 1)
+
                llSay(0, "Please take this object back to your inventory and "
                {
+
                    + "rez it again. Then edit the object (ctrl+3), go to the menu at the "
                    llGiveInventory(llGetLinkKey(n),llGetScriptName());
+
                    + "top of your viewer and select BUILD > SCRIPTS > SET SCRIPTS TO RUNNING.");
                    --n;
+
            }
                }
+
        }
                llSetText((string)prims + " prims to clean up.",<1.0,1.0,1.0>,1.0);
+
        else//  not the root prim
                llOwnerSay("Unrez and rerez the linkset; set scripts to running using the menu of the viewer to erase all scripts in child prims.");
+
        {
            }
+
            llMessageLinked(LINK_ROOT, DELETE, "", NULL_KEY);
            else  
+
            remove_scripts();
            {
+
        }
                erase();
+
    }
                llOwnerSay("done.");
+
 
                llSetText("",<1.0,1.0,1.0>,1.0);
+
    link_message(integer sender_num, integer num, string str, key id)
                llRemoveInventory(llGetScriptName());
+
    {
            }
+
        //  if the received linkmessage contains the ident number code previously stored...
        }
+
        if (num == DELETE)
        else
+
        {
        {
+
            --prims;
            erase();
+
            if (prims == 1)
            llMessageLinked(LINK_ROOT,DELETE,"",NULL_KEY);
+
            {
            llRemoveInventory(llGetScriptName());
+
                llSay(0, "Done removing scripts.");
        }
+
                remove_scripts();
    }
+
            }
}
+
        }
</lsl>
+
    }
 +
}
 +
</source>

Latest revision as of 19:07, 24 January 2015

This simple script removes all scripts contained in a linkset. I had found one on the Internet but for an unknown reason, it moves the linkset (see [1]) ?! This one is simple, and works for attachments and rezzed objects. Just drop the script in the linkset (so in the root prim). If the linkset is one single prim, there is nothing else to do. Otherwise, when the script tells you that it is ready, unrez/re-rez the object and set all scripts to running using the menu of the viewer. That's all. An hovertext shows the number of remaining prims to be cleaned up. This script is very useful for example for Firestorm's users: indeed when this page is being written down, the feature is still missing in Firestorm.

//  Script eraser by Dahlia Orfan (2012)
//  Drop this script in a linkset (rezzed on the ground or attachment)
//  When the script tells that it is ready, unrez and rerez the linkset
//  Set all scripts to running using the menu of the viewer
//  Wait until it is done.   http://pastebin.com/gqi7mKFE
 
integer prims;
integer DELETE;
 
//  remove all other scripts, then this one
remove_scripts()
{
    string thisScript = llGetScriptName();
 
    integer index = llGetInventoryNumber(INVENTORY_SCRIPT);
    string scriptName;
 
    //  start with last script which has the index (numberOfScripts - 1)
    do
    {
        --index;
        scriptName = llGetInventoryName(INVENTORY_SCRIPT, index);
 
        if (scriptName != thisScript)
            llRemoveInventory(scriptName);
    }
    while (index);
 
    //  at last remove this script
    llRemoveInventory(thisScript);
}
 
default
{
    state_entry()
    {
        //  set an ident number code
        DELETE = (integer) ("0x" + (string) llGetOwner() );
        integer link = llGetLinkNumber();
 
        //  the root prim has link number 0 for single prim objects and 1 for linksets
        if (link < 2)
        {
            prims = llGetObjectPrimCount(llGetKey() );        // Get number of prims excluding seated avatars
 
            //  if single prim, else linkset
            if (prims == 1)
            {
                llSay(0, "Done removing scripts.");
                remove_scripts();
            }
            else
            {
                integer n = prims;
                while(n > 1)
                {
                    llGiveInventory(llGetLinkKey(n), llGetScriptName());
                    --n;
                }
                llSay(0, "Please take this object back to your inventory and "
                    + "rez it again. Then edit the object (ctrl+3), go to the menu at the "
                    + "top of your viewer and select BUILD > SCRIPTS > SET SCRIPTS TO RUNNING.");
            }
        }
        else//  not the root prim
        {
            llMessageLinked(LINK_ROOT, DELETE, "", NULL_KEY);
            remove_scripts();
        }
    }
 
    link_message(integer sender_num, integer num, string str, key id)
    {
        //  if the received linkmessage contains the ident number code previously stored...
        if (num == DELETE)
        {
            --prims;
            if (prims == 1)
            {
                llSay(0, "Done removing scripts.");
                remove_scripts();
            }
        }
    }
}