User:Void Singer/v7-D Zen Resizer

From Second Life Wiki
< User:Void Singer
Revision as of 21:02, 11 May 2012 by Void Singer (talk | contribs) (~fixing a bit of wiki-stupid)
Jump to navigation Jump to search

v7-D Zen Resizer

Builder Features:

  • Drag and Drop Design (minimal to no editing at all)
  • Clear Simple Instructions
  • Multiple configurations possible
  • Open source scripts let you modify directly in the script if desired
  • Multi Language Support
  • Allows end users to set and restore their own default (in the range you allow)
  • Allows end user to remove the resize script
  • Allows you to disable the the above user functions

Warning: Not fully compatible with other scripts that change the position/size of the links.

User Features:

  • Single LSO script, triggers after a two second touch/hold to avoid triggering when other touch scripts are present (and to override v2x dialogs)
  • Auto-language detection on ownership change (where reported, creator configurable to include any language code, default language set by creator)
  • Equivalent size adjustments (+10% then -10% results in the same starting size)
  • Size percentage reported on dialog in easy to understand 0.00 to 100.00 percentage format (representing size limits)
  • Preset Limits avoid broken objects (even on max resize). no guessing if a change will exceed min size or max link distance, because it won't.
  • Removable from no mod objects
  • User Settable Save and Restore
  • Auto-remenu (saves time editing) with "Done" cancel button.
  • Owner feedback on dialog commands provided.

Quickstart Instructions:

  1. Make a copy of your object for safety.
  2. Drop the v7-D Zen Resizer Prep script into your object, click it and follow the dialog instructions.
  3. Remove the previous script and drop the v7-D Zen Resizer (lite) script and v7-D Zen Resizer (lite): User Manual into your object.

Done!

Return to top

Detailed Instructions

Step 1

REQUIRED: Make a Copy of your object before Starting for safety!

Step 2

OPTIONAL: Drop a translated v7-D Zen Resizer Prep.cfg notecard into the root prim of your object Drop the v7-D Zen Resizer Prep script into the root prim of your object

Step 3

Click your object, and follow the instructions in the dialogs

NOTE: This step changes the size of your object; It will be reset to it's default size at the end of this step
NOTE: This step automatically sets the object description to set=< rotation > (it will also be printed to your chat history). You can add other information to the description without interfering with it, or if you prefer, you can remove it and add it to the notecard in [Step 5].

Step 4

Remove the v7-D Zen Resizer Prep script from your object (and any v7-D Zen Resizer Prep.cfg notecard)

Step 5

  • (5a) Edit the v7-D Zen Resizer (lite).cfg notecard for any custom changes
  • (5b) Drop the v7-D Zen Resizer (lite).cfg notecard into the root prim of your object
    • NOTE: Steps (5b) is REQUIRED if you removed the object description text above (and did not directly edit it into the script); otherwise it is OPTIONAL.
  • (5c) OPTIONAL: Translate the v7-D Zen Resizer (lite).cfg notecard into another language, and save as a new notecard, adding ".xx" (no quotes) to the end of its name (where "xx" is the language code, see the default v7-D Zen Resizer (lite).cfg notecard for details)

Step 6

Drop the v7-D Zen Resizer (lite) script into the root prim of your object

Step 7

