Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ----------------------------------------------------------------
- // Script Title: 1-Prim Book
- // Created by: WhiteStar Magic
- // Modified by Salahzar Stenvaag November 2013 to avoid config notecard
- // uses all textures in inventory, first is Front Page, Last is Last page
- // Creation Date: Feb.06.2012
- // Platforms:
- // SecondLife: Not Tested
- // OpenSim: Yes
- //
- // Revision: V.0.3
- // Revision History:
- //
- // Origination:
- // Initially Based loosely off the Improved book script Script @ http://forums.osgrid.org/viewtopic.php?f=5&t=2400
- //
- // Revision Contributors:
- // WhiteStar V.0.3 March.23.2012
- // - small mod, adding BLANK_TEXTURE @ end of pages list IF the list is an odd number
- // corrects for the last page not being shown properly if odd pages in list
- // WhiteStar V.0.2
- // - Streamlined page handling
- // - Divided pages up so each inside face holds a full texture
- // - Modified texture pre-caching to use "spine & bottom" edges to preload up coming textures
- // - added facility to use front & back covers
- // - add states for "run" and "GET_NOTECARDS"
- // - Installed Notecard reader facility to eliminate script from having to be edited.
- // - Size= allows use of REG, LG & XLG book sizes depending on material
- // - CoverFR= for front Cover entry into NoteCard
- // - CoverBK= for back Cover entry into NoteCard
- // - 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
- //
- // ================================================================
- // ** SCRIPT NOTES **
- //
- // drop script & notecard into a BOX prim and it will set up.
- // edit the Book.CFG and add the texture UUID's or Texture Names if contained in prim.
- // -- sit back & enjoy your new book.
- //================================================================
- // ** Licence **
- // !Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0)
- // http://creativecommons.org/licenses/by-nc-sa/3.0/
- //================================================================
- // adjust below to make book only respond to owner
- integer OWNER_ONLY = FALSE; // default FALSE allows anyone to use book
- //
- // ====================================== \\
- // Make changes below at your own peril ! \\
- // ====================================== \\
- //
- // Global Variables
- vector sz_open; // open & closed changed in notecard reader
- vector sz_closed;
- vector sz_reg_o = <0.050,1.00,0.75>; // reg sizes
- vector sz_reg_c = <0.025,0.50,0.75>;
- vector sz_lg_o = <0.050,1.50,1.00>; // lg sizes
- vector sz_lg_c = <0.025,0.75,1.00>;
- vector sz_xlg_o = <0.050,3.00,2.00>; // xlg sizes
- vector sz_xlg_c = <0.025,1.50,2.00>;
- //
- 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>];
- 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>];
- // FR=Front, BK=Back covers. from notecard. UUID or TextureName if contained
- string cover_FR;
- string cover_BK;
- //
- string bookstate = "closed";
- string bookconfig = "Book.CFG";
- key NChandle = NULL_KEY;
- integer line = 0;
- //
- list Lst_pages; // page= data from notecard (uuid or name)
- integer page_qty; // # of pages in Lst_pages
- integer page_crnt = 0;
- integer page_next = 1;
- //
- integer tLT = 6; // Left page Touchface
- integer tRT = 5; // Right page Touchface
- float timer_delay = 5.0;
- //
- // ==================== \\
- // SCRIPT STARTS HERE ! \\
- //======================\\
- set_pages() // set textures for both inner pages
- {
- llSetText("Pag. "+(string)(page_crnt+1)+".."+(string)(page_crnt+2)+"/"+(string)(llGetInventoryNumber(INVENTORY_TEXTURE)-2),<1,1,1>,1);
- key Lt_pg = (key)llList2String(Lst_pages,page_crnt); // ODD Pages on left
- key Rt_pg = (key)llList2String(Lst_pages,(page_crnt+1)); // EVEN pages on Right
- llSetPrimitiveParams([PRIM_TEXTURE, 5, Rt_pg, <1.0,1.0,0.0>, <0.0,0,0>, 0.0]); // Right Face: full image
- llSetPrimitiveParams([PRIM_TEXTURE, 6, Lt_pg, <1.0,1.0,0.0>, <0.0,0,0>, 0.0]); // Left Face: full image
- }
- pre_cache()
- {
- llSetTimerEvent(0.0); // do this only once
- if(bookstate=="closed") return;
- key oddcache=llList2Key(Lst_pages,page_next+1);
- key evencache=llList2Key(Lst_pages,page_next+2);
- //llSetColor(<0,0,0>, 3); // colour over left face
- llSetTexture(oddcache,3); // left face edge (spine) when open
- //llSetColor(<0,0,0>, 4); // colour over bottom face
- llSetTexture(evencache,4); // bottom face edge when open
- }
- openbook()
- {
- bookstate="open";
- llSetPrimitiveParams([PRIM_SIZE, sz_open]); // set new size
- llSetPrimitiveParams(pcut_open); // set the cut params
- 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
- // llSetRot(llGetRot()*llEuler2Rot(<0,0,PI>));
- }
- closebook()
- {
- llSetText("Clicca per sfogliare "+(string)(llGetInventoryNumber(INVENTORY_TEXTURE)-2)+" pagine",<1,1,1>,1);
- bookstate="closed";
- page_crnt=0;
- page_next=1;
- //
- llSetPrimitiveParams([PRIM_SIZE, sz_closed]);
- llSetPrimitiveParams(pcut_close);
- llSetPrimitiveParams([PRIM_TEXTURE, 4, cover_FR, <1.0,1.0,0.0>, <0.0,0,0>, 0.0]); // Front Cover
- llSetPrimitiveParams([PRIM_TEXTURE, 2, cover_BK, <1.0,1.0,0.0>, <0.0,0,0>, 0.0]); // Back Cover, rescaled for prim form
- //
- //llSetColor(<1.0,1.0,1.0>, 4); // re-colour cover white IF bottom face edge was blackened in pre_cache()
- //
- llSetTexture(TEXTURE_BLANK,0); // top face edge
- llSetTexture(TEXTURE_BLANK,1); // rigt side edge
- llSetTexture(TEXTURE_BLANK,3); // left side edge (spine)
- llSetTexture(TEXTURE_BLANK,5); // bottom face adge
- }
- // START //
- default
- {
- state_entry()
- {
- // bookconfig=llGetInventoryName(
- state GET_NOTECARDS;
- }
- }
- // RUNNING //
- state run
- {
- state_entry()
- {
- closebook();
- llOwnerSay("[ "+ llGetListLength(Lst_pages)+" ] Pages loaded. Ready, click on cover to read");
- page_qty = llGetListLength(Lst_pages);
- float d = ((float)page_qty / 2);
- integer e = (page_qty / 2);
- if((float)d != (float)e) {Lst_pages += [TEXTURE_BLANK]; page_qty = llGetListLength(Lst_pages);} // ODD # so add BLANK TEXTURE to make EVEN #
- }
- touch_start(integer num_times)
- {
- if(OWNER_ONLY && llDetectedKey(0)!=llGetOwner()) return; // only owner is set, to ignore others
- //
- if(bookstate=="closed")
- {
- openbook();
- set_pages();
- pre_cache();
- }
- else if(bookstate=="open")
- {
- if(llDetectedTouchFace(0) == tRT) // RTface touched
- {
- page_crnt=page_crnt + 2;
- if(page_crnt>(page_qty-2))
- {
- // llSetRot(llGetRot()*llEuler2Rot(<0,0,PI>));
- closebook();
- }
- else
- {
- set_pages();
- page_next = page_crnt+1;
- }
- if ( page_next < llGetListLength(Lst_pages) )
- {
- llSetTimerEvent(timer_delay);
- }
- else llSetTimerEvent(0.0);
- }
- else if(llDetectedTouchFace(0) == tLT) // LTface touched
- {
- page_crnt=page_crnt - 2;
- if(page_crnt< 0)
- {
- // llSetRot(llGetRot()*llEuler2Rot(<0,0,PI>));
- closebook();
- }
- else
- {
- set_pages();
- page_next = page_crnt-1;
- }
- if ( page_next < llGetListLength(Lst_pages) )
- {
- llSetTimerEvent(timer_delay);
- }
- else llSetTimerEvent(0.0);
- }
- }
- }
- timer()
- {
- pre_cache(); // preload next page after a delay
- }
- changed(integer change)
- {
- if (change & CHANGED_INVENTORY)
- {
- llOwnerSay("The inventory changed. Restarting book");
- llResetScript();
- }
- if (change & 1024) llResetScript();
- }
- }
- //-------------------\\
- // Get Notecard Data \\
- //-------------------\\
- state GET_NOTECARDS
- {
- state_entry()
- {
- integer i; for(i=1;i<llGetInventoryNumber(INVENTORY_TEXTURE)-1;i++)
- {
- Lst_pages += [ llGetInventoryName(INVENTORY_TEXTURE,i) ];
- }
- string data="xlg";
- if(llToLower(data)=="reg")
- {
- sz_closed = sz_reg_c;
- sz_open = sz_reg_o;
- }
- else if(llToLower(data)=="lg")
- {
- sz_closed = sz_lg_c;
- sz_open = sz_lg_o;
- }
- else if(llToLower(data)=="xlg")
- {
- sz_closed = sz_xlg_c;
- sz_open = sz_xlg_o;
- }
- cover_FR=llGetInventoryName(INVENTORY_TEXTURE,0);
- cover_BK=llGetInventoryName(INVENTORY_TEXTURE,llGetInventoryNumber(INVENTORY_TEXTURE)-1);
- state run;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement