Advertisement
RiverFromSL

Random Saying on Touch (from Notecard)

Jul 2nd, 2018 (edited)
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //  Constants
  2. string  SAYINGS_NC = "Sayings";
  3.  
  4. // Globals used when reading the notecard
  5. integer  ncLine;
  6. key      ncKey;
  7. integer  ncOK;
  8.  
  9. // Storing the list
  10. list Sayings;
  11. integer item;
  12. integer maxitems;
  13.    
  14. default
  15. {
  16.     // When the script starts...
  17.     state_entry()
  18.     {
  19.         Sayings = [];
  20.        
  21.         // Check the notecard is there...
  22.         if (llGetInventoryType(SAYINGS_NC) == INVENTORY_NONE)
  23.         {
  24.             llOwnerSay("Can't find " + SAYINGS_NC + " notecard!");
  25.             return;
  26.         }
  27.  
  28.         // Start reading it...
  29.         ncOK = FALSE;
  30.         ncLine = 0;
  31.         ncKey = llGetNotecardLine(SAYINGS_NC, ncLine);
  32.     }
  33.  
  34.     // When a new line of data has been read from the notecard...
  35.     dataserver(key qid, string data)
  36.     {
  37.         if (qid == ncKey) {
  38.  
  39.             if (data == EOF) {
  40.                 // Notecard finished!
  41.                 if (llGetListLength(Sayings) == 0) {
  42.                     llOwnerSay("No data in notecard!");
  43.                     return;
  44.                     }
  45.                 else {
  46.                     ncOK = TRUE;
  47.                     item = 0;
  48.                     maxitems = llGetListLength(Sayings);
  49.                     Sayings = llListRandomize(Sayings, 1);
  50.                     }
  51.                 }
  52.  
  53.             else {
  54.                 // We have new data - add the lines to the Sayings list
  55.                 // (if it's not a blank line)
  56.                 if (llStringTrim(data, STRING_TRIM) != "") Sayings += [data];
  57.                 // Request next line
  58.                 ncKey = llGetNotecardLine(SAYINGS_NC, ++ncLine);
  59.                 }
  60.  
  61.             }
  62.     }
  63.  
  64.    
  65.     touch_start(integer total_number)
  66.     {
  67.         if(ncOK) {
  68.             key avi = llDetectedKey(0);
  69.             llRegionSayTo(avi, 0, llList2String(Sayings, item++));
  70.             if (item >= maxitems) {
  71.                 Sayings = llListRandomize(Sayings, 1);
  72.                 item = 0;
  73.                 }
  74.             }  
  75.     }
  76.  
  77.    
  78.     changed(integer c)
  79.     {
  80.         if (c & CHANGED_INVENTORY) llResetScript();
  81.     }
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement