Difference between revisions of "Curtain script"

From Second Life Wiki
Jump to navigation Jump to search
(replaced example script with three example scripts, one for each axis.)
(Replace 3 rambling scripts with one concise multi-purpose script)
Line 1: Line 1:
{{LSL Header}}
{{LSL Header}}
== About these scripts: ==
== About this script: ==


Drop these scripts into the prim you want to use as a curtain. The script will change the length of the prim on one of the three axis. There's one script each for x, y and z.
Drop this script into the prim you want to use as a curtain etc.  
The script will change the length of the prim on one or more axes.
Use sliced or path-cut prims to keep an edge stationary, e.g. in a blind.
For a Mesh prim, arrange for the pivot point to be on one edge.


You can use these scripts with any prim type.
You can use these scripts with any prim type.


== Curtain script to change length on x-axis ==
<lsl>
<lsl>
float maxScaleX;
// Prim Resizer (shrink/expand) by Omei Qunhua
float minScaleX;
// e.g. Roll a blind from the top. (use a prim with slice end = 50%)
float time;
integer direction;


init()
// Note: This script can rescale a prim on any or all axes
{
    maxScaleX = 4.00;
    minScaleX = 0.50;
    time = 2.0;
 
    direction = 1;
}
 
OperateBlind()
{
    vector startScale = llGetScale();
    vector startPos = llGetLocalPos();
    rotation localRot = llGetLocalRot();
    float i;
    llResetTime();
    do
    {
        i = llGetTime()/time;
        if (direction == 1)
            llSetLinkPrimitiveParamsFast(LINK_THIS,[
                PRIM_SIZE, <maxScaleX - i*(maxScaleX-minScaleX), startScale.y, startScale.z>,
                PRIM_POSITION, startPos + i*<(maxScaleX-minScaleX)*0.5, 0.0, 0.0>*localRot]);
        else if (direction == -1)
            llSetLinkPrimitiveParamsFast(LINK_THIS,[
                PRIM_SIZE, <minScaleX + i*(maxScaleX-minScaleX), startScale.y, startScale.z>,
                PRIM_POSITION, startPos - i*<(maxScaleX-minScaleX)*0.5, 0.0, 0.0>*localRot]);
    }
    while (llGetTime() < time);
    if (direction == 1)
        llSetLinkPrimitiveParamsFast(LINK_THIS,[
            PRIM_SIZE, <maxScaleX - i*(maxScaleX-minScaleX), startScale.y, startScale.z>,
            PRIM_POSITION, startPos + i*<(maxScaleX-minScaleX)*0.5, 0.0, 0.0>*localRot]);
    else if (direction == -1)
        llSetLinkPrimitiveParamsFast(LINK_THIS,[
            PRIM_SIZE, <minScaleX + i*(maxScaleX-minScaleX), startScale.y, startScale.z>,
            PRIM_POSITION, startPos - i*<(maxScaleX-minScaleX)*0.5, 0.0, 0.0>*localRot]);
    direction *= -1;
}
 
default
{
    state_entry()
    {
        init();
    }
 
    touch_start(integer num_detected)
    {
        OperateBlind();
    }
}
</lsl>
== Curtain script to change length on y-axis ==
<lsl>
float maxScaleY;
float minScaleY;
float time;
integer direction;
 
init()
{
    maxScaleY = 4.00;
    minScaleY = 0.50;
    time = 2.0;


    direction = 1;
// Define the large and small sizes of the prim here:-
}
// (if the prim is sliced or path cut, it will appear to be half size on the affected dimension)
vector  ScaleLarge = <0.1, 3.0, 6.0>;
vector  ScaleSmall = <0.1, 3.0, 1.2>;


OperateBlind()
integer gSteps  = 20;   // Number of steps in the shrink/expand process
{
float   gSwitch = 1.0; // Action on first touch. +1.0 = shrink, -1.0 = expand
    vector startScale = llGetScale();
    vector startPos = llGetLocalPos();
    rotation localRot = llGetLocalRot();
    float i;
    llResetTime();
    do
    {
        i = llGetTime()/time;
        if (direction == 1)
            llSetLinkPrimitiveParamsFast(LINK_THIS,[
                PRIM_SIZE, <startScale.x, maxScaleY - i*(maxScaleY-minScaleY), startScale.z>,
                PRIM_POSITION, startPos + i*<0.0, (maxScaleY-minScaleY)*0.5, 0.0>*localRot]);
        else if (direction == -1)
            llSetLinkPrimitiveParamsFast(LINK_THIS,[
                PRIM_SIZE, <startScale.x, minScaleY + i*(maxScaleY-minScaleY), startScale.z>,
                PRIM_POSITION, startPos - i*<0.0, (maxScaleY-minScaleY)*0.5, 0.0>*localRot]);
    }
    while (llGetTime() < time);
    if (direction == 1)
        llSetLinkPrimitiveParamsFast(LINK_THIS,[
            PRIM_SIZE, <startScale.x, maxScaleY - (maxScaleY-minScaleY), startScale.z>,
            PRIM_POSITION, startPos + <0.0, (maxScaleY-minScaleY)*0.5, 0.0>*localRot]);
    else if (direction == -1)
        llSetLinkPrimitiveParamsFast(LINK_THIS,[
            PRIM_SIZE, <startScale.x, minScaleY + (maxScaleY-minScaleY), startScale.z>,
            PRIM_POSITION, startPos - <0.0, (maxScaleY-minScaleY)*0.5, 0.0>*localRot]);
    direction *= -1;
}


