ZenMondo's Radio Script 1.0

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

Reply to "ZenMondo's Radio Script 1.0"

Here you can reply to the paste above

captcha