Menu driven Texture Changer

Written by: Headmaster

found on the SL Texture Library written by Jessica Margetts:

// Here is a menu based texture changing script, that has no limits on the number of pages textures it can support.

// PLEASE remember that textures MUST HAVE full permissions in order to be used with it.

integer         INVENTORY_TYPE  = INVENTORY_TEXTURE;
integer         PAGES;
integer         PAGE            = 1;
integer         COM_CHAN        = -278976;
integer         LISTENER;
integer         NEEDED_PERMS;

list            THIS_PAGE;
list            LIST_NAV_X      = ;
list            LIST_NAV_A      = ;
list            LIST_NAV_B      = ;
list            LIST_NAV_C      = ;

string          PAGE_NAV_NULL   = "    ";
string          PAGE_NAV_NEXT   = "NEXT";
string          PAGE_NAV_BACK   = "BACK";
string          PAGE_NAV_HOME   = "HOME";

integer ptTestPerms(string item, integer needed)
{
    integer perm = llGetInventoryPermMask(item, MASK_OWNER);
    if ((perm & needed) == needed) { return(TRUE); }
    return(FALSE);
}

ptDisplayPage(key theUser) {
    integer     TEXTURES    = llGetInventoryNumber(INVENTORY_TYPE);
    integer     I;
    integer     START;
    integer     STOP;
    string      INTRO       = "Page " + (string) PAGE + " of " + (string) PAGES;
    string      NEW_LINE;
    string      ITEM_NAME;
    string      T;
    list        MENU;
   
   
    if (TEXTURES >= 1) {
        PAGES       = 1 + (llFloor((float) TEXTURES / 9.0));
        INTRO       = "Page " + (string) PAGE + " of " + (string) PAGES;
        if (TEXTURES <= 9) {
            MENU = [] + LIST_NAV_X;
            for (I = 0; I < TEXTURES; ++I)
            {
                T           = (string) (I + 1);
                ITEM_NAME   = llGetInventoryName(INVENTORY_TYPE, I);
                if (ptTestPerms(ITEM_NAME, NEEDED_PERMS)) {               
                    NEW_LINE    = "\n" + T + "- " + ITEM_NAME;
                    INTRO       = "" + INTRO + NEW_LINE;
                    MENU        = [] + MENU + ;
                } else {
                    NEW_LINE    = "\n" + T + "- ~BLOCKED ~";
                    INTRO       = "" + INTRO + NEW_LINE;
                    MENU        = [] + MENU + ;
                }
            }
        } else {
            if ((PAGE == 1) || (PAGE > PAGES)) {
                PAGE = 1;
                MENU = [] + LIST_NAV_A;
            } else if ((PAGE == PAGES) || (PAGE < 1)) {
                MENU = [] + LIST_NAV_C;
            } else {
                MENU = [] + LIST_NAV_B;
            }
            START       = ((PAGE - 1) * 9);
            STOP        = (PAGE * 9);
            if (STOP > TEXTURES) { STOP = TEXTURES - 1; }
            INTRO       = "Page " + (string) PAGE + " of " + (string) PAGES;
           
            for (I = START; I < STOP; ++I)
            {
                T           = (string) (I + 1);
                ITEM_NAME   = llGetInventoryName(INVENTORY_TYPE, I);
                NEW_LINE    = "\n" + T + "- " + ITEM_NAME;
                INTRO       = "" + INTRO + NEW_LINE;
                MENU        = [] + MENU + ;
            }
        }  
        llDialog(theUser, INTRO, MENU, COM_CHAN);
    }
}

default
{
    state_entry()
    {
        NEEDED_PERMS    = PERM_COPY | PERM_MODIFY | PERM_TRANSFER;
        //LISTENER    = llListen(COM_CHAN, "", llGetOwner(), "");
        LISTENER    = llListen(COM_CHAN, "", NULL_KEY, "");
    }
   
    on_rez(integer param) { llResetScript(); }
   
    touch_start(integer total)
    {
        key     agent   = llDetectedKey(0);
        PAGE            = 1;
        //if (agent == llGetOwner()) {
            ptDisplayPage(agent);
        //}
    }
   
    listen(integer channel, string name, key agent, string message) {
        integer TEXTURE_CHOICE = (integer) message;
        if (!TEXTURE_CHOICE) {
            if (message == PAGE_NAV_NEXT) { ++PAGE; }
            if (message == PAGE_NAV_BACK) { --PAGE; }
            if (message == PAGE_NAV_HOME) { PAGE=1; }
            ptDisplayPage(agent);
        } else {
            key         DOITNOW;
            integer     CHOICE  = TEXTURE_CHOICE - 1;
            string      SHOWIT  = llGetInventoryName(INVENTORY_TYPE, CHOICE);
            if (ptTestPerms(SHOWIT, NEEDED_PERMS)) {
                DOITNOW     = llGetInventoryKey(SHOWIT);
            } else {
                DOITNOW     = "3651326d-9398-a600-7fe0-10db365896b9";
            }
           
            llSetLinkTexture(LINK_SET, DOITNOW, ALL_SIDES);
            ptDisplayPage(agent);
        }
    }
}