Simple Texture Changer (for inventory)(all prims & all sides).lsl

From Second Life Wiki
Revision as of 21:03, 24 January 2015 by Lady Sumoku (talk | contribs) (Replaced old <LSL> block with <source lang="lsl2">)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Part of Bobbyb's texture changer collection

//https://wiki.secondlife.com/wiki/Simple_Texture_Changer_(input_list)(multiple_prims_%26_multiple_sides).lsl
//***********************************************************************************************************
//                                                                                                          *
//              --Simple Texture Changer (for inventory)(all prims & all sides)--                           *
//                                                                                                          *
//***********************************************************************************************************
// www.lsleditor.org  by Alphons van der Heijden (SL: Alphons Jano)
//Creator: Bobbyb30 Swashbuckler
//Attribution: None required, but it is appreciated.
//Created: November 12, 2008
//Last Modified: November 28, 2009
//Released: Saturday, November 28, 2009
//License: Public Domain

//Status: Fully Working/Production Ready
//Version: 1.0.3

//Name: Simple Texture Changer (for inventory)(all prims & all sides).lsl
//Purpose: To change the texture on all the prims and all of their sides based on the textures in inventory.
//Technical Overview: The script finds how many textures there are in inventory, and uses a timer to change the
//                    texture on a side based on randomness or order. It takes into account inventory changes. It uses
//                    a user defined list to determine which sides to change.
//Description: A simple texture changer script that changes the texture on all the sides of all the prims in a
// 			   linked prim set to those in inventory. It allows for a random order, or a logical "next up" order.
//Directions: Create a prim. Place pictures in prim inventory. Place script in prim inventory. Modify script parameters
//            to suit your needs. If you add pictures, and the script does not reset, manually reset the script.

//Compatible: Mono & LSL compatible
//Other items required: More than 1 texture in inventory.
//Notes: Uses a timer event. Should be low lag. Commented for easier following. This will change the all the sides
//       of linked prims to the *same* texture.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Adjustable global variables...you may change these
//Please note there is a .2 second delay between prims.
//all prims all sides
float frequency = 2.0;//how often to change the texture in seconds. Shouldn't be below 2.0

//please note that the last and first texture will be shown less frequently than those in between
integer random = TRUE;//whether to show the textures randomly, or in order
integer duplicatecheck = TRUE;//if random is true, this will check to make sure the random selection is a new texture
integer atonce = FALSE;//whether to change all the prims at once, or one at a time

/////////////////////////////////////////////////////////////
//global variables...do not change
integer numberoftextures;//number of textures in inventory
integer currenttexture;//inventory number of current texture
integer numberofprims;//the number of prims there are

changetexture()//user fucntion to change texture;
{

    string texture = llGetInventoryName(INVENTORY_TEXTURE,currenttexture);//gets texture key
    if(atonce)
        llSetLinkTexture(LINK_SET,texture,ALL_SIDES);
    else
    {
        integer counter=1;
        do
        {
            llSetLinkTexture(counter,texture,ALL_SIDES);
        }while(++counter < (numberofprims + 1));
    }
}

default
{
    on_rez(integer start_param)//on rez reset...probably not needed.
    {
        llResetScript();
    }
    state_entry()
    {
        llOwnerSay("Simple Texture Changer (for inventory)(all prims & all sides).lsl' (Public Domain 2009)");
        llOwnerSay("Because knowledge should be free.");
        numberoftextures = llGetInventoryNumber(INVENTORY_TEXTURE);//number of textures in inventory
        numberofprims = llGetNumberOfPrims();
        if(numberoftextures <= 0)//no textures
            llOwnerSay("No textures were found in my inventory. Please add textures.");
        else if(numberoftextures == 1)//only 1 texture
            llOwnerSay("I only found 1 picture in my inventory. I need more in order to change them.");
        //for 2 random isn't needed...but I'm too lazy to add that in
        else//more than 1 texture found...
        {
            llOwnerSay("I found " + (string)numberoftextures + " pictures which I will change every "
                + (string)frequency + " seconds on " + (string)numberofprims + " prims.");
            llSetTimerEvent(frequency);
        }
    }
    timer()
    {
        if(random)//show pics randomly
        {
            integer randomtexture;
            if(duplicatecheck)//whether to make sure random doesn't repeat itself
            {
                do
                {
                    randomtexture= llRound(llFrand(numberoftextures - 1));
                    //llOwnerSay("r" + (string)randomtexture);//debug
                }while(randomtexture == currenttexture);//make sure the random one isn't the same as the current one
            }
            else//no duplicate check
                randomtexture = llRound(llFrand(numberoftextures - 1));//generate random texture number
            currenttexture = randomtexture;//set the current one to the random one selected
            changetexture();//change the texture
            //llOwnerSay("c" + (string)currenttexture);//debug
        }
        else//not random, go in order
        {
            ++currenttexture;
            if(currenttexture == numberoftextures)//if current texture = number of textures, reset counter
                currenttexture = 0;
            changetexture();//change the texture
            //llOwnerSay("c" + (string)currenttexture);//debug
        }
    }
    changed(integer change)
    {
        if(change & CHANGED_INVENTORY)//new or removed inventory...update texture count
        {
            llOwnerSay("Inventory change detected.");
            numberoftextures = llGetInventoryNumber(INVENTORY_TEXTURE);
            llOwnerSay("I found " + (string)numberoftextures + " pictures which I will change every "
                + (string)frequency + " seconds on " + (string)numberofprims + " prims."); 		}
        else if(change & CHANGED_LINK)//new or removed prims...update prim count
        {
            llOwnerSay("Object links changed.");
            numberofprims = llGetNumberOfPrims();
            llOwnerSay("This object has " + (string)numberofprims + " prims.");

        }
    }
}