Difference between revisions of "Phantom Child"

From Second Life Wiki
Jump to navigation Jump to search
m (added LSL TIP with reference to PRIM_PHYSICS_SHAPE_TYPE)
m (→‎Switchable: made spaces consistent)
(4 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{Multi-lang|Phantom Child}}
{{LSL Header}}
{{LSL Header}}
{{LSL Tip|The examples listed below are '''NOT NEEDED''' anymore. This page is being kept for archiving purposes. Instead please set the [[PRIM_PHYSICS_SHAPE_TYPE]] to [[PRIM_PHYSICS_SHAPE_NONE]] for all child prims you want to set a phantom effect for.}}
{{LSL Tip|The examples listed below are '''NOT NEEDED''' anymore. This page is being kept for archiving purposes. Instead please set the [[PRIM_PHYSICS_SHAPE_TYPE]] to [[PRIM_PHYSICS_SHAPE_NONE]] for all child prims you want to set a phantom effect for.}}
Line 13: Line 14:
== Basic ==
== Basic ==


<lsl>//Phantom Child Script by Aeron Kohime
<source lang="lsl2">//Phantom Child Script by Aeron Kohime
//WARNING: When used on the root prim it makes the entire object phantom, it
//WARNING: When used on the root prim it makes the entire object phantom, it
//        also does not function correctly on tortured prims. (Sorry.)
//        also does not function correctly on tortured prims. (Sorry.)
Line 44: Line 45:
          
          
     }
     }
}</lsl>
}</source>


== Switchable ==
== Switchable ==
Line 50: Line 51:
Addition to the above script, a switchable version that could be useful for a phantom door.
Addition to the above script, a switchable version that could be useful for a phantom door.


<lsl>//Phantom Child Script by Aeron Kohime
<source lang="lsl2">//Phantom Child Script by Aeron Kohime
//WARNING: When used on the root prim it makes the entire object phantom, it
//WARNING: When used on the root prim it makes the entire object phantom, it
//        also does not function correctly on tortured prims. (Sorry.)
//        also does not function correctly on tortured prims. (Sorry.)
Line 57: Line 58:
//Phantom door idea added by Taff Nouvelle
//Phantom door idea added by Taff Nouvelle
//Psi Merlin updated CHANGED_REGION_START (live as of Server 1.27)
//Psi Merlin updated CHANGED_REGION_START (live as of Server 1.27)
//Sei Lisa made it work on newer sims


integer a = 1;
integer a = 1;
    
    
default
default
{
{
    state_entry()
    {
    }
     touch_start(integer total_number)
     touch_start(integer total_number)
     {
     {
    a*=-1;
        a = !a;
    if(a == 1)
        if (a)
    {
        {
        llSetPrimitiveParams([PRIM_TYPE, PRIM_TYPE_BOX,
            llSetPrimitiveParams([PRIM_TYPE, PRIM_TYPE_BOX,
            0, <0,1,0>, 0, <0,0,0>, <1,1,0>, <0,0,0>,
                0, <0,1,0>, 0, <0,0,0>, <1,1,0>, <0,0,0>,
            PRIM_FLEXIBLE, TRUE, 0, 0, 0, 0, 0, <0,0,0>,
                PRIM_FLEXIBLE, TRUE, 0, 0, 0, 0, 0, <0,0,0>,
            PRIM_TYPE] + llGetPrimitiveParams([PRIM_TYPE]));  
                PRIM_TYPE] + llGetPrimitiveParams([PRIM_TYPE]));  
             llOwnerSay ("Phantom");
             llOwnerSay("Phantom");
        }
        else
        {
            llSetPrimitiveParams([PRIM_PHANTOM, TRUE, PRIM_PHANTOM, FALSE]);
            llOwnerSay("Solid");
        }
     }
     }
     else
     on_rez(integer s)
     {
     {
        llSetPrimitiveParams([PRIM_PHANTOM, FALSE]);
        llOwnerSay ("Solid");
    }
}
    on_rez(integer s) {
         llResetScript();
         llResetScript();
     }
     }
     changed (integer vBitChanges){
     changed (integer vBitChanges)
         if (CHANGED_REGION_START & vBitChanges){
    {
         if (CHANGED_REGION_START & vBitChanges)
             llResetScript();
             llResetScript();
        }
     }
     }
}</lsl>
}
</source>


== New Functions ==
== New Functions ==
Line 97: Line 98:
This can be applied to any number of prims in the linkset, but not the root prim.
This can be applied to any number of prims in the linkset, but not the root prim.


<lsl>
<source lang="lsl2">
default
default
{
{
Line 105: Line 106:
     }
     }
}
}
</lsl>
</source>


== Advanced ==
== Advanced ==
Line 111: Line 112:
Unlike the versions above, this version will work with ANY prim type (torus, tube, box, sculpt etc.) with ANY shaping parameters (twist, hollow, taper, slice, dimple etc.) and ANY texturing applied (glow, texture, fullbright, color etc.) without changing those parameters. In other words... This version works in ALL cases without error (At least I'm pretty sure it does ). The downside being a greater memory use and slower run time (Although this is negligible) for complex (tortured) prims. Should only be used on child prims.
Unlike the versions above, this version will work with ANY prim type (torus, tube, box, sculpt etc.) with ANY shaping parameters (twist, hollow, taper, slice, dimple etc.) and ANY texturing applied (glow, texture, fullbright, color etc.) without changing those parameters. In other words... This version works in ALL cases without error (At least I'm pretty sure it does ). The downside being a greater memory use and slower run time (Although this is negligible) for complex (tortured) prims. Should only be used on child prims.


<lsl>list PRIM_PHANTOM_HACK = [
<source lang="lsl2">list PRIM_PHANTOM_HACK = [
     PRIM_FLEXIBLE, 1, 0, 0.0, 0.0, 0.0, 0.0, <0,0,0>,
     PRIM_FLEXIBLE, 1, 0, 0.0, 0.0, 0.0, 0.0, <0,0,0>,
     PRIM_FLEXIBLE, 0, 0, 0.0, 0.0, 0.0, 0.0, <0,0,0>];
     PRIM_FLEXIBLE, 0, 0, 0.0, 0.0, 0.0, 0.0, <0,0,0>];
Line 227: Line 228:
     }
     }
}
}
</lsl>
</source>


==Sculpted Children==
==Sculpted Children==
A modified version of above that will go through all the prims in a linkset and turn only the sculpts phantom. [[User:ninjafoo Ng|ninjafoo Ng]]
A modified version of above that will go through all the prims in a linkset and turn only the sculpts phantom. [[User:ninjafoo Ng|ninjafoo Ng]]
<lsl>
<source lang="lsl2">
// Makes all child sculpted prims phantom, leaves all regular prims alone.
// Makes all child sculpted prims phantom, leaves all regular prims alone.


Line 279: Line 280:
     }
     }
}
}
</lsl>
</source>




{{LSLC|Library}}
{{LSLC|Library}}
{{LSLC|Examples}}
{{LSLC|Examples}}

Revision as of 08:48, 7 July 2015

KBcaution.png Important: The examples listed below are NOT NEEDED anymore. This page is being kept for archiving purposes. Instead please set the PRIM_PHYSICS_SHAPE_TYPE to PRIM_PHYSICS_SHAPE_NONE for all child prims you want to set a phantom effect for.

Phantom Child

This easy to use code when put into a child prim of a linkset will make that child and only that child phantom, even when taken into inventory and re-rezzed. You can use multiple copies of this script to make multiple children of a linkset phantom.

This code relies on a bug in Second Life and may not function in later versions (Currently working in server 1.36). This script was created in part by Aeron Kohime and documents this useful bug (which like invis-prims, has countless applications).

You may use the following script in any manner you like, excluding claiming you made it and individually reselling it without change in function (its on the Wiki silly). Otherwise you can sell it as part of a product, modify it, remove my comments, etc etc.

It needs to be reset on sim restarts. A reliable solution is included in all these scripts. Checking llGetTime and a timer could be used but, is a more "expensive" method.

Basic

//Phantom Child Script by Aeron Kohime
//WARNING: When used on the root prim it makes the entire object phantom, it
//         also does not function correctly on tortured prims. (Sorry.)
//Reset on Sim restart added by Void Singer
//Strife Onizuka was here doing simplification
//Reset on collision added by Taff Nouvelle (my stairs kept reverting)
//Psi Merlin updated CHANGED_REGION_START (live as of Server 1.27)
//New function code added by Taff Nouvelle December 15th.