OPTIONAL (but strongly suggested): Perform the following tests to confirm that Zen Resizer has been installed correctly:

  • (7a) make a copy of your current object (to avoid having to reset it)
  • (7b) Click on the Object, holding the mouse button down for two seconds to activate the menu
  • (7c) (via the dialog) Increase the objects size to 100.00%
  • (7d) (via the dialog) Save the current size
  • (7e) (via the dialog) Decrease the objects size to 0.00%
  • (7f) (via the dialog) Restore the saved size
  • (7g) if any test fails (and it shouldn't) go back to [Step 1] and use a smaller maximum size.

Step 8

OPTIONAL: Drop the v7-D Zen Resizer (lite): User Manual notecard into the root prim of your object

NOTE: If you made changes to the v7-D Zen Resizer (lite).cfg notecard, you will want to edit this notecard to reflect any command changes as well
NOTE: If you included translations for the menus, you may want to include translations of this notecard as well
NOTE: Optionally, You may, instead, copy the instructions to your own notecard included with the object.

Step 9

REQUIRED: Include a Plain Text (readable by the User) copy of the following three lines somewhere in or with your object

v7-D Zen Resizer
(C) 2010 (CC-BY) [ http://creativecommons.org/licenses/by/3.0 ]
Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ]
Return to top

Advanced Tips

  • Any Changes made in the default notecard can be directly edited into the script instead (all necessary variables are at the top)
  • Dialog can be triggered via link message so that you can tie the dialog into your own script with the following

<lsl>llMessageLinked( LINK_ROOT, 0, "v7-D Zen Resizer (lite)", llGetOwner() );</lsl>

You can replace llGetOwner() with the key of any avatar you want to receive the dialog
  • You can directly access the resize function via Link message from your own script with the following commands

<lsl>llMessageLinked( LINK_ROOT, llRound( percentage * 10000 ), "v7-D Zen Resizer (lite)", "" ); //-- change object size</lsl>

Replace percentage with a float in the range of 0.0 to 1.0

<lsl>llMessageLinked( LINK_ROOT, -1, "v7-D Zen Resizer (lite)", "" ); //-- Reset the object to the last saved size llMessageLinked( LINK_ROOT, -2, "v7-D Zen Resizer (lite)", "" ); //-- Saves the current Size llMessageLinked( LINK_ROOT, -3, "v7-D Zen Resizer (lite)", "" ); //-- Removes the resize script</lsl>

  • All direct access commands will report back with:

<lsl>llMessageLinked( source_link_number, 1, "v7-D ZenResizer (lite)_", "" ); //-- Command Succeeded llMessageLinked( source_link_number, 0, "v7-D ZenResizer (lite)_", "" ); //-- Command Failed</lsl>

source_link_number = the link number of the script that sent the original command
  • The script name can be changed, notecards and link commands MUST be changed to match
  • This package is free; If you paid for it, you got screwed, probably by a copyright violator.
  • "set = " is set by notecard if present, by script if not, and by description field only if the other two are not present.
Return to top

Notecards and Scripts

v7-D Zen Resizer Prep.cfg

  1. Create a notecard and name it v7-D Zen Resizer Prep.cfg
  2. Copy and paste the contents of the box below into it and save
:: This is a comment, comments are good. anything starting with "::" and after is a comment
:: this notecard must be named the same as the script with ".cfg" (no quotes) added to the end
:: values may be translated, please include the "//" in txt0 for safety, line breaks wil be inserted for every instance of "\n" (no quotes)
txt0 = // You may paste the following line into your notecard:
txt1 = Resize the object (in edit, via a corner grab) to the DEFAULT size you want, then press "OK"\n\n(This size will automatically be restored when done)
txt2 = Resize the object (in edit, via a corner grab) to the SMALLEST size you want available, then press "OK"\n\n(This size must be SMALLER than the DEFAULT)
txt3 = Resize the object (in edit, via a corner grab) to the LARGEST size you want available, then press "OK"\n\n(this size must be LARGER than the DEFAULT)
txt4 = Done!\n\nThe set variable is saved to the object's description field, and has been sent to your chat history window. You may remove this script now.
Return to top

v7-D Zen Resizer Prep

  1. Create a script and name it v7-D Zen Resizer Prep
  2. Copy and paste the contents of the box below into it and save

<lsl>/*//( v7-D Zen Resizer (lite) Prep v1.4 )//*/

//-- these variable may be translated here or in an optional notecard list gLstTxt = ["// You may paste the following line into your notecard:",

                   "Resize the object (in edit, via a corner grab) to the DEFAULT size you want, then press \"OK\"\n\n(This size will automatically be restored when done)",
                   "Resize the object (in edit, via a corner grab) to the SMALLEST size you want available, then press \"OK\"\n\n(This size must be SMALLER than the DEFAULT)",
                   "Resize the object (in edit, via a corner grab) to the LARGEST size you want available, then press \"OK\"\n\n(this size must be LARGER than the DEFAULT)",
                   "Done!\n\nThe Object Stats are saved to the objects description field, and have been sent to your chat window (you may include it in your notecard)"];

