Advertisement
salahzar

1 prim - book script - Whitestar Magic / Salahzar Stenvaag

Nov 3rd, 2013
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ----------------------------------------------------------------
  2. // Script Title:    1-Prim Book
  3. // Created by:      WhiteStar Magic
  4. // Modified by Salahzar Stenvaag November 2013 to avoid config notecard
  5. // uses all textures in inventory, first is Front Page, Last is Last page
  6. // Creation Date:   Feb.06.2012
  7. // Platforms:
  8. //    SecondLife:    Not Tested
  9. //    OpenSim:       Yes
  10. //
  11. // Revision:        V.0.3
  12. // Revision History:
  13. //
  14. // Origination:
  15. // Initially Based loosely off the Improved book script Script @ http://forums.osgrid.org/viewtopic.php?f=5&t=2400
  16. //
  17. // Revision Contributors:
  18. // WhiteStar V.0.3 March.23.2012
  19. // - small mod, adding BLANK_TEXTURE @ end of pages list IF the list is an odd number
  20. //   corrects for the last page not being shown properly if odd pages in list
  21. // WhiteStar V.0.2
  22. // - Streamlined page handling
  23. // - Divided pages up so each inside face holds a full texture
  24. // - Modified texture pre-caching to use "spine & bottom" edges to preload up coming textures
  25. // - added facility to use front & back covers
  26. // - add states for "run" and "GET_NOTECARDS"
  27. // - Installed Notecard reader facility to eliminate script from having to be edited.
  28. // -    Size=    allows use of REG, LG & XLG book sizes depending on material
  29. // -    CoverFR= for front Cover entry into NoteCard
  30. // -    CoverBK= for back Cover entry into NoteCard
  31. // -    Page=    to specify the pages. 1 per line using name(if contained in prim) or UUID, in sequential order.  Page-1, Page-2 Page-3 etc
  32. //
  33. // ================================================================
  34. // ** SCRIPT NOTES **
  35. //
  36. // drop script & notecard into a BOX prim and it will set up.
  37. // edit the Book.CFG and add the texture UUID's or Texture Names if contained in prim.
  38. // -- sit back & enjoy your new book.
  39. //================================================================
  40. // ** Licence **
  41. // !Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0)
  42. // http://creativecommons.org/licenses/by-nc-sa/3.0/
  43. //================================================================
  44. // adjust below to make book only respond to owner
  45. integer OWNER_ONLY  = FALSE;  // default FALSE allows anyone to use book
  46. //
  47. // ====================================== \\
  48. // Make changes below at your own peril ! \\
  49. // ====================================== \\
  50. //
  51. // Global Variables
  52. vector  sz_open;    // open & closed changed in notecard reader
  53. vector  sz_closed;
  54. vector  sz_reg_o    = <0.050,1.00,0.75>;    // reg sizes
  55. vector  sz_reg_c    = <0.025,0.50,0.75>;
  56. vector  sz_lg_o     = <0.050,1.50,1.00>;    // lg sizes
  57. vector  sz_lg_c     = <0.025,0.75,1.00>;
  58. vector  sz_xlg_o    = <0.050,3.00,2.00>;    // xlg sizes
  59. vector  sz_xlg_c    = <0.025,1.50,2.00>;
  60. //
  61. list    pcut_close  = [PRIM_TYPE, PRIM_TYPE_BOX, 0, <0.0,1.0,0.0>, 0.0, <0.0,0.0,0.0>, <1.0,1.0,1.0>, <0.0,0.0,0.0>];
  62. list    pcut_open   = [PRIM_TYPE, PRIM_TYPE_BOX, 0, <0.0,0.700,0.0>, 0.0, <0.0,0.0,0.0>, <1.0,1.0,1.0>, <0.0,0.0,0.0>];
  63. //      FR=Front, BK=Back covers. from notecard. UUID or TextureName if contained
  64. string  cover_FR;
  65. string  cover_BK;
  66. //
  67. string  bookstate   = "closed";
  68. string  bookconfig  = "Book.CFG";
  69. key     NChandle    = NULL_KEY;
  70. integer line        = 0;
  71. //
  72. list    Lst_pages;          // page= data from notecard (uuid or name)
  73. integer page_qty;           // # of pages in Lst_pages
  74. integer page_crnt   = 0;
  75. integer page_next   = 1;
  76. //
  77. integer tLT         = 6;    // Left page Touchface
  78. integer tRT         = 5;    // Right page Touchface
  79. float   timer_delay = 5.0;
  80. //
  81. // ==================== \\
  82. // SCRIPT STARTS HERE ! \\
  83. //======================\\
  84. set_pages() // set textures for both inner pages
  85. {
  86.     llSetText("Pag. "+(string)(page_crnt+1)+".."+(string)(page_crnt+2)+"/"+(string)(llGetInventoryNumber(INVENTORY_TEXTURE)-2),<1,1,1>,1);
  87.     key Lt_pg = (key)llList2String(Lst_pages,page_crnt);     // ODD Pages on left
  88.     key Rt_pg = (key)llList2String(Lst_pages,(page_crnt+1)); // EVEN pages on Right
  89.     llSetPrimitiveParams([PRIM_TEXTURE, 5, Rt_pg, <1.0,1.0,0.0>, <0.0,0,0>, 0.0]); // Right Face: full image
  90.     llSetPrimitiveParams([PRIM_TEXTURE, 6, Lt_pg, <1.0,1.0,0.0>, <0.0,0,0>, 0.0]); // Left Face: full image
  91. }
  92.  
  93. pre_cache()
  94. {
  95.     llSetTimerEvent(0.0);       // do this only once
  96.     if(bookstate=="closed") return;
  97.     key oddcache=llList2Key(Lst_pages,page_next+1);
  98.     key evencache=llList2Key(Lst_pages,page_next+2);
  99.     //llSetColor(<0,0,0>, 3);   // colour over left face
  100.     llSetTexture(oddcache,3);  // left face edge (spine) when open
  101.     //llSetColor(<0,0,0>, 4);   // colour over bottom face
  102.     llSetTexture(evencache,4); // bottom face edge when open
  103. }
  104.  
  105. openbook()
  106. {
  107.     bookstate="open";
  108.     llSetPrimitiveParams([PRIM_SIZE, sz_open]); // set new size
  109.     llSetPrimitiveParams(pcut_open);               // set the cut params
  110.     llSetPrimitiveParams([PRIM_TEXTURE, 2, cover_BK, <2.0,1.0,0.0>, <0.50,0,0>, 0.0]); // set back cover & scale for display on new prim form
  111.    // llSetRot(llGetRot()*llEuler2Rot(<0,0,PI>));
  112. }
  113.  
  114. closebook()
  115. {
  116.     llSetText("Clicca per sfogliare "+(string)(llGetInventoryNumber(INVENTORY_TEXTURE)-2)+" pagine",<1,1,1>,1);
  117.     bookstate="closed";
  118.     page_crnt=0;
  119.     page_next=1;
  120.     //
  121.     llSetPrimitiveParams([PRIM_SIZE, sz_closed]);
  122.     llSetPrimitiveParams(pcut_close);    
  123.     llSetPrimitiveParams([PRIM_TEXTURE, 4, cover_FR, <1.0,1.0,0.0>, <0.0,0,0>, 0.0]);  // Front Cover
  124.     llSetPrimitiveParams([PRIM_TEXTURE, 2, cover_BK, <1.0,1.0,0.0>, <0.0,0,0>, 0.0]);  // Back Cover, rescaled for prim form
  125.     //
  126.     //llSetColor(<1.0,1.0,1.0>, 4);  // re-colour cover white IF bottom face edge was blackened in pre_cache()
  127.     //
  128.     llSetTexture(TEXTURE_BLANK,0); // top face edge
  129.     llSetTexture(TEXTURE_BLANK,1); // rigt side edge
  130.     llSetTexture(TEXTURE_BLANK,3); // left side edge (spine)
  131.     llSetTexture(TEXTURE_BLANK,5); // bottom face adge
  132. }
  133.  
  134. // START //
  135. default
  136. {
  137.     state_entry()
  138.     {
  139.       //  bookconfig=llGetInventoryName(
  140.         state GET_NOTECARDS;
  141.     }
  142. }
  143. // RUNNING //
  144. state run
  145. {
  146.     state_entry()
  147.     {
  148.         closebook();
  149.         llOwnerSay("[ "+ llGetListLength(Lst_pages)+" ] Pages loaded. Ready, click on cover to read");
  150.         page_qty = llGetListLength(Lst_pages);
  151.         float d = ((float)page_qty / 2);
  152.         integer e = (page_qty / 2);
  153.         if((float)d != (float)e) {Lst_pages += [TEXTURE_BLANK]; page_qty = llGetListLength(Lst_pages);} // ODD # so add BLANK TEXTURE to make EVEN #
  154.  
  155.     }
  156.  
  157.     touch_start(integer num_times)
  158.     {
  159.         if(OWNER_ONLY && llDetectedKey(0)!=llGetOwner()) return; // only owner is set, to ignore others
  160.         //
  161.         if(bookstate=="closed")
  162.         {
  163.             openbook();
  164.             set_pages();
  165.             pre_cache();
  166.         }
  167.         else if(bookstate=="open")
  168.         {
  169.             if(llDetectedTouchFace(0) == tRT) // RTface touched
  170.             {
  171.                 page_crnt=page_crnt + 2;
  172.  
  173.                 if(page_crnt>(page_qty-2))
  174.                 {
  175.                     // llSetRot(llGetRot()*llEuler2Rot(<0,0,PI>));
  176.                     closebook();
  177.                 }
  178.                 else
  179.                 {
  180.                     set_pages();
  181.                     page_next = page_crnt+1;
  182.                 }
  183.  
  184.                 if ( page_next < llGetListLength(Lst_pages) )
  185.                 {
  186.                     llSetTimerEvent(timer_delay);
  187.                 }
  188.                 else llSetTimerEvent(0.0);
  189.             }
  190.             else if(llDetectedTouchFace(0) == tLT) // LTface touched
  191.             {
  192.                 page_crnt=page_crnt - 2;
  193.                 if(page_crnt< 0)
  194.                 {
  195.                    //  llSetRot(llGetRot()*llEuler2Rot(<0,0,PI>));
  196.                     closebook();
  197.                 }
  198.                 else
  199.                 {
  200.                     set_pages();
  201.                     page_next = page_crnt-1;
  202.                 }
  203.                 if ( page_next < llGetListLength(Lst_pages) )
  204.                 {
  205.                     llSetTimerEvent(timer_delay);
  206.                 }
  207.                 else llSetTimerEvent(0.0);
  208.             }
  209.         }
  210.     }
  211.  
  212.     timer()
  213.     {
  214.         pre_cache();            // preload next page after a delay
  215.     }
  216.  
  217.     changed(integer change)
  218.     {
  219.         if (change & CHANGED_INVENTORY)
  220.         {
  221.             llOwnerSay("The inventory changed. Restarting book");
  222.             llResetScript();
  223.         }
  224.         if (change & 1024) llResetScript();
  225.     }
  226. }
  227. //-------------------\\
  228. // Get Notecard Data \\
  229. //-------------------\\
  230. state GET_NOTECARDS
  231. {
  232.     state_entry()
  233.     {
  234.        
  235.         integer i; for(i=1;i<llGetInventoryNumber(INVENTORY_TEXTURE)-1;i++)
  236.         {
  237.             Lst_pages += [ llGetInventoryName(INVENTORY_TEXTURE,i) ];
  238.         }
  239.         string data="xlg";
  240.         if(llToLower(data)=="reg")
  241.         {
  242.             sz_closed  = sz_reg_c;
  243.             sz_open    = sz_reg_o;
  244.         }
  245.         else if(llToLower(data)=="lg")
  246.         {
  247.             sz_closed  = sz_lg_c;
  248.             sz_open    = sz_lg_o;
  249.         }
  250.         else if(llToLower(data)=="xlg")
  251.         {
  252.             sz_closed  = sz_xlg_c;
  253.             sz_open    = sz_xlg_o;
  254.         }
  255.         cover_FR=llGetInventoryName(INVENTORY_TEXTURE,0);
  256.         cover_BK=llGetInventoryName(INVENTORY_TEXTURE,llGetInventoryNumber(INVENTORY_TEXTURE)-1);
  257.         state run;
  258.     }
  259. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement