Difference between revisions of "User:Susie Chaffe"

From Second Life Wiki
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
''''''SLFS''' - Susie's Little Ferry Service'''
<lsl>
// Dialog Based Object Rezzer Script
// Susie Chaffe 2013
// Free to use modify and mangle as you see fit


Latest News
// 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


Latest Project - Learining how to format this wiki page ----aaagh
//======================= SYSTEM VARIABLES ==========================//


March 2010 - The ferries are back up and running. I am testing a new boat with START/STOP Controls
vector  vRezPos = <0.00, 0.00, 1.00>;
integer dialogChannel;
integer dialogHandle;
integer iInvType = INVENTORY_OBJECT;
integer iPageIdx = 0;
list    lstShortName;


FAQ's
//======================= CUSTOM FUNCTIONS ==========================//


Q  What is SLFS ?
// Create Short name for Long Object Names and add to a look up list
A  "Susie's Little Ferry Service"
// Note that only the first 12 characters will normally show on the menu button
     It was concieved as a safe way to see the Mainland Continents without running into "Ban Lines"
// You can use a shorter substring if you prefer
string AliasName(string sLongName)
{
    string sShortName = (llGetSubString(sLongName,0,23));
    lstShortName += [sShortName,sLongName];
     return sShortName;
}


Q  Where can I catch a ferry ?
// Reorder Buttons as shown in list
A  At a Rez Point - touch the notecard giver at my "Ferry Bar" for the most current list
list order(list buttons)
{
    return llList2List(buttons, -3, -1) + llList2List(buttons, -6, -4) + llList2List(buttons, -9, -7) + llList2List(buttons, -12, -10);
}


Q  What are the routes ?
// Dynamic menu dialog function
A  see below
doDialog(key av)
{
    // Standard Buttons that will appear on every page - normally navigation buttons
    list lstStatic = ["<< PREV","< MAIN >","NEXT >>"];
    integer iBtnSlots = 12-llGetListLength(lstStatic);


Q  What determines the speed
    // Optional extra buttons that will only appear on the first page
A The speed is the best compromise I can find for allowing textures to load, objects to rez and being reasonably safe for sim crossings
    // 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);


Q  The boat is a bit basic
    // Dynamic buttons - read from inventory object names
A  As a vehicle it can only use 32 prims (and that includes passengers who count as 1 prim each)
    integer iTotalNames = llGetInventoryNumber(iInvType);
      The simpler the vehicle the safer it is at crossing sim boundaries


Q  Why does the boat seem to slow down and then jump forward
    // Calculate menu last page index
A  This is an illusion caused by "lag", the boat is actually moving at a constant speed
    integer iMaxPageIdx = (llFloor((float) (iTotalNames + iAdjSlots) / (float) iBtnSlots));
      This effect is most noticeable in areas with lots of objects (especially sculpties) or large groups of avatars.
 
      Try adjusting your view point by using the mouse or arrow keys
    // First & Last Page Navigation Toggle
     
    if (iPageIdx < 0 ) iPageIdx = iMaxPageIdx;
Q.  Can you let me know when you have made a new route
    else if (iPageIdx > iMaxPageIdx) iPageIdx = 0;
A.  Touch the subscribe-o-matic in the SL Ferry Bar to be added to the updates mailing list
 
      Note this does not use any of your group slots
    // Build the button list
         
    list lstDialog = [];
Q. The route seems to be blocked
    lstShortName = [];
A. Please put the details into a notecard and drop it on my profile (my IM's get capped)
    integer idxSlot = iPageIdx*iBtnSlots;
    The mainland does change and sometimes people inadvertantly block a protected route.
 
<nowiki>Insert non-formatted text here</nowiki>
    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>