list gLstVal; integer gIntCnt; rotation gNfoSet = <0.0, 0.0, 0.0, 0.0>;

key gKeyChk; string gStrNCL;

//-- Adjust Set Size

uAdjSiz( float vFltNew ){

    //-- clamp vFltNew to valid percentage [0.0, 1.0]
   vFltNew = (vFltNew * (vFltNew > 0.0) - 1.0) * (vFltNew < 1.0) + 1.0;
    //-- only run if previous percent greater or less than next percentage? (0 means the same)
   if ((vFltNew < gNfoSet.z) - (vFltNew > gNfoSet.z)){
        //-- get the current root size for comparison
       vector vSizOld = llGetScale();
        //-- save the new percentage to gNfoSet, and reuse gFltNew to save the relative change percentage
       vFltNew = (gNfoSet.x + gNfoSet.y * (gNfoSet.z = vFltNew)) / vSizOld.x;
       
        //-- intialize a temp list for holding child prims size/offset
       list vLstTmp;
        //-- get the number of prims for our loop + 1 (make loops cleaner later)
        //-- llGetObjectPrimCount doesn't count seated avs, but returns 0 for attachments
        //-- llGetNumberOfPrims works on attachments, but counts seated avs when detached
        //-- !!llGetAttached returns TRUE(1) if attached, or FALSE(0) if not, to cancel #ofPrims if unattached.
       integer  vIntCnt = ~-(llGetObjectPrimCount( llGetKey() ) +  llGetNumberOfPrims() * !!llGetAttached());
           //-- set the root prim separately since it's position will not change
       llSetLinkPrimitiveParamsFast( LINK_THIS, [PRIM_SIZE, vSizOld * vFltNew] );
       while (~-(--vIntCnt)){
           vLstTmp = llGetLinkPrimitiveParams( vIntCnt, [PRIM_SIZE, PRIM_POSITION] );
           llSetLinkPrimitiveParamsFast( vIntCnt,
                                         [PRIM_SIZE, llList2Vector( vLstTmp, 0 ) * vFltNew,
                                          PRIM_POS_LOCAL, llList2Vector( vLstTmp, 1 ) * vFltNew] );
       }
   }

}

default{

   state_entry(){
       gStrNCL = llGetScriptName() + ".cfg";
       if (~llGetInventoryType( gStrNCL )){
           gKeyChk = llGetNotecardLine( gStrNCL, gIntCnt );
       }else{
           state sRdy;
       }
   }
   
   dataserver( key vKeyQry, string vStrDta ){
       if (gKeyChk == vKeyQry){
           if (EOF == vStrDta){
               state sRdy;
           }else{
               if (vStrDta = llStringTrim( llList2String( llParseString2List( vStrDta, ["::"], [] ), 0 ), STRING_TRIM )){
                   if (!llSubStringIndex( llToLower( vStrDta ), "txt" )){
                       integer vIdxTxt = (integer)llGetSubString( vStrDta, 3, 0xFFFFFFFF );
                       vStrDta = (string)llList2List( llParseStringKeepNulls( vStrDta, ["="], [] ), 1, 0xFFFFFFFF );
                       gLstTxt = llListReplaceList( gLstTxt, (list)llDumpList2String( llParseStringKeepNulls( vStrDta, ["\\n"], [] ), "\n" ), vIdxTxt, vIdxTxt );
                   }
               }
               gKeyChk = llGetNotecardLine( gStrNCL, ++gIntCnt );
           }
       }
   }

}

state sRdy{

   state_entry(){
       gIntCnt = -4;
   }
   touch_end( integer vIntNul ){
       if (llGetOwner() == llDetectedKey( 0 )){
           state sRun;
       }
   }
   
   changed( integer vBitChg ){
       if (CHANGED_INVENTORY & vBitChg){
           if (~llGetInventoryType( gStrNCL )){
               llResetScript();
           }
       }
   }

}

