Caledon Library Book Server 2.61

From ZenMondo Wormser, 1 Year ago, written in Linden Scripting, viewed 342 times.
URL http://flynnos.org/flynnbin/view/c0a73f7d Embed
Download Paste or View Raw
  1. ///////////////////////////
  2. // Caledon Library Book Server 2.61 by ZenMondo Wormser
  3. // Developed for Caledon Library System
  4. //
  5. //  Takes a patron to an aetheric address to read
  6. //  a book or chapter of a book.
  7. //
  8. //  The Titles and URLs are stored on a configuration notecard.
  9. //
  10. // The Format of the notecard is as follows
  11. //  A Line with the Title of the book or chapter,
  12. //  followed by a line with the URL of the book or chapter.
  13. //
  14. //  The notecard can be named anything, I suggesst descriptive names such as
  15. //  "The Book of Houshold Management by Mrs. Isabella Beeton"  and not something
  16. //  vaugue such as "urls".
  17. //
  18. //
  19. //  A book or object containing this script is limited to one reader at a time.
  20. //////////////////////
  21.  
  22.  
  23. ///////////////////////////
  24. // This work is licensed under the Creative Commons Attribution-Noncommercial-Share
  25. // Alike 3.0 License. To view a copy of this license, visit
  26. // http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative
  27. // Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
  28. //
  29. // Attribution:
  30. //  If unmodified you must keep the filename intact
  31. //  If a derivative work you must say "Based on the CodePoetry of ZenMondo Wormser"
  32. //////////////////////////
  33.  
  34. //Global Variables
  35. integer position = 0;
  36. string notecard;
  37. key query;
  38.  
  39. integer handle;
  40. integer UserChan = 11811;
  41.  
  42. integer titleCounter = 0;
  43. list titleData = [];
  44. list urlData = [];
  45.  
  46.  
  47. integer menuPage;
  48. integer lastMenu;
  49.  
  50. key currentPatron = NULL_KEY;
  51. integer reading = FALSE;
  52.  
  53. //Functions
  54.  
  55. //Compact function to put buttons in "correct" human-readable order ~ Redux
  56. //Taken from http://lslwiki.net/lslwiki/wakka.php?wakka=llDialog
  57. list order_buttons(list buttons)
  58. {
  59.     return llList2List(buttons, -3, -1) + llList2List(buttons, -6, -4) + llList2List(buttons, -9, -7) + llList2List(buttons, -12, -10);
  60. }
  61.  
  62. //Function to Display the pages of the Menu
  63. // Instead of defining my menus ahead of time
  64. // (and in so doing putting a limit on the number of items)
  65. // I build the pages of the menu dynamicaly
  66. DisplayMenuPage(key id)
  67. {
  68.    
  69.  
  70.     //These are the buttons, they will be numbers
  71.     // Based on what page of the menu we are on.
  72.    
  73.     string b1 = (string) (menuPage *9 +1);
  74.     string b2 = (string) (menuPage *9 +2);
  75.     string b3 = (string) (menuPage *9 +3);
  76.     string b4 = (string) (menuPage *9 +4);
  77.     string b5 = (string) (menuPage *9 +5);
  78.     string b6 = (string) (menuPage *9 +6);
  79.     string b7 = (string) (menuPage *9 +7);
  80.     string b8 = (string) (menuPage *9 +8);
  81.     string b9 = (string) (menuPage *9 +9);
  82.  
  83.    
  84.     list menu = [b1, b2, b3, b4, b5, b6, b7, b8, b9, "<<PREV", "Bibl.", "NEXT>>"]; //will use the order_buttons function to put these in a good order for llDialog
  85.    
  86.     list menu_text = llList2List(titleData, menuPage * 9, menuPage * 9  + 8); //This is the part of the list for menu text for this page.
  87.    
  88.     integer menu_length = llGetListLength(menu_text);
  89.    
  90.     if(menu_length < 9) //Don't Need all the buttons
  91.     {
  92.         menu = llDeleteSubList(menu, menu_length, 8); //Trim the menu buttons
  93.     }
  94.    
  95.     llDialog(id, llDumpList2String(menu_text, "\n"), order_buttons(menu), UserChan); //Display the Menu
  96. }
  97.  
  98. {
  99.     state_entry()
  100.     {  
  101.         menuPage = 0;
  102.        
  103.         UserChan = -((integer)llFrand(2147483646.0) + 1); //Choose a random  negative channel to use to aoid crossttalk with other books
  104.        
  105.        notecard = llGetInventoryName(INVENTORY_NOTECARD, 0);
  106.                      
  107.        if(llGetInventoryType(notecard) == INVENTORY_NOTECARD)
  108.         {
  109.             llWhisper(0, "Reading Configuration Notecard.");
  110.             query = llGetNotecardLine(notecard, position);
  111.         }
  112.        
  113.         else
  114.         {
  115.             llWhisper(0, "Configuration notecard is not present in the object's inventory.");
  116.         }
  117.        
  118.        
  119.     }
  120.  
  121.     touch_start(integer total_number)
  122.     {
  123.        if(reading) //Book in use
  124.        {
  125.             if(currentPatron != llDetectedKey(0))
  126.             {
  127.                 //Communicate using llDialog we are in a library after all
  128.                 // and its even quieter than a whisper.
  129.                 llDialog(llDetectedKey(0), "I'm sorry another patron is reading me at this time, please wait a moment and try again.", ["OK"], 1181111811);
  130.             }
  131.            
  132.             else // Our reader
  133.             {
  134.                 DisplayMenuPage(currentPatron); //Give the menu again but not more time
  135.                                                 // This is in case they accidently hit "ignore"
  136.             }
  137.         }
  138.        
  139.         else //Book is available and ready for use
  140.         {
  141.             currentPatron = llDetectedKey(0);
  142.             reading = TRUE;
  143.             handle = llListen(UserChan, "", currentPatron, "");
  144.             llSetTimerEvent(90); //90 Second limit to make a choice or reset if walk away
  145.             DisplayMenuPage(currentPatron);
  146.         }
  147.        
  148.        
  149.     }
  150.    
  151.     listen(integer channel, string name, key id, string message)
  152.     {
  153.         if(message == "Bibl.") //Give them the notecard and they can look up the URLS on thier own
  154.         {
  155.             llGiveInventory(id, notecard);
  156.            
  157.             //We will assume they are done, as another menu would obstruct the dialog
  158.             // To accept the notecard from the book.
  159.             llSetTimerEvent(0);
  160.             llListenRemove(handle);
  161.             reading = FALSE;
  162.             currentPatron = NULL_KEY;
  163.             menuPage = 0;
  164.            
  165.         }
  166.        
  167.         else if(message == "<<PREV")
  168.         {
  169.             menuPage--;
  170.             if(menuPage == -1)
  171.             {
  172.                 menuPage = lastMenu;
  173.             }
  174.            
  175.             DisplayMenuPage(currentPatron);
  176.         }
  177.        
  178.         else if(message == "NEXT>>")
  179.         {
  180.             menuPage++;
  181.             if(menuPage > lastMenu)
  182.             {
  183.                 menuPage = 0;
  184.             }
  185.            
  186.             DisplayMenuPage(currentPatron);
  187.         }
  188.        
  189.         else //Patron Chose a Number
  190.         {
  191.             llSetTimerEvent(0);
  192.             llListenRemove(handle);
  193.            
  194.             integer GoUrl = (integer) message;
  195.             GoUrl--; //Humans like to count from 1, but computers like 0 better.    
  196.            
  197.             llLoadURL(currentPatron, "Would you like to visit the aetheric version of " + llList2String(titleData, GoUrl) + "?", llList2String(urlData, GoUrl));
  198.            
  199.             reading = FALSE;
  200.             currentPatron = NULL_KEY;
  201.             menuPage = 0;
  202.            
  203.  
  204.         }
  205.     }
  206.    
  207.     timer()
  208.     {
  209.         llSetTimerEvent(0);
  210.         llListenRemove(handle);
  211.         llDialog(currentPatron, "I'm sorry time has expired to make a menu choice." , ["OK"], 1181111811);
  212.         reading = FALSE;
  213.         currentPatron = NULL_KEY;
  214.         menuPage = 0;  
  215.     }
  216.    
  217.     changed(integer change)
  218.     {
  219.         if(change & CHANGED_INVENTORY)
  220.         {
  221.             //asuming the notecard has been edited or swapped out. If it wasn't that,
  222.             // WHAT ELSE ARE YOU PUTTING IN? DON'T DO THAT! ONLY THE SCRIPT AND NOTECARD!
  223.             llResetScript();
  224.         }  
  225.        
  226.        
  227.     }
  228.    
  229.    
  230.  
  231.  
  232.     dataserver(key request, string data)
  233.     {
  234.         if(query == request)
  235.         {
  236.             if(data == EOF) //Then end of the notecard
  237.             {
  238.                 if(titleCounter % 9 == 0) //Multiples of 9 won't round down right.
  239.                 {
  240.                     --titleCounter;
  241.                 }
  242.                
  243.                 lastMenu = llFloor(titleCounter / 9.0);  //How Many Pages of Menus we will use
  244.                 llWhisper(0, "Ready");
  245.                 //End of notecard!
  246.             }
  247.             else
  248.             {
  249.                 //Do something with the data
  250.                
  251.                 if (position % 2) // These lines 1,3,5,7... and so on will be URLs
  252.                 {
  253.                     urlData += (list)(data);
  254.                 }
  255.                 else
  256.                 {
  257.                     titleData += (list)((string)(++titleCounter) + ") " + data);
  258.                
  259.                 }
  260.                
  261.                 //llSay(0, "Added " + data +" to access list.");
  262.                
  263.                 //Increase the position variable and
  264.                 ++position;
  265.                 //Continue reading the next lines.
  266.                 query = llGetNotecardLine(notecard, position);
  267.             }
  268.         }
  269.     }
  270.    
  271.     on_rez(integer start_param)
  272.     {
  273.         llResetScript();
  274.     }
  275. }

Reply to "Caledon Library Book Server 2.61"

Here you can reply to the paste above

captcha