Phantom Child

From Second Life Wiki
Revision as of 00:18, 13 April 2010 by Fred Gandt (talk | contribs) (Can someone verify that I have got it right at last?)
Jump to navigation Jump to search

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 Secondlife and may not function in later versions (currently server version 1.24)(UPDATE: Still works 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. one possible solution is included below. Checking llGetTime in a timer may be another.

<lsl> //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)

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();
       
   }

} </lsl>

Addition to this script, a switchable version that is useful for a phantom door.

<lsl>

//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)

integer a = 1;

default

{
   state_entry()
   {
   }
   touch_start(integer total_number)
   {
   a*=-1;
   if(a == 1)
   {
       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, FALSE]);
       llOwnerSay ("Solid");
   }

}

   on_rez(integer s) {
       llResetScript();
   }
   changed (integer vBitChanges){
       if (CHANGED_REGION_START & vBitChanges){
           llResetScript();
       }
   }

} </lsl>

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).

<lsl>list Params() {

   list p;
   integer l; // length
   integer c; // count
   integer f; // face
   list s = llGetPrimitiveParams([17, -1]);
   l = llGetListLength(s);
   do
   {
       p += [17, (f++)] + llList2List(s, c, (c + 3));
       c = (c + 4);
   }
   while(c < l);
   c = 0;
   f = 0;
   s = llGetPrimitiveParams([18, -1]);
   l = llGetListLength(s);
   do
   {
       p += [18, (f++)] + llList2List(s, c, (c + 1));
       c = (c + 2);
   }
   while(c < l);
   c = 0;
   f = 0;
   s = llGetPrimitiveParams([19, -1]);
   l = llGetListLength(s);
   do
   {
       p += [19, (f++)] + llList2List(s, c, (c + 1));
       c = (c + 2);
   }
   while(c < l);
   c = 0;
   f = 0;
   s = llGetPrimitiveParams([20, -1]);
   l = llGetListLength(s);
   do
   p += [20, (f++)] + llList2List(s, c, c);
   while((++c) < l);
   c = 0;
   f = 0;
   s = llGetPrimitiveParams([22, -1]);
   l = llGetListLength(s);
   do
   p += [22, (f++)] + llList2List(s, c, c);
   while((++c) < l);
   c = 0;
   f = 0;
   s = llGetPrimitiveParams([25, -1]);
   l = llGetListLength(s);
   do
   p += [25, (f++)] + llList2List(s, c, c);
   while((++c) < l);
   return p;

}

default {

   state_entry()
   {
       list params = llGetPrimitiveParams([9]);
       integer type = llList2Integer(params, 0);
       if(type > 2)
       {
           if(type != 7)
           params += Params();
           llSetPrimitiveParams([9, 0, 0, <0.0,1.0,0.0>, 0.0, <0.0,0.0,0.0>, <1.0,1.0,0.0>, <0.0,0.0,0.0>,
                                 21, 1, 0, 0.0, 0.0, 0.0, 0.0, <0.0,0.0,0.0>,
                                 21, 0, 0, 0.0, 0.0, 0.0, 0.0, <0.0,0.0,0.0>,
                                 9] + params);
       }
       else
       llSetPrimitiveParams([21, 1, 0, 0.0, 0.0, 0.0, 0.0, <0.0,0.0,0.0>,
                             21, 0, 0, 0.0, 0.0, 0.0, 0.0, <0.0,0.0,0.0>]);
   }
   changed(integer change)
   {
       if(change & CHANGED_REGION_START)
       llResetScript();
   }
   on_rez(integer param)
   {
       llResetScript();
   }
   collision_start(integer nd)
   {
       llResetScript();
   }

}</lsl>