state sRun{

   state_entry(){
       integer vIntChn = (integer)("0xF" + llGetSubString( llGetOwner(), 0, 6 ));
       llListen( vIntChn, "", llGetOwner(), "OK");
       llDialog( llGetOwner(), llList2String( gLstTxt, gIntCnt ), [], vIntChn );
   }
   
   listen( integer vIntChn, string vStrNul, key vKeyOwn, string vStrNull ){
       vector vSizTst = llGetScale();
       gLstVal += (list)vSizTst.x;
       if (~(++gIntCnt)){
           llDialog( vKeyOwn, llList2String( gLstTxt, gIntCnt ), [], vIntChn );
       }else{
            //-- calculate the info needed for the set.
           gNfoSet.x = llList2Float( gLstVal, 1 );
           gNfoSet.y = llList2Float( gLstVal, 2 ) - gNfoSet.x;
           gNfoSet.z = 1.0;
           gNfoSet.s = (llList2Float( gLstVal, 0 ) - gNfoSet.x) / gNfoSet.y;
           gLstVal = []; //-- clear the values list in case the user wants to do this again.
            //-- LSL has some weird rounding of rotations, but it's ignored if you diredctly print the elements
           llSetObjectDesc( "set=<" +
                            (string)gNfoSet.x + "," +
                            (string)gNfoSet.y + "," +
                            (string)gNfoSet.s + "," +
                            (string)gNfoSet.s + ">" );
            //-- avoid rounding errors in chat and pull the "set" variable from the description we just installed
           llOwnerSay( "\n" + llList2String( gLstTxt, 0) + "\n" + llGetObjectDesc() );
           uAdjSiz( gNfoSet.s );
           
           llDialog( llGetOwner(), llList2String( gLstTxt, -1 ), [], vIntChn );
           
           state sRdy;
       }
   }

}

/*//-- License Text --//*/ /*// Free to copy, use, modify, distribute, or sell, with attribution. //*/ /*// (C)2010 (CC-BY) [ http://creativecommons.org/licenses/by/3.0 ] //*/ /*// Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ] //*/ /*// All usages must contain a plain text copy of the previous 2 lines. //*/ /*//-- --//*/</lsl>

Return to top

v7-D Zen Resizer (lite).cfg

  1. Create a notecard and name it v7-D Zen Resizer (lite).cfg
  2. Copy and paste the contents of the box below into it and save
// this is a comment, comments are good. anything begining with "//" will be ignored. so will blank lines.
txt0 = (v7-D Zen Resizer) Reading Notecard...
txt1 = (v7-D Zen Resizer) Notecard Read Failed; Retrying...
txt2 = (v7-D Zen Resizer) Ready.
txt3 = (v7-D Zen Resizer) Set Info Missing; Resize Aborted.
txt4 = (v7-D Zen Resizer) Resizing...
txt5 = (v7-D Zen Resizer) Resize Done.
txt6 = (v7-D Zen Resizer) Current Size Saved.
txt7 = (v7-D Zen Resizer) Dialog Timed Out.
txt8 = v7-D (v7-D Zen Resizer)  v1.3\n\nCurrent Size:
btn00 = +0.02%
btn01 = -0.02%
btn02 = Done
btn03 = +0.2%
btn04 = -0.2%
btn05 = Recall
btn06 = +2%
btn07 = -2%
btn08 = Save
btn09 = +20%
btn10 = -20%
btn11 = -Script
set = <0.0,0.0,0.0>
EOF

//-- Notecard must have the same name as the script plus ".cfg" added to the end (no quotes)
//-- You may have multiple notecards, each in a different language. to specify the
//--   language add the language code to the end of that. example: ".ja" for japanese
//-- Examples: "v7-D Zen Resizer.cfg.ja", or "v7-D Zen Resizer.cfg"
//--   the first would be used if the user had japanese as their SL client language
//--   the second would be used if no language could be found (or was not shared with object by the client)
//--     See [ http://wiki.secondlife.com/wiki/LlGetAgentLanguage ], for more details.

