Script Remover for Link Sets

Written by Kitsune
// SCRIPT REMOVER by Dora Gustafson, Studio Dora 2010
// Based on 'Script eraser v1.2' Script by Dora Gustafson 2008
// Place script in the root of the object you want to clean for scripts and follow the instructions
// v1.01 monitor number of scripts started
 vector position_original;
integer primNo;
integer childcount = 1;
float eb_delay = 0.03125; // seconds to hold script. Defeat event buffer limit (64 events)
 eraser()
{  // erase all scripts from prim
    integer i = 0;
    string s;
    string thisScript = llGetScriptName();
    do
    {    s = llGetInventoryName( INVENTORY_SCRIPT, i );
         if ( s != thisScript ) llRemoveInventory( s );
         else ++i; // don't erase skip it
    }
    while ( llGetInventoryNumber( INVENTORY_SCRIPT ) > 1 );
    if ( primNo == 1 )
    {
        llOwnerSay("All scripts have been removed from this object");
        llSetText("", <1.0, 1.0, 1.0>, 1.0);
    }
    llRemoveInventory( thisScript ); // remove this as the last
}
 default
{
    state_entry()
    {
        integer dg;
        primNo = llGetLinkNumber();
        if ( primNo == 1 )
        {
            childcount = 1;
            position_original = llGetPos();
            for ( dg = 2; dg <= llGetNumberOfPrims(); dg++ ) llGiveInventory( llGetLinkKey( dg ), llGetScriptName());
            llOwnerSay("\n1. Take this object into Inventory!\n2. Rezz it back into the world!\n(will snap in position if less than 10m from where it was)");
        }
        else if (primNo > 1)
        {
            llSleep( eb_delay*primNo );
            llMessageLinked( LINK_ROOT, FALSE, "child running", NULL_KEY);
        }
    }
    on_rez( integer parm )
    {
        if ( !primNo )
        {  // if linkset is just one prim, probably the box it is sold in
            llOwnerSay("\nOpen prim and save script in inventory before use:\nPlace script in the object you want to clean and follow the instructions\nCongratulations with this SCRIPT REMOVER by Dora Gustafson, Studio Dora");
        }
        else if ( primNo == 1 )
        {
            llSetPos( position_original );
            llOwnerSay( "\n3. Select and 'Set Scripts to Running in Selection'");
        }
    }
    link_message(integer targ, integer num, string instruct, key id)
    {
        if ( instruct == "Erase Only" ) eraser();
        else if ( instruct == "child running" )
        {
            if ( ++childcount == llGetNumberOfPrims() ) llMessageLinked( LINK_SET, FALSE, "Erase Only", NULL_KEY);
            llSetText( (string)(llGetNumberOfPrims()-childcount)+" scripts are NOT running", <1.0, 1.0, 1.0>, 1.0);
        }
    }
}