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.)
Line 1: Line 1:
{{LSL Header}}
{{LSL Header}}
General no frills script to retract and stretch back out a prim for use in curtains, blinds, bed covers and more. Choose local axis and direction for move/size change. Works both in unlinked and linked prims, but must not be root prim.
== About these scripts: ==


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.
You can use these scripts with any prim type.
== Curtain script to change length on x-axis ==
<lsl>
<lsl>
//When touched the prim is retracted towards one end and when touched again stretched back out.
float maxScaleX;
//
float minScaleX;
//Prim moves/changes size along the local coordinate specified in the offset vector below.
float time;
//
integer direction;
//To change the overall size, edit the prim when stretched out and reset the script when done.
//
//The script works both in unlinked and linked prims.
//
// Copyright (C) 2008 Zilla Larsson
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License version 3, as
//    published by the Free Software Foundation.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>


init()
{
    maxScaleX = 4.00;
    minScaleX = 0.50;
    time = 2.0;


vector offset = <1,0,0>; //Prim moves/changes size along this local coordinate
    direction = 1;
float hi_end_fixed = FALSE; //Which end of the prim should remain in place when size changes?         
}
                            //The one with the higher (local) coordinate?
float min = 0.2; //The minimum size of the prim relative to its maximum size
integer ns = 10; //Number of distinct steps for move/size change


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 {
default
     state_entry() {
{
         offset *= ((1.0 - min) / ns) * (offset * llGetScale());
     state_entry()
        hi_end_fixed -= 0.5;
    {
         init();
     }
     }
   
 
     touch_start(integer detected) {
     touch_start(integer num_detected)
         integer i;
    {
        do  llSetPrimitiveParams([PRIM_SIZE, llGetScale() - offset,
         OperateBlind();
                PRIM_POSITION, llGetLocalPos() + ((hi_end_fixed * offset) * llGetLocalRot())]);
        while ((++i) < ns);         
        offset = - offset;
     }
     }
}
}
</lsl>
</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;
}
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, <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
{
    state_entry()
    {
        init();
    }


    touch_start(integer num_detected)
    {
        OperateBlind();
    }
}
</lsl>
== Curtain script to change length on z-axis ==
<lsl>
float maxScaleZ;
float minScaleZ;
float time;
integer direction;
init()
{
    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;
        if (direction == 1)
            llSetLinkPrimitiveParamsFast(LINK_THIS,[
                PRIM_SIZE, <startScale.x, startScale.y, maxScaleZ - i*(maxScaleZ-minScaleZ)>,
                PRIM_POSITION, startPos + i*<0.0, 0.0, (maxScaleZ-minScaleZ)*0.5>*localRot]);
        else if (direction == -1)
            llSetLinkPrimitiveParamsFast(LINK_THIS,[
                PRIM_SIZE, <startScale.x, startScale.y, minScaleZ + i*(maxScaleZ-minScaleZ)>,
                PRIM_POSITION, startPos - i*<0.0, 0.0, (maxScaleZ-minScaleZ)*0.5>*localRot]);
    }
    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>
{{LSLC|Library}}
{{LSLC|Library}}

Revision as of 09:19, 17 October 2012

About these scripts:

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.

You can use these scripts with any prim type.

Curtain script to change length on x-axis

<lsl> float maxScaleX; float minScaleX; float time; integer direction;

init() {

   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;

}

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, <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 {

   state_entry()
   {
       init();
   }
   touch_start(integer num_detected)
   {
       OperateBlind();
   }

} </lsl>

Curtain script to change length on z-axis

<lsl> float maxScaleZ; float minScaleZ; float time; integer direction;

init() {

   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;
       if (direction == 1)
           llSetLinkPrimitiveParamsFast(LINK_THIS,[
               PRIM_SIZE, <startScale.x, startScale.y, maxScaleZ - i*(maxScaleZ-minScaleZ)>,
               PRIM_POSITION, startPos + i*<0.0, 0.0, (maxScaleZ-minScaleZ)*0.5>*localRot]);
       else if (direction == -1)
           llSetLinkPrimitiveParamsFast(LINK_THIS,[
               PRIM_SIZE, <startScale.x, startScale.y, minScaleZ + i*(maxScaleZ-minScaleZ)>,
               PRIM_POSITION, startPos - i*<0.0, 0.0, (maxScaleZ-minScaleZ)*0.5>*localRot]);
   }
   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>