Difference between revisions of "User:Susie Chaffe"

From Second Life Wiki
Jump to navigation Jump to search
(Created page with ''''SLFS''' - Second Life Ferry Service Due to severed problems with Sim crossings this project is currently on hold as of Feb 2010')
 
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
'''SLFS''' - Second Life Ferry Service
<lsl>
// Dialog Based Object Rezzer Script
// Susie Chaffe 2013
// Free to use modify and mangle as you see fit


Due to severed problems with Sim crossings this project is currently on hold as of Feb 2010
// No Limit on Number of Object Names
// Handles 24 character limit by creating alised object names
// Has the option to create custom buttons / submenus if required
// Is a little long winded for the sake of clarity
 
//======================= SYSTEM VARIABLES ==========================//
 
vector  vRezPos = <0.00, 0.00, 1.00>;
integer dialogChannel;
integer dialogHandle;
integer iInvType = INVENTORY_OBJECT;
integer iPageIdx = 0;
list    lstShortName;
 
//======================= CUSTOM FUNCTIONS ==========================//
 
// Create Short name for Long Object Names and add to a look up list
// Note that only the first 12 characters will normally show on the menu button
// You can use a shorter substring if you prefer
string AliasName(string sLongName)
{
    string sShortName = (llGetSubString(sLongName,0,23));
    lstShortName += [sShortName,sLongName];
    return sShortName;
}
 
// Reorder Buttons as shown in list
list order(list buttons)
{
    return llList2List(buttons, -3, -1) + llList2List(buttons, -6, -4) + llList2List(buttons, -9, -7) + llList2List(buttons, -12, -10);
}
 
// Dynamic menu dialog function
doDialog(key av)
{
    // Standard Buttons that will appear on every page - normally navigation buttons
    list lstStatic = ["<< PREV","< MAIN >","NEXT >>"];
    integer iBtnSlots = 12-llGetListLength(lstStatic);
 
    // Optional extra buttons that will only appear on the first page
    // Can be used to create sub-menus if required
    // list lstExtraBtn = []; // **Use this if you no extra buttons
    list lstExtraBtn = ["-CONTENTS-"];  // ** This is just an example
    integer iAdjSlots = llGetListLength(lstExtraBtn);
 
    // Dynamic buttons - read from inventory object names
    integer iTotalNames = llGetInventoryNumber(iInvType);
 
    // Calculate menu last page index
    integer iMaxPageIdx = (llFloor((float) (iTotalNames + iAdjSlots) / (float) iBtnSlots));
 
    // First & Last Page Navigation Toggle
    if (iPageIdx < 0 ) iPageIdx = iMaxPageIdx;
    else if (iPageIdx > iMaxPageIdx) iPageIdx = 0;
 
    // Build the button list
    list lstDialog = [];
    lstShortName = [];
    integer idxSlot = iPageIdx*iBtnSlots;
 
    integer i;
    // First menu page that has extra buttons
    if((0 == iPageIdx) && ([] != lstExtraBtn))
    {
        for(i = idxSlot; (i < idxSlot+iBtnSlots-iAdjSlots) && (i <= iTotalNames-1 ); i++)
        {
            string sItemName = llGetInventoryName(iInvType,i);
            if(24 < llStringLength(sItemName)) sItemName = AliasName(sItemName);
            lstDialog += [sItemName];
        }
        //Add the Extra button(s)
        lstDialog += lstExtraBtn;
    }
 
    // Other Pages or First Page if no extra buttons
    else
    {
        for(i = idxSlot; (i < idxSlot+iBtnSlots) && (i <= iTotalNames-1 + iAdjSlots); i++)
        {
            string sItemName = llGetInventoryName(iInvType,i-iAdjSlots);
            if(24 < llStringLength(sItemName)) sItemName = AliasName(sItemName);
            lstDialog += [sItemName];
        }
    }
 
    // Add Static Btns to the end of the Dyanamic List
    lstDialog += lstStatic;
 
    // Menu message
    string msg = " \n Choose an Option: "  + "Page " + (string) (iPageIdx+1) + " of " + (string) (iMaxPageIdx + 1);
 
    //Open a Listen
    dialogChannel = (integer)llFrand(DEBUG_CHANNEL)*-1;
    dialogHandle = llListen(dialogChannel, "", "", "");
 
    // Call Function and set a time out for the listen
    llDialog(av, msg , order(lstDialog), dialogChannel);
    llSetTimerEvent(30.0);
}
 
close_menu()
{
    llSetTimerEvent(0);
    llListenRemove(dialogHandle);
}
 
//=============================== RUN TIME =========================================//
 
default
{
    touch_start(integer total_number)
    {
        key id = llDetectedKey(0);
        close_menu();
        doDialog(id);
    }
 
    listen( integer channel, string name, key id, string msg )
    {
        close_menu();
 
        if(msg == "< MAIN >")
        {
            iPageIdx=0;
            doDialog(id);
            return;
        }
 
        else if(msg == "<< PREV")
        {
            iPageIdx--;
            doDialog(id);
        }
 
        else if(msg == "NEXT >>")
        {
            iPageIdx++;
            doDialog(id);
        }
 
        else if(llGetInventoryType(msg) == 6)
        {
            llRezObject(msg, llGetPos() + vRezPos, ZERO_VECTOR, llGetRot(), 0);
        }
 
        else if(~llListFindList(lstShortName, [msg]))
        {
            integer idx = llListFindList(lstShortName, [msg]);
            llRezObject(llList2String(lstShortName,idx+1), llGetPos() + vRezPos, ZERO_VECTOR, llGetRot(), 0);
        }
        // Example of Extra Button
        else if(msg == "-CONTENTS-") llSay(0, "There are " + (string) llGetInventoryNumber(iInvType) + " items in this container");
    }
 
    timer()
    {
        close_menu();
    }
}
 
//=============================================================================================//
</lsl>

Latest revision as of 04:14, 23 July 2013

<lsl> // Dialog Based Object Rezzer Script // Susie Chaffe 2013 // Free to use modify and mangle as you see fit

// No Limit on Number of Object Names // Handles 24 character limit by creating alised object names // Has the option to create custom buttons / submenus if required // Is a little long winded for the sake of clarity

//======================= SYSTEM VARIABLES ==========================//

vector vRezPos = <0.00, 0.00, 1.00>; integer dialogChannel; integer dialogHandle; integer iInvType = INVENTORY_OBJECT; integer iPageIdx = 0; list lstShortName;

//======================= CUSTOM FUNCTIONS ==========================//

// Create Short name for Long Object Names and add to a look up list // Note that only the first 12 characters will normally show on the menu button // You can use a shorter substring if you prefer string AliasName(string sLongName) {

   string sShortName = (llGetSubString(sLongName,0,23));
   lstShortName += [sShortName,sLongName];
   return sShortName;

}

