ZenMondo's Object Giver 2.21

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

Reply to "ZenMondo's Object Giver 2.21"

Here you can reply to the paste above

captcha