Here is a little script I quickly put together. Its job is to make an entire object (a whole link-set) disappear or appear upon "hearing" a command on a private channel. It also takes "care" of hiding and showing the text above the object (but see details below).
This script is very simple but proves useful for hiding simple things like pose balls. Do not use it however for things more complicated, like a house or a tent, because the mechanism the script uses to make the object disappear will alter the alpha (transparency) setting of all faces of all prims in the object, and will make them fully opaque again when reappearing.
If you plan to have this functionnality on objects with partial transparency on some faces, a way more subtle means to do this is required.
The channel number, as well as the SHOW and HIDE commands are customizable via easy parameters at the start of the script. Due to some limitation, the floating text, if any, to be set above the root prim has to be entered in the script too [Technical note : no apparent way of getting the text in a prim]. Currently the script is limitted to setting only the root prim's text (could be done in a different way but, well...). You can also set the color of said text in the parameters.
A second script (ShowHide control) is designed to be placed in an object (like a cube or a poster) to "toggle" the show and hide commands for objects in range that have the first script. That way, you can make all your poseballs appear or disappear at the same time by touching the control. Its parameters (channel and commands) should be the same as those of the ShowHide script.
One last useful tip : by setting the channel parameter to a negative number, you prevent avatars from issuing a direct command over the chat, and only the control script will be useable.
First, the ShowHide script :
// ShowHide script by Oggy Fink // text to set above the root prim string text="here"; // modify me, use "" for no text vector color=<1.0,1.0,1.0>; // color of the text // modifiable parameters integer channel = 8; // channel number string showcmd="SHOW"; // show command - use uppercase only string hidecmd="HIDE"; // hide command - use uppercase only // do not touch below show() { llSetLinkAlpha(LINK_SET,1.0,ALL_SIDES); llSetText(text,color,1.0); } hide() { llSetLinkAlpha(LINK_SET,0.0,ALL_SIDES); llSetLinkPrimitiveParamsFast(LINK_SET,[PRIM_TEXT,"",color,0.0]); } default { state_entry() { llListen(channel,"",NULL_KEY,""); } listen(integer channel, string name, key id, string message) { string m=llToUpper(llStringTrim(message,STRING_TRIM)); if (m==showcmd) { show(); } else if (m==hidecmd) { hide(); } } }
Then the ShowHide control script :
// www.lsleditor.org by Alphons van der Heijden (SL: Alphons Jano) integer channel=8; // channel number string showtext="Show !"; string hidetext="Hide !"; vector color=<1.0,0.5,0.0>; // color for the floating text :. Use <1.0,1.0,1.0> for white string showcmd="SHOW"; string hidecmd="HIDE"; // do not modify below integer visible=TRUE; default { state_entry() { llSetText(showtext,color,1.0); } touch_start(integer total_number) { if (visible) { llSay(channel,hidecmd); visible=FALSE; llSetText(showtext,color,1.0); } else { llSay(channel,showcmd); visible=TRUE; llSetText(hidetext,color,1.0); } } }
All this is downloadable for free at my marketplace store.
Thank you!! Came in handy!
ReplyDeleteHi Oggy...wondering if you have a show/hide on touch..like as for a tap please?
ReplyDeleteThanks
Fleur Ferris in SL
Hello. If you mean to control one object (the water) by clicking on a separate object (the tap) then you can use the scripts described here: the ShowHide goes into the water and the ShowHide control goes into the tap. This will work if they are separate objects (not linked prims in the same linkset).
DeleteIf you need to do this with linked prims the script has to be modified. Either send me an email (oggy.fink@gmail.com) or an IM, or I'll get back to you in SL soon. Cheers.
Reading again my old scripts :)
DeleteTurns out that what you want (if I understand correctly) is already possible with the ShowHide-Multi script described here : https://oggysscripteditems.blogspot.com/2011/09/showhide-multi-script.html (and free on my MP).
Put the ShowHide-Multi script inside your water prim, and the ShowHide-Multi control inside the tap prim. Make sure that inside the control script the emittype paramater is set to 4 (link_message). Email or IM me if you need assistance.
Thank you so much Oggy...You're awesome...I'm just learning how to do scripting and it's very confusing to me. I am slowly learning though...watching youtube tutorials and secondlife wiki and blogs etc.
ReplyDeleteYou've been VERY helpful...thanks again
Fleur Ferris
P.S. I found out what the problem is not finding me LOL
I'm glad I could help you ... Any question just ask and spread the word :)
DeleteHow would I make them function by owner only without affecting other copies nearby?
ReplyDeleteHello. Not entirely sure to understand what you mean exactly. If you want to make sure the command comes from an object that belongs to the same owner, then checking if the speaker and the object have the same object may do the trick. To do this, right after the line saying
Deletelisten(integer channel, string name, key id, string message) {
add the following line:
if (llGetOwnerKey(id)!=llGetOwner()) return;
This will cause the script to ignore commands coming from object with a different owner.
If you meant you want to "separate" the commands for different objects, the best thing is to change the command channel. In that case just change the "channel" variable (in both scripts) to a different number (not 0).
Hope this helps,
Oggy