// Reorder Buttons as shown in list list order(list buttons) {

   return llList2List(buttons, -3, -1) + llList2List(buttons, -6, -4) + llList2List(buttons, -9, -7) + llList2List(buttons, -12, -10);

}

// Dynamic menu dialog function doDialog(key av) {

   // Standard Buttons that will appear on every page - normally navigation buttons
   list lstStatic = ["<< PREV","< MAIN >","NEXT >>"];
   integer iBtnSlots = 12-llGetListLength(lstStatic);
   // Optional extra buttons that will only appear on the first page
   // Can be used to create sub-menus if required
   // list lstExtraBtn = []; // **Use this if you no extra buttons
   list lstExtraBtn = ["-CONTENTS-"];  // ** This is just an example
   integer iAdjSlots = llGetListLength(lstExtraBtn);
   // Dynamic buttons - read from inventory object names
   integer iTotalNames = llGetInventoryNumber(iInvType);
   // Calculate menu last page index
   integer iMaxPageIdx = (llFloor((float) (iTotalNames + iAdjSlots) / (float) iBtnSlots));
   // First & Last Page Navigation Toggle
   if (iPageIdx < 0 ) iPageIdx = iMaxPageIdx;
   else if (iPageIdx > iMaxPageIdx) iPageIdx = 0;
   // Build the button list
   list lstDialog = [];
   lstShortName = [];
   integer idxSlot = iPageIdx*iBtnSlots;
   integer i;
   // First menu page that has extra buttons
   if((0 == iPageIdx) && ([] != lstExtraBtn))
   {
       for(i = idxSlot; (i < idxSlot+iBtnSlots-iAdjSlots) && (i <= iTotalNames-1 ); i++)
       {
           string sItemName = llGetInventoryName(iInvType,i);
           if(24 < llStringLength(sItemName)) sItemName = AliasName(sItemName);
           lstDialog += [sItemName];
       }
       //Add the Extra button(s)
       lstDialog += lstExtraBtn;
   }
   // Other Pages or First Page if no extra buttons
   else
   {
       for(i = idxSlot; (i < idxSlot+iBtnSlots) && (i <= iTotalNames-1 + iAdjSlots); i++)
       {
           string sItemName = llGetInventoryName(iInvType,i-iAdjSlots);
           if(24 < llStringLength(sItemName)) sItemName = AliasName(sItemName);
           lstDialog += [sItemName];
       }
   }
   // Add Static Btns to the end of the Dyanamic List
   lstDialog += lstStatic;
   // Menu message
   string msg = " \n Choose an Option: "  + "Page " + (string) (iPageIdx+1) + " of " + (string) (iMaxPageIdx + 1);
   //Open a Listen
   dialogChannel = (integer)llFrand(DEBUG_CHANNEL)*-1;
   dialogHandle = llListen(dialogChannel, "", "", "");
   // Call Function and set a time out for the listen
   llDialog(av, msg , order(lstDialog), dialogChannel);
   llSetTimerEvent(30.0);

}

close_menu() {

   llSetTimerEvent(0);
   llListenRemove(dialogHandle);

}

//=============================== RUN TIME =========================================//

default {

   touch_start(integer total_number)
   {
       key id = llDetectedKey(0);
       close_menu();
       doDialog(id);
   }
   listen( integer channel, string name, key id, string msg )
   {
       close_menu();
       if(msg == "< MAIN >")
       {
           iPageIdx=0;
           doDialog(id);
           return;
       }
       else if(msg == "<< PREV")
       {
           iPageIdx--;
           doDialog(id);
       }
       else if(msg == "NEXT >>")
       {
           iPageIdx++;
           doDialog(id);
       }
       else if(llGetInventoryType(msg) == 6)
       {
           llRezObject(msg, llGetPos() + vRezPos, ZERO_VECTOR, llGetRot(), 0);
       }
       else if(~llListFindList(lstShortName, [msg]))
       {
           integer idx = llListFindList(lstShortName, [msg]);
           llRezObject(llList2String(lstShortName,idx+1), llGetPos() + vRezPos, ZERO_VECTOR, llGetRot(), 0);
       }
       // Example of Extra Button
       else if(msg == "-CONTENTS-") llSay(0, "There are " + (string) llGetInventoryNumber(iInvType) + " items in this container");
   }
   timer()
   {
       close_menu();
   }

}

//=============================================================================================// </lsl>