default
default
Line 117: Line 27:
     state_entry()
     state_entry()
     {
     {
        init();
llSetScale(ScaleLarge);
     }
     }


     touch_start(integer num_detected)
     on_rez(integer x)
     {
     {
        OperateBlind();
llResetScript();
     }
     }
}
</lsl>
== Curtain script to change length on z-axis ==
<lsl>
float maxScaleZ;
float minScaleZ;
float time;
integer direction;


init()
     touch_start(integer total_number)
{
    maxScaleZ = 4.00;
    minScaleZ = 0.50;
    time = 2.0;
 
     direction = 1;
}
 
OperateBlind()
{
    vector startScale = llGetScale();
    vector startPos = llGetLocalPos();
    rotation localRot = llGetLocalRot();
    float i;
    llResetTime();
    do
     {
     {
        i = llGetTime()/time;
vector ScaleStep = (ScaleLarge - ScaleSmall) / gSteps; // Compute the scale augment per step
        if (direction == 1)
vector wscale = llGetScale();
            llSetLinkPrimitiveParamsFast(LINK_THIS,[
gSwitch *= -1;  // Switch between stretch and contract
                PRIM_SIZE, <startScale.x, startScale.y, maxScaleZ - i*(maxScaleZ-minScaleZ)>,
integer i;
                PRIM_POSITION, startPos + i*<0.0, 0.0, (maxScaleZ-minScaleZ)*0.5>*localRot]);
for (i = 0; i < gSteps; i++)
        else if (direction == -1)
{
            llSetLinkPrimitiveParamsFast(LINK_THIS,[
    // It is more lag-friendly to incorporate a sleep per step
                PRIM_SIZE, <startScale.x, startScale.y, minScaleZ + i*(maxScaleZ-minScaleZ)>,
    // Rather than greatly increasing the number of steps
                PRIM_POSITION, startPos - i*<0.0, 0.0, (maxScaleZ-minScaleZ)*0.5>*localRot]);
    llSleep(0.1); 
    llSetScale(wscale + ScaleStep * i * gSwitch);  
}
     }
     }
    while (llGetTime() < time);
    if (direction == 1)
        llSetLinkPrimitiveParamsFast(LINK_THIS,[
            PRIM_SIZE, <startScale.x, startScale.y, maxScaleZ - (maxScaleZ-minScaleZ)>,
            PRIM_POSITION, startPos + <0.0, 0.0, (maxScaleZ-minScaleZ)*0.5>*localRot]);
    else if (direction == -1)
        llSetLinkPrimitiveParamsFast(LINK_THIS,[
            PRIM_SIZE, <startScale.x, startScale.y, minScaleZ + (maxScaleZ-minScaleZ)>,
            PRIM_POSITION, startPos - <0.0, 0.0, (maxScaleZ-minScaleZ)*0.5>*localRot]);
    direction *= -1;
}
}


default
{
    state_entry()
    {
        init();
    }
    touch_start(integer num_detected)
    {
        OperateBlind();
    }
}
</lsl>
</lsl>
{{LSLC|Library}}
{{LSLC|Library}}

Revision as of 07:46, 14 December 2012

About this script:

Drop this script into the prim you want to use as a curtain etc. The script will change the length of the prim on one or more axes. Use sliced or path-cut prims to keep an edge stationary, e.g. in a blind. For a Mesh prim, arrange for the pivot point to be on one edge.

You can use these scripts with any prim type.

<lsl> // Prim Resizer (shrink/expand) by Omei Qunhua // e.g. Roll a blind from the top. (use a prim with slice end = 50%)

// Note: This script can rescale a prim on any or all axes

// Define the large and small sizes of the prim here:- // (if the prim is sliced or path cut, it will appear to be half size on the affected dimension) vector ScaleLarge = <0.1, 3.0, 6.0>; vector ScaleSmall = <0.1, 3.0, 1.2>;

integer gSteps = 20; // Number of steps in the shrink/expand process float gSwitch = 1.0; // Action on first touch. +1.0 = shrink, -1.0 = expand

default {

   state_entry()
   {

llSetScale(ScaleLarge);

   }
   on_rez(integer x)
   {

llResetScript();

   }
   touch_start(integer total_number)
   {

vector ScaleStep = (ScaleLarge - ScaleSmall) / gSteps; // Compute the scale augment per step vector wscale = llGetScale(); gSwitch *= -1; // Switch between stretch and contract integer i; for (i = 0; i < gSteps; i++) { // It is more lag-friendly to incorporate a sleep per step // Rather than greatly increasing the number of steps llSleep(0.1); llSetScale(wscale + ScaleStep * i * gSwitch); }

   }

}

</lsl>