User:LindaB Helendale/removeAllScripts

From Second Life Wiki
Jump to navigation Jump to search

The script below removes all the scripts from a linkset. Unfortunately it cannot be made fully automatic, see the comments in the script, but this is the easiest way I could figure out.

 
/**
Remove all scripts from linkset by LindaB Helendale
Permission to use this script in any way granted.

Usage:
  1. Drop this script in the root prim.
  2. Take the object in the inventory, and rez it again
  2. Select the object and choose Build>Scripts>Set Scripts to Running

Running scripts cannot be installed without remote PIN, so we can only 
drop the scripts in the child prims and set them running manually. 
With give inventory scripts reach destination disabled (not running, 
and cannot be made to run unless the destination object is taken 
to inventory and rezzed again, or the script is recompiled).

Recompiling from Build>Scripts>Recompile is not reliable, since the object
inventory may not be up to date and some of the inserted cleaning scripts 
may not be compiled. Taking the object back to inv and rerezzing refreshes 
the inventory and it should work... 'should work' in SL sense ;)

After getting the scripts compiled, set them running from
Build>Scripts>Set Scripts to Running

NOTE: if you drop this in a child prim, it will clean only that prim. 
**/

remove_all_scripts() {
    integer N=llGetInventoryNumber(INVENTORY_SCRIPT)-1;
    string me=llGetScriptName();
    string msg="Link #" + (string)llGetLinkNumber();
    if (llGetLinkNumber()<=1) {
        msg += " (root)";
    }
    msg +=  ": removing " + (string)N + " scripts";
    llOwnerSay(msg);
    while(N>=0) {
        string s=llGetInventoryName(INVENTORY_SCRIPT,N--);
        if (s!=me) {
            llRemoveInventory(s);
        }
    }
    llRemoveInventory(me);
}

default
{
    state_entry()
    {        
        integer numLinks = llGetNumberOfPrims();
        if (numLinks>1) {
            if (llGetLinkNumber()==1) {
                integer i;
                for(i=2;i<=numLinks;i++) {
                    llGiveInventory(llGetLinkKey(i),llGetScriptName());
                }
                llOwnerSay("To clean the " + (string)(numLinks-1) + " child prims, you have to start the cleaning scripts inserted in them. \n1) Take the object back in the inv, and rez it.\n2) Select the object and choose Build>Scripts>Set Scripts to Running");
            }
        }
        remove_all_scripts();
    }
}