Phantom Child
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
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
<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>
Switchable
Addition to the above script, a switchable version that could be 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>
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.
<lsl>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(); }
} </lsl>
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 <lsl> // 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(); } }
} </lsl>