Difference between revisions of "Phantom Child"
Psi Merlin (talk | contribs) (Updated CHANGED_REGION_START references (live as of Server 1.27)) |
m (Replaced <source> with <syntaxhighlight>) |
||
(23 intermediate revisions by 9 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.}} | |||
= 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 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 | 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 [[User:Aeron Kohime|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 == | |||
< | <syntaxhighlight lang="lsl2">//Phantom Child Script by Aeron Kohime | ||
//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 17: | Line 21: | ||
//Reset on collision added by Taff Nouvelle (my stairs kept reverting) | //Reset on collision added by Taff Nouvelle (my stairs kept reverting) | ||
//Psi Merlin updated CHANGED_REGION_START (live as of Server 1.27) | //Psi Merlin updated CHANGED_REGION_START (live as of Server 1.27) | ||
//New function code added by Taff Nouvelle December 15th. | |||
default { | default { | ||
Line 40: | Line 45: | ||
} | } | ||
} | }</syntaxhighlight> | ||
</ | |||
== Switchable == | |||
Addition to the above script, a switchable version that could be useful for a phantom door. | |||
//Phantom Child Script by Aeron Kohime | <syntaxhighlight 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 54: | 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 | ||
{ | |||
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(); | |||
} | |||
} | |||
</syntaxhighlight> | |||
== 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. | |||
<syntaxhighlight lang="lsl2"> | |||
default | |||
{ | |||
state_entry() | state_entry() | ||
{ | { | ||
llSetLinkPrimitiveParamsFast(LINK_THIS,[ PRIM_PHYSICS_SHAPE_TYPE,PRIM_PHYSICS_SHAPE_NONE]); | |||
} | |||
} | |||
</syntaxhighlight> | |||
== 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. | |||
<syntaxhighlight lang="lsl2">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; | |||
} | } | ||
on_rez(integer | |||
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(); | llResetScript(); | ||
} | |||
} | |||
</syntaxhighlight> | |||
==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]] | |||
<syntaxhighlight lang="lsl2"> | |||
// 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){ | changed (integer vBitChanges){ | ||
Line 88: | Line 280: | ||
} | } | ||
} | } | ||
</ | </syntaxhighlight> | ||
{{LSLC|Library}} | {{LSLC|Library}} | ||
{{LSLC|Examples}} | {{LSLC|Examples}} |
Latest revision as of 13:22, 17 April 2022
LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
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();
}
}
}