//-- text section explanation, replace with translated text, any missing line will use script defaults
//-- you may inlcude line breaks by using "\n" in these texts
//txt0 = <tell user we're reading the notecard> (this line should always be first in translations, and should ALWAYS be present)
//txt1 = <tell user we're going to reset reading the notecard because it timed out> (should always be the second line in translations)
//txt2 = <tell user: info missing, cannot resize>
//txt3 = <tell user: done reading notecard, ready to work>
//txt4 = <tell user: resizing the set> (in case the visual change isn't noticable)
//txt5 = <tell user: done resizing the set>
//txt6 = <tell user: saved current size>
//txt7 = <tell user: dialog timed out> (user took to long to make a choice, needs to reopen dialog to continue)
//txt8 = <Special: dialog box text to show user, the current percentage will be added to the end>

//-- button section explanation, replace with translated text, any missing line will use script defaults
//-- percentages must be from 0.01 to 100.00 (thoundands of whole percent)
//btn00 = <+/- percentage> (blank to disable)
//btn01 = <+/- percentage> (blank to disable)
//btn02 = <Closes Dialog>
//btn03 = <+/- percentage> (blank to disable)
//btn04 = <+/- percentage> (blank to disable)
//btn05 = <Reset to Saved Percentage>
//btn06 = <+/- percentage> (blank to disable)
//btn07 = <+/- percentage> (blank to disable)
//btn08 = <Save Current Percentage> (blank to disable)
//btn09 = <+/- percentage> (blank to disable)
//btn10 = <+/- percentage> (blank to disable)
//btn11 = <Remove Script> (blank to disable)

//-- Set value explanation: code from the prep script (remove this line to default to script or description field values)
//set = <0.0,0.0,0.0>

//-- "EOF" (no quotes) is a super comment, nothing after it will be read
Return to top

v7-D Zen Resizer (lite)

  1. Create a notecard and name it v7-D Zen Resizer (lite)
  2. Copy and paste the contents of the box below into it and save

<lsl>/*//( v7-D Zen Resizer (lite) v1.4 )//*/

/*//-- Notes:

Do Not Move/Rotate Object While It Is Resizing, it WILL break [LSL Limitation] (attached to moving av is safe)
- a bad idea for physics objects, or objects with active move/rotation scripts, or object being edited
(this limitation will be removed in the MONO Version I just haven't rewritten it yet)
The gNfoSet Global, and uAdjSiz function can easily be reused in custom scripts

//*/

/*//-- Menu Variables --//*/

//-- timeout for dialog listens and notecard reads

float gFltTmt = 45.0;

//-- Default Dialog Buttons

list gLstBtn = ["+0.02%", "-0.02%", "Done",

                   "+0.2%", "-0.2%", "Recall",
                   "+2%", "-2%", "Save",
                   "+20%", "-20%", "-Script"];
//-- Default User Text

list gLstTxt = ["(v7-D Zen Resizer) Reading Notecard...",

                   "(v7-D Zen Resizer) Notecard Read Failed; Retrying...",
                   "(v7-D Zen Resizer) Ready.",
                   "(v7-D Zen Resizer) Set Info Missing; Resize Aborted.",
                   "(v7-D Zen Resizer) Resizing...",
                   "(v7-D Zen Resizer) Resize Done.",
                   "(v7-D Zen Resizer) Current Size Saved.",
                   "(v7-D Zen Resizer) Dialog Timed Out.",
                   "v7-D Zen Resizer v1.3\n\nCurrent Size:"];


/*//-- The Centerpiece Global, stores the --//*/ rotation gNfoSet = <0.0, 0.0, 0.0, 0.0>;


/*//-- do not modify these variables. --//*/

//-- key of the user given the resize dialog (also used to store the notecard request id)

key gKeyMnu;

//-- channel the dialog will use (calculated per user) (also used to store the current notecard line)

integer gIntChn;

//-- stores the calculated name of the notecard (including translation if available)

string gStrNCL;


//-- Adjust Set Size

uAdjSiz( float vFltNew ){

    //-- clamp vFltNew to valid percentage [0.0, 1.0]
   vFltNew = (vFltNew * (vFltNew > 0.0) - 1.0) * (vFltNew < 1.0) + 1.0;
    //-- only run if previous percent greater or less than next percentage? (0 means the same)
   if ((vFltNew < gNfoSet.z) - (vFltNew > gNfoSet.z)){
        //-- get the current root size for comparison
       vector vSizOld = llGetScale();
        //-- save the new percentage to gNfoSet, and reuse gFltNew to save the relative change percentage
       vFltNew = (gNfoSet.x + gNfoSet.y * (gNfoSet.z = vFltNew)) / vSizOld.x;
       
        //-- intialize a temp list for holding child prims size/offset
       list vLstTmp;
        //-- get the number of prims for our loop + 1 (make loops cleaner later)
        //-- llGetObjectPrimCount doesn't count seated avs, but returns 0 for attachments
        //-- llGetNumberOfPrims works on attachments, but counts seated avs when detached
        //-- !!llGetAttached returns TRUE(1) if attached, or FALSE(0) if not, to cancel #ofPrims if unattached.
       integer  vIntCnt = ~-(llGetObjectPrimCount( llGetKey() ) +  llGetNumberOfPrims() * !!llGetAttached());
           //-- set the root prim separately since it's position will not change
       llSetLinkPrimitiveParamsFast( LINK_THIS, [PRIM_SIZE, vSizOld * vFltNew] );
       while (~-(--vIntCnt)){
           vLstTmp = llGetLinkPrimitiveParams( vIntCnt, [PRIM_SIZE, PRIM_POSITION] );
           llSetLinkPrimitiveParamsFast( vIntCnt,
                                         [PRIM_SIZE, llList2Vector( vLstTmp, 0 ) * vFltNew,
                                          PRIM_POS_LOCAL, llList2Vector( vLstTmp, 1 ) * vFltNew] );
       }
   }

}

//-- Menu

uDialog(){

    //-- Format the Current Size Percentage to thousandths of percent
   string vStrPct = (string)llRound( gNfoSet.z * 10000.0 );
   if (llStringLength( vStrPct ) < 3){
       vStrPct = llGetSubString( "00" + vStrPct, -3 , -1 );
   }
    //-- Pop the dialog
   llDialog( gKeyMnu, llList2String( gLstTxt, 8 ) + llInsertString( vStrPct, llStringLength( vStrPct ) - 2, "." ) + "%", gLstBtn, gIntChn );
    //-- set a timeout to capture dialog cancelation and close the listen
   llSetTimerEvent( gFltTmt );

}

uChkNfo(){

    //-- are we missing linkset information?
   if (0.0 == gNfoSet.y){
        //-- set it from the description if it's available
       string vStrTmp = llGetObjectDesc();
       integer vIdxTmp = llSubStringIndex( vStrTmp, "set=" );
       if (~vIdxTmp){
           gNfoSet = (rotation)llGetSubString( vStrTmp, vIdxTmp + 4, 0xFFFFFFFF );
       }
   }
    //-- if we have a valid info set, make sure to set an accurate current percentage.
   if (gNfoSet.y){
       vector vSizTmp = llGetScale();
       gNfoSet.z = (vSizTmp.x - gNfoSet.x) / gNfoSet.y;
   }

}


default{

   state_entry(){
        //-- Check for language specific notecard
       if (~llGetInventoryType( gStrNCL = llGetScriptName() + ".cfg." + llGetAgentLanguage( llGetOwner() ) )){
        //-- check for default notecard
       }else if (~llGetInventoryType( gStrNCL = llGetScriptName() + ".cfg")){
       }else{
            //-- no notecard available
           gStrNCL = "";
       }
        //-- if there is a notecard, start reading it
       if (gStrNCL){
            //-- pre-use the av global to verify notecard reads
           gKeyMnu = llGetNotecardLine( gStrNCL, gIntChn );
            //-- set a timeout for notecard reads
           llSetTimerEvent( gFltTmt );
       }else{
            //-- make sure we have good information for the set
           uChkNfo();
            //-- fast timeout to avoid dumping changed events
           llSetTimerEvent( 0.01 );
       }
   }
   
   dataserver( key vKeyQry, string vStrDta ){
        //-- make sure this event was triggered by our script
       if (gKeyMnu == vKeyQry){
            //-- are we done reading the notecard?
if (EOF == vStrDta

Questions or Comments?

Feel free to leave me a note on my User Talk page.