default {
    state_entry() {
        llSetPrimitiveParams([PRIM_TYPE, PRIM_TYPE_BOX,
            0, <0,1,0>, 0, <0,0,0>, <1,1,0>, <0,0,0>,
            PRIM_FLEXIBLE, TRUE, 0, 0, 0, 0, 0, <0,0,0>,
            PRIM_TYPE] + llGetPrimitiveParams([PRIM_TYPE]));
    }
 
    on_rez(integer s) {
        llResetScript();
    }
 
    //-- This event/test will reset the script on sim restart.
    changed (integer vBitChanges){
        if (CHANGED_REGION_START & vBitChanges){
            llResetScript();
        }
    }
    collision_start(integer num_detected){
        llResetScript();
        
    }
}

Switchable

Addition to the above script, a switchable version that could be useful for a phantom door.

//Phantom Child Script by Aeron Kohime
//WARNING: When used on the root prim it makes the entire object phantom, it
//         also does not function correctly on tortured prims. (Sorry.)
//Reset on Sim restart added by Void Singer
//Strife Onizuka was here doing simplification
//Phantom door idea added by Taff Nouvelle
//Psi Merlin updated CHANGED_REGION_START (live as of Server 1.27)
//Sei Lisa made it work on newer sims

integer a = 1;
  
default
{
    touch_start(integer total_number)
    {
        a = !a;
        if (a)
        {
            llSetPrimitiveParams([PRIM_TYPE, PRIM_TYPE_BOX,
                0, <0,1,0>, 0, <0,0,0>, <1,1,0>, <0,0,0>,
                PRIM_FLEXIBLE, TRUE, 0, 0, 0, 0, 0, <0,0,0>,
                PRIM_TYPE] + llGetPrimitiveParams([PRIM_TYPE])); 
            llOwnerSay("Phantom");
        }
        else
        {
            llSetPrimitiveParams([PRIM_PHANTOM, TRUE, PRIM_PHANTOM, FALSE]);
            llOwnerSay("Solid");
        }
    }
    on_rez(integer s) 
    {
        llResetScript();
    }
    changed (integer vBitChanges)
    {
        if (CHANGED_REGION_START & vBitChanges)
            llResetScript();
    }
}

New Functions

New functions brought in with MESH now make setting a child prim to phantom very simple. This can be applied to any number of prims in the linkset, but not the root prim.

default
{
    state_entry()
    {
        llSetLinkPrimitiveParamsFast(LINK_THIS,[ PRIM_PHYSICS_SHAPE_TYPE,PRIM_PHYSICS_SHAPE_NONE]);
    }
}

Advanced

Unlike the versions above, this version will work with ANY prim type (torus, tube, box, sculpt etc.) with ANY shaping parameters (twist, hollow, taper, slice, dimple etc.) and ANY texturing applied (glow, texture, fullbright, color etc.) without changing those parameters. In other words... This version works in ALL cases without error (At least I'm pretty sure it does ). The downside being a greater memory use and slower run time (Although this is negligible) for complex (tortured) prims. Should only be used on child prims.

list PRIM_PHANTOM_HACK = [
    PRIM_FLEXIBLE, 1, 0, 0.0, 0.0, 0.0, 0.0, <0,0,0>,
    PRIM_FLEXIBLE, 0, 0, 0.0, 0.0, 0.0, 0.0, <0,0,0>];

list Params()
{
    list result = [];
    integer i = 0;
    integer face = 0;
    list src = llGetPrimitiveParams([PRIM_TEXTURE, ALL_SIDES]);
    integer len = llGetListLength(src);
    do
    {
        result += [PRIM_TEXTURE, face] + llList2List(src, i, (i + 3));
        face++;
        i += 4;
    }
    while(i < len);
    
    i = 0;
    face = 0;
    src = llGetPrimitiveParams([PRIM_COLOR, ALL_SIDES]);
    len = llGetListLength(src);
    do
    {
        result += [PRIM_COLOR, face] + llList2List(src, i, (i + 1));
        face++;
        i += 2;
    }
    while(i < len);
    
    i = 0;
    face = 0;
    src = llGetPrimitiveParams([PRIM_BUMP_SHINY, ALL_SIDES]);
    len = llGetListLength(src);
    do
    {
        result += [PRIM_BUMP_SHINY, face] + llList2List(src, i, (i + 1));
        face++;
        i += 2;
    }
    while(i < len);
    
    i = 0;
    face = 0;
    src = llGetPrimitiveParams([PRIM_FULLBRIGHT, ALL_SIDES]);
    len = llGetListLength(src);
    do
    {
        result += [PRIM_FULLBRIGHT, face] + llList2List(src, i, i);
        face++;
        i++;
    }
    while(i < len);
    i = 0;
    face = 0;
    src = llGetPrimitiveParams([PRIM_TEXGEN, ALL_SIDES]);
    len = llGetListLength(src);
    do
    {
        result += [PRIM_TEXGEN, face] + llList2List(src, i, i);
        face++;
        i++;
    }
    while(i < len);
    
    i = 0;
    face = 0;
    src = llGetPrimitiveParams([PRIM_GLOW, ALL_SIDES]);
    len = llGetListLength(src);
    do
    {
        result += [PRIM_GLOW, face] + llList2List(src, i, i);
        face++;
        i++;
    }
    while(i < len);

    return result;
}

default
{
    state_entry()
    {
        list type_params = llGetPrimitiveParams([PRIM_TYPE]);
        integer type = llList2Integer(type_params, 0);
        if(type > PRIM_TYPE_PRISM)
        {
            // After prism comes sphere, torus, tube, ring and sculpt.
            if(type != PRIM_TYPE_SCULPT)
                type_params += Params();
            
            llSetPrimitiveParams([PRIM_TYPE, PRIM_TYPE_BOX, PRIM_HOLE_DEFAULT, <0,1,0>, 0, <0,0,0>, <1,1,0>, <0,0,0>]
                                  + PRIM_PHANTOM_HACK
                                  + [PRIM_TYPE] + type_params);
        }
        else
        {
            llSetPrimitiveParams(PRIM_PHANTOM_HACK);
        }
    }
    changed(integer change)
    {
        if(change & CHANGED_REGION_START)
            llResetScript();
    }
    on_rez(integer param)
    {
        llResetScript();
    }
    collision_start(integer nd)
    {
        llResetScript();
    }
}

Sculpted Children

A modified version of above that will go through all the prims in a linkset and turn only the sculpts phantom. ninjafoo Ng

// Makes all child sculpted prims phantom, leaves all regular prims alone.

list PRIM_PHANTOM_HACK = [
    PRIM_FLEXIBLE, 1, 0, 0.0, 0.0, 0.0, 0.0, <0,0,0>,
    PRIM_FLEXIBLE, 0, 0, 0.0, 0.0, 0.0, 0.0, <0,0,0>];
    
integer get_number_of_prims()
{//ignores avatars.
    integer a = llGetNumberOfPrims();
    //Mono tweak
    vector size = llGetAgentSize(llGetLinkKey(a));
    while(size.z > 0)
    {
        --a;
        size = llGetAgentSize(llGetLinkKey(a));
    }
    return a;
}
         
default
{
    state_entry()
    {
        integer num_prims = get_number_of_prims();
        integer x;
        list prim_params;
        integer prim_type;

        for(x=2;x<=num_prims;++x)
        {
            prim_params = llGetLinkPrimitiveParams(x,[PRIM_TYPE]);
            prim_type = llList2Integer(prim_params, 0);
            if(prim_type == PRIM_TYPE_SCULPT)    {
                llSetLinkPrimitiveParamsFast(x,
                    [PRIM_TYPE, PRIM_TYPE_BOX, PRIM_HOLE_DEFAULT, <0,1,0>, 0, <0,0,0>, <1,1,0>, <0,0,0>]
                    + PRIM_PHANTOM_HACK
                    + [PRIM_TYPE] + prim_params
                    );
            }  
        }
    }
    changed (integer vBitChanges){
        if (CHANGED_REGION_START & vBitChanges){
            llResetScript();
        }
    }
}