Light on/off scripts?
|
|
Squee Harden
Registered User
Join date: 27 May 2008
Posts: 2
|
03-30-2009 15:20
I've been looking around forever and I can't find anything along the lines of a chat-activated light script. I'm sure it can't be as hard as I'm making it. Does anyone know where I could find one or have one made?
|
|
Keira Wells
Blender Sculptor
Join date: 16 Mar 2008
Posts: 2,371
|
03-30-2009 15:39
default { state_entry() { llListen(0, "", "", ""); //Listen for messages on channel 0 (Local chat) } listen(integer channel, string name, key id, string message) { if(llToLower(message)=="light on") //If heard message is 'light on', then { llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <1, 1, 1>, 1.0, 10.0, 0.75]); //Cause prim to emit white light, with a intensity of 1, radius of 10m, and a falloff of .75 meters. } else if(llToLower(message)=="light off") //Else, if heard message is 'light off', then { llSetPrimitiveParams([PRIM_POINT_LIGHT, FALSE, <1, 1, 1>, 1.0, 10.0, 0.75]); //Cause prim to stop/not emit light. } } }
There ya go... should work, I think, but not in world to test it. Commented as to what each function (Basically) does. It may not be the best script for the use, but it should work as you said. Just a basic script for a chat controlled light-source (For the specific prim, not all prims in the object). 'Light on' (Not case sensitive) will turn it on, and 'Light off' will turn it off.
_____________________
Tutorials for Sculpties using Blender! Http://www.youtube.com/user/BlenderSL
|
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
03-30-2009 16:36
You can streamline things a bit by using a single keyword as a toggle to turn the light on or off. By filtering the listen, it will also reduce some demand on the sim. integer light; default { state_entry() { llListen(0,"",NULL_KEY,"clap"); // or whatever keyword you like best light = 0; } listen (integer channel, string name, key id, string message) { if (light == FALSE) { llSetPrimitiveParams([PRIM_POINT_LIGHT, TRUE, <1, 1, 1>, 1.0, 10.0, 0.75]); //Cause prim to emit white light, with a intensity of 1, radius of 10m, and a falloff of .75 meters. light = 1; } else { llSetPrimitiveParams([PRIM_POINT_LIGHT, FALSE, <1, 1, 1>, 1.0, 10.0, 0.75]); //Cause prim to stop/not emit light. light = 0; } } }
I think that ought to work. Unlike Keira's example, the chat message ("clap" in this case) is case-sensitive.
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
03-30-2009 18:20
slightly optimized single message version integer gBooLit;
default{ state_entry(){ //-- pick a channel you like llListen( 42, "", "", "" ); }
listen( integer vIntNull, string vStrNull, key vKeySpeaker, string vStrHeard ){ //-- only responds to owner if (llGetOwner() == vKeySpeaker){ //-- only responds to the word "clap", capitalization, leading/trailing spaces don't matter if ("clap" == llToLower( llStringTrim( vStringHeard, STRING_TRIM ) )){ //-- reverse the lit/dark state gBooLit = !gBooLit; llSetPrimitiveParams( [PRIM_POINT_LIGHT, gBooLit, <1, 1, 1>, 1.0, 10.0, 0.75, PRIM_FULBRIGHT, ALL_SIDES, gBooLit ] ); //-- added full bright for clients not rendering local lights. } } } }
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|
|
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
|
03-30-2009 20:30
You can also use llGetSunDirection() to toggle lights on/off automatically. A couple of things I sell use that technique.
_____________________
My tutes http://www.youtube.com/johanlaurasia
|
|
Keira Wells
Blender Sculptor
Join date: 16 Mar 2008
Posts: 2,371
|
03-30-2009 21:41
From: Johan Laurasia You can also use llGetSunDirection() to toggle lights on/off automatically. A couple of things I sell use that technique. However, doesn't this only detect the 'natural' location of the sun? That is, if you change the time with the World menu, then it won't notice at all, since that's a viewer-side effect while the on/off is server side. So, if you never change the environment settings, and aren't selling/giving away the scripted item, this would be fine, but if you ever change the sun position, or are going to be selling/giving away the item, it's not nearly ideal. Touch or chat, or even timers, in some situations, would usually be preferred, I'd think.
_____________________
Tutorials for Sculpties using Blender! Http://www.youtube.com/user/BlenderSL
|
|
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
|
03-30-2009 22:27
From: Keira Wells However, doesn't this only detect the 'natural' location of the sun? That is, if you change the time with the World menu, then it won't notice at all, since that's a viewer-side effect while the on/off is server side.
So, if you never change the environment settings, and aren't selling/giving away the scripted item, this would be fine, but if you ever change the sun position, or are going to be selling/giving away the item, it's not nearly ideal. Touch or chat, or even timers, in some situations, would usually be preferred, I'd think. Valid points for sure, both are in demand, and yes, llGetSunDirection() detects the position that the server is seeing and does not, (and cannot) detect any forced settings in a client. However, there's cases where automatic lights are desired as well. For example, I sell a copy version of a street lamp that many-a-sim builders have bought from me so they can line the streets with street lamps that work like real ones, and I also have some outdoor lighting, and an ambient sound generator that generates random bird sounds by day, and crickets by night which sell well being automatic.
_____________________
My tutes http://www.youtube.com/johanlaurasia
|
|
Keira Wells
Blender Sculptor
Join date: 16 Mar 2008
Posts: 2,371
|
03-31-2009 08:48
From: Johan Laurasia Valid points for sure, both are in demand, and yes, llGetSunDirection() detects the position that the server is seeing and does not, (and cannot) detect any forced settings in a client. However, there's cases where automatic lights are desired as well. For example, I sell a copy version of a street lamp that many-a-sim builders have bought from me so they can line the streets with street lamps that work like real ones, and I also have some outdoor lighting, and an ambient sound generator that generates random bird sounds by day, and crickets by night which sell well being automatic. I definitely understand that... I just wish there was a function that could detect client settings, even though I know it's not likely to come around. Would be sooo much better XD (I very rarely use the default environment settings, so it's rather odd to see things on at the wrong time)
_____________________
Tutorials for Sculpties using Blender! Http://www.youtube.com/user/BlenderSL
|
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
03-31-2009 14:56
From: Keira Wells I definitely understand that... I just wish there was a function that could detect client settings, even though I know it's not likely to come around.
Would be sooo much better XD (I very rarely use the default environment settings, so it's rather odd to see things on at the wrong time) I don't see that happening, it'd increase either server processing, bandwidth use, or both and require an new mode of script processing, all for something that would end up being a client side effect. (not that it wouldn't be cool, it would)
_____________________
| | . "Cat-Like Typing Detected" | . This post may contain errors in logic, spelling, and | . grammar known to the SL populace to cause confusion | | - Please Use PHP tags when posting scripts/code, Thanks. | - Can't See PHP or URL Tags Correctly? Check Out This Link... | - 
|