Wednesday, June 6, 2012

TECHNICAL


Second Life Script making programme - SCRATCH4SL

Examples of used scripts in our building:

Triangular elements elegantly moving up and down, slowly, emphasising its floating motion.
Triangular elements moving script when typing 'open'.





Other scripts are involved as well which are as simple as moving up and down.


TELEPORT SCRIPT
from ground level to first floor

//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//_/_/_/_/_/_/_/_/_/_/_/_/_/ The script begins _/_/_/_/_/_/_/_/_/_/_/_/_/_/
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
vector destination = <22.860,156.773,48.387(co-ordinates to the first floor)>; // the destination coordinate
string text = "Touch To Teleport to first floor"; // optional floating text on the teleporter, input a space if not used
vector text_color = <1.0,1.0,1.0>; // the floating text's color
integer touch2sit = TRUE; // TRUE - left click to sit; FALSE - left click to touch
integer access_mode = 1; // 1 - public; 2 - owner; 3 - group;

//=================================================
posJump( vector target_position )
{// Trickery discovered by Uchi Desmoulins and Gonta Maltz. More exact value provided by Fake Fitzgerald.
    llSetPrimitiveParams([PRIM_POSITION, <1.304382E+19, 1.304382E+19, 0.0>, PRIM_POSITION, target_position ]);
}
//=================================================
warpPos( vector destpos )
{   //R&D by Keknehv Psaltery, 05/25/2006; unlimited modified by Klug Kuhn 10/01/2008

    // Change this safety range depends on your script memory
    // The larger the range, the quicker (and less "flashes") to get to the destination, however, the more to eat up script memory.
    float safety_range = 1000.0;


    integer arrived = FALSE;
    integer within_range = FALSE;
    vector inter_pos = ZERO_VECTOR;
    vector current_pos = llGetPos();
    vector checking_pos = destpos;
    integer jumps = 0;
    list rules = [];
    integer count = 0;

    if (llVecDist(destpos, current_pos) <= safety_range)
    {
        jumps = (integer)(llVecDist(destpos, current_pos) / 10.0) + 1;
        rules = [ PRIM_POSITION, destpos ];  //The start for the rules list
        count = 1;
        while ( ( count = count << 1 ) < jumps)
            rules = (rules=[]) + rules + rules;   //should tighten memory use.
        llSetPrimitiveParams( rules + llList2List( rules, (count - jumps) << 1, count) );          
    }
    else
    {
        while (!arrived)
        {
            current_pos = llGetPos();
            checking_pos = destpos;
         
            within_range = FALSE;            
            while (!within_range)
            {
                if (llVecDist(checking_pos,current_pos) > safety_range)
                {
                    checking_pos = <(current_pos.x + checking_pos.x) / 2.0,(current_pos.y + checking_pos.y) / 2.0,(current_pos.z + checking_pos.z) / 2.0>;
                }
                else
                {
                    within_range = TRUE;
                 
                    if (llVecDist(destpos, current_pos) <= safety_range)
                    {
                        jumps = (integer)(llVecDist(destpos, current_pos) / 10.0) + 1;
                        rules = [ PRIM_POSITION, destpos ];  //The start for the rules list
                        count = 1;
                        while ( ( count = count << 1 ) < jumps)
                            rules = (rules=[]) + rules + rules;   //should tighten memory use.
                        llSetPrimitiveParams( rules + llList2List( rules, (count - jumps) << 1, count) );          
                     
                        arrived = TRUE;
                    }                  
                }
            }
         
            if (!arrived)
            {
                jumps = (integer)(llVecDist(checking_pos, current_pos) / 10.0) + 1;
                rules = [ PRIM_POSITION, checking_pos ];  //The start for the rules list
                count = 1;
                while ( ( count = count << 1 ) < jumps)
                    rules = (rules=[]) + rules + rules;   //should tighten memory use.
                llSetPrimitiveParams( rules + llList2List( rules, (count - jumps) << 1, count) );
            }
        }
    }
}
//=================================================
default
{
    state_entry()
    {
        llSitTarget(<0.0, 0.0, 0.01>, ZERO_ROTATION);                      
        llSetText(text,text_color,1.0);
        if (touch2sit)
            llSetClickAction(CLICK_ACTION_SIT);
        else
            llSetClickAction(CLICK_ACTION_NONE);
    }
    changed(integer change)
    {
        if (change & CHANGED_LINK)
        {
            key user = llAvatarOnSitTarget();
            if (llGetAgentSize(user) != ZERO_VECTOR)
            {
                integer access_granted = FALSE;
                if (access_mode == 1)
                    access_granted = TRUE;
                else if (access_mode == 2)
                {
                    if (user == llGetOwner())
                        access_granted = TRUE;
                    else
                    {
                        llUnSit(user);                      
                        llSay(0,"  sorry, owner access only.");
                    }
                }
                else if (access_mode == 3)
                {
                    if (llSameGroup(user))
                        access_granted = TRUE;
                    else
                    {
                        llUnSit(user);
                        llSay(0,"  sorry, group memeber access only.");
                    }
                }
             
                if (access_granted)
                {
                    vector init_pos = llGetPos();              
//                  warpPos(destination); // use warPos() function
                    posJump(destination); // use posJump() function
                    llUnSit(user);
                    llSleep(0.2);
//                  warpPos(init_pos); // use warPos() function
                    posJump(init_pos); // use posJump() function              
                }
            }
        }
    }  
}
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//_/_/_/_/_/_/_/_/_/_/_/_/_/ The script ends _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/


script: 'open'
script: 'up'/'down' and 'touch to teleport to first floor'
script: touch blog to scroll up and down, 'stairs up'/'stairs down', 'level 4'/'level 4 close' and sit on the moon chair
(my file was too big so I am using Daeun's avatar's version)

script: 'door', 'journals' and 'back'

No comments:

Post a Comment