ZenMondo's Notecard Library

From ZenMondo Wormser, 1 Year ago, written in Linden Scripting, viewed 345 times.
URL http://flynnos.org/flynnbin/view/70ad68a5 Embed
Download Paste or View Raw
  1. /////////////////////////////////////////
  2. // ZenMondo's NoteCard Library by ZenMondo Wormser
  3. // Based on ZenMondo's Item Giver 2.21
  4. // Developed for Caledon Library System
  5. //  
  6. // Menu-Driven Notecard Giver.
  7. // Can be Used by one person at a time.
  8. //////////////////////////////////////
  9.  
  10. ///////////////////////////
  11. // This work is licensed under the Creative Commons Attribution-Noncommercial-Share
  12. // Alike 3.0 License. To view a copy of this license, visit
  13. // http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative
  14. // Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
  15. //
  16. // Attribution:
  17. //  If unmodified you must keep the filename intact
  18. //  If a derivative work you must say "Based on the CodePoetry of ZenMondo Wormser"
  19. //////////////////////////
  20.  
  21. //Global Variables
  22.  
  23. //Folder Name for when patron selects "Get All"
  24. string folder_name = "From the Ruusan Jedi Archives";
  25.  
  26. //Text that will float over object
  27. string float_text = "From the Ruusan Jedi Archives\n Pray, touch and receive.";
  28.  
  29. integer object_counter=0;
  30. list inventory_list = [];
  31. list menu_list = [];
  32.  
  33. integer menu_page;
  34. integer last_menu;
  35.  
  36. integer handle;
  37. integer UserChan = -11811;
  38.  
  39. key current_user = NULL_KEY;
  40.  
  41. integer using;
  42.  
  43. //Functions
  44.  
  45. //Compact function to put buttons in "correct" human-readable order ~ Redux
  46. //Taken from http://lslwiki.net/lslwiki/wakka.php?wakka=llDialog
  47. list order_buttons(list buttons)
  48. {
  49.     return llList2List(buttons, -3, -1) + llList2List(buttons, -6, -4) + llList2List(buttons, -9, -7) + llList2List(buttons, -12, -10);
  50. }
  51.  
  52.  
  53. //Function to Build the two lists we will use
  54. // Could have put it all in state_entry but may be a handy function
  55. // to use in another similar script so I put it here.
  56. BuildLists()
  57. {
  58.     integer counter=0;
  59.     integer inventory_num = llGetInventoryNumber(INVENTORY_NOTECARD);
  60.        
  61.     while(counter < inventory_num)
  62.     {
  63.         string object_name = llGetInventoryName(INVENTORY_NOTECARD, counter);
  64.        
  65.         inventory_list = (inventory_list=[]) + inventory_list + object_name;
  66.         menu_list = (menu_list=[]) + menu_list + [(string) (++counter) + ")" + object_name];   //Incrimenting the the counter in this line.  Probably bad practice
  67.                 //But it solves two problems, incrimenting the counter in the loop
  68.                 // and making a human readale list startign at "1" instead of "0"
  69.  
  70.     }
  71.      
  72.     if(counter % 9 == 0) //Multiples of 9 won't round down right.
  73.     {
  74.         --counter;
  75.     }
  76.    
  77.     last_menu = llFloor(counter / 9.0); //I say 9.0 so it treats it like a float
  78.                                         // and will round down correctly.
  79.    
  80.    
  81.    
  82. }
  83.  
  84.  
  85. //Function to Display the pages of the Menu
  86. // Instead of defining my menus ahead of time
  87. // (and in so doing putting a limit on the number of items)
  88. // I build the pages of the menu dynamicaly
  89. DisplayMenu(key id)
  90. {
  91.     //These are the buttons, they will be numbers
  92.     // Based on what page of the menu we are on.
  93.    
  94.     string b1 = (string) (menu_page *9 +1);
  95.     string b2 = (string) (menu_page *9 +2);
  96.     string b3 = (string) (menu_page *9 +3);
  97.     string b4 = (string) (menu_page *9 +4);
  98.     string b5 = (string) (menu_page *9 +5);
  99.     string b6 = (string) (menu_page *9 +6);
  100.     string b7 = (string) (menu_page *9 +7);
  101.     string b8 = (string) (menu_page *9 +8);
  102.     string b9 = (string) (menu_page *9 +9);
  103.  
  104.    
  105.        list menu = [b1, b2, b3, b4, b5, b6, b7, b8, b9, "<<PREV", "Get All", "NEXT>>"]; //will use the order_buttons function to put these in a good order for llDialog
  106.    
  107.     list menu_text = llList2List(menu_list, menu_page * 9, menu_page * 9  + 8); //This is the part of the list for menu text for this page.
  108.    
  109.     integer menu_length = llGetListLength(menu_text);
  110.    
  111.     if(menu_length < 9) //Don't Need all the buttons
  112.     {
  113.         menu = llDeleteSubList(menu, menu_length, 8); //Trim the menu buttons
  114.     }
  115.    
  116.     llDialog(id, llDumpList2String(menu_text, "\n"), order_buttons(menu), UserChan); //Display the Menu
  117.      
  118. }
  119.  
  120.  
  121.  
  122. {
  123.     state_entry()
  124.     {
  125.         menu_page = 0;
  126.        
  127.         UserChan = -((integer)llFrand(2147483646.0) + 1); //Choose a random  negative channel to use to avoid crossttalk with other books
  128.  
  129.         BuildLists();
  130.        
  131.         llSetText(float_text, <0, 1, 1>, 1.0);
  132.     }
  133.  
  134.     touch_start(integer total_number)
  135.     {if(using) //Object in use
  136.        {
  137.             if(current_user != llDetectedKey(0))
  138.             {
  139.                 //Communicate using llDialog we are in a library after all
  140.                 // and its even quieter than a whisper.
  141.                 llDialog(llDetectedKey(0), "I'm sorry another patron is using me at this time, please wait a moment and try again.", ["OK"], 1181111811);
  142.             }
  143.            
  144.             else // Our user
  145.             {
  146.                 DisplayMenu(current_user); //Give the menu again but not more time
  147.                                         // This is in case they accidently hit "ignore"
  148.             }
  149.         }
  150.        
  151.         else //Giver is available and ready for use
  152.         {
  153.             current_user = llDetectedKey(0);
  154.             using = TRUE;
  155.             handle = llListen(UserChan, "", current_user, "");
  156.             llSetTimerEvent(90); //90 Second limit to make a choice or reset if walk away
  157.             DisplayMenu(current_user);
  158.             llSetText("Currently in Use, \nplease wait a moment...", <1,0,0>, 1.0);
  159.         }
  160.        
  161.          
  162.     }
  163.    
  164.    
  165.     listen(integer channel, string name, key id, string message)
  166.     {
  167.         if(message == "Get All") //Give them all the contents
  168.         {
  169.              llGiveInventoryList(current_user, folder_name, inventory_list);  
  170.            
  171.             //We will assume they are done, as another menu would obstruct the dialog
  172.             // To accept the folder from the object.
  173.             llSetTimerEvent(0);
  174.             llListenRemove(handle);
  175.             using = FALSE;
  176.             current_user = NULL_KEY;
  177.             menu_page = 0;
  178.             llSetText(float_text, <0, 1, 1>, 1.0);
  179.            
  180.         }
  181.        
  182.         else if(message == "<<PREV")
  183.         {
  184.             menu_page--;
  185.             if(menu_page == -1)
  186.             {
  187.                 menu_page = last_menu;
  188.             }
  189.            
  190.             DisplayMenu(current_user);
  191.         }
  192.        
  193.         else if(message == "NEXT>>")
  194.         {
  195.             menu_page++;
  196.             if(menu_page > last_menu)
  197.             {
  198.                 menu_page = 0;
  199.             }
  200.            
  201.             DisplayMenu(current_user);
  202.         }
  203.        
  204.         else //Patron Chose a Number
  205.         {
  206.             llSetTimerEvent(0);
  207.             llListenRemove(handle);
  208.            
  209.             integer get_item = (integer) message;
  210.             get_item--; //Humans like to count from 1, but computers like 0 better.    
  211.            
  212.             llGiveInventory(current_user, llList2String(inventory_list, get_item));
  213.            
  214.            
  215.             using = FALSE;
  216.             current_user = NULL_KEY;
  217.             menu_page = 0;
  218.             llSetText(float_text, <0, 1, 1>, 1.0);
  219.  
  220.         }
  221.     }
  222.        
  223.    
  224.    
  225.     timer()
  226.     {
  227.         llSetTimerEvent(0);
  228.         llListenRemove(handle);
  229.         llDialog(current_user, "I'm sorry time has expired to make a menu choice." , ["OK"], 1181111811);
  230.         using= FALSE;
  231.         current_user = NULL_KEY;
  232.         menu_page = 0;
  233.         llSetText(float_text, <0, 1, 1>, 1.0);  
  234.     }
  235.    
  236.     changed(integer change)
  237.     {
  238.         if(change & CHANGED_INVENTORY)
  239.         {
  240.             llResetScript();
  241.         }  
  242.        
  243.        
  244.     }
  245.    
  246.        
  247. }
  248.  

Reply to "ZenMondo's Notecard Library"

Here you can reply to the paste above

captcha