Firepit help with Turning on/off.
|
|
Claire Silverspar
Pokes Badgers With Spoons
Join date: 31 Oct 2007
Posts: 5,375
|
08-13-2008 13:04
I've never scripted anything before, but I'm making a firepit, and need to: a) be able to turn the fire off and on, preferably by click or chat command and b) Have a crackling noise that will turn off at the same time as the flames. I have the sound already. I have 3 flames, so I'm thinking that chat command will probably be easier to turn the sound off at the same time. Are there any scripts that I can use, or buy? Or how would I begin to write it? Any help would be greatly appreciated. Thanks  Claire xx
_____________________
 I'll miss this damn place. I'll be over at SCII after the end has come.
|
|
Wulfric Chevalier
Give me a Fish!!!!
Join date: 22 Dec 2006
Posts: 947
|
08-13-2008 13:07
The autoscriipt site should be able to make you scripts to do that: http://www.3greeneggs.com/autoscript/You might need to combine two scripts to do the sound and the flames - I have no idea about scripting either  .
|
|
Claire Silverspar
Pokes Badgers With Spoons
Join date: 31 Oct 2007
Posts: 5,375
|
08-13-2008 13:40
I found a script to turn the fire on and off, and to turn the sound on, and to keep playing, but how do I add into the script so when someone says "fire off" The sound stops. To play the sound I have: From: someone // This script was auto-generated by Ann Enigma's script autogenerator // available at http://www.3greeneggs.com/autoscript/// Note: You will need to copy both this script and a sound into your object default { state_entry() { llListen(0,"", NULL_KEY, ""  ; } listen(integer channel, string name, key id, string message) { if (message == "light"  { llLoopSound(llGetInventoryName(INVENTORY_SOUND,0),1); } } }
_____________________
 I'll miss this damn place. I'll be over at SCII after the end has come.
|
|
Cynebald Ceawlin
Scripting the night away
Join date: 15 Apr 2007
Posts: 30
|
08-13-2008 13:51
Haven't played w/ it much, but I'd say it's pretty likely the autoscript site would indeed be a great place to start. Other than that, you can find example scripts to show you how to handle touch events, set up chat listeners, use llLoopSound(), and a couple of different ways to handle turning the flames "on" and "off" (things like simply turning them transparent for "off" via llSetTexture() or llSetAlpha(), or a more complicated approach that would let you rez/derez them). A GREAT resource for learning to script can be found on the LSL Wiki ( http://lslwiki.net/lslwiki/wakka.php?wakka=LSLTutorials); they've also got a good library of example scripts over there ( http://lslwiki.net/lslwiki/wakka.php?wakka=examples) Something to watch out for -- if you put the same sound in all three flame prims, you can end up with some rather unpleasant audio effects as there is no way to guarantee that the sounds will play in synch with each other; if they're just a little bit out of phase it can sound rather hideous. Better to just put the sound in one prim (e.g. in a log) if you've only got one sound file, or put in different sounds in different prims to create a much nicer layered sound effect.
|
|
Cynebald Ceawlin
Scripting the night away
Join date: 15 Apr 2007
Posts: 30
|
08-13-2008 13:58
From: Claire Silverspar I found a script to turn the fire on and off, and to turn the sound on, and to keep playing, but how do I add into the script so when someone says "fire off" The sound stops. To play the sound I have: // This script was auto-generated by Ann Enigma's script autogenerator // available at http://www.3greeneggs.com/autoscript/ // Note: You will need to copy both this script and a sound into your object default { state_entry() { llListen(0,"", NULL_KEY, ""  ; } listen(integer channel, string name, key id, string message) { if (message == "light"  { llLoopSound(llGetInventoryName(INVENTORY_SOUND,0), 1); } else if (message == "fire off"  { llStopSound(); } } A lag-friendly modification you should think about making to this would be to have it listen on a private chat channel rather than the open chat (channel 0) -- you can do this by changing the line that starts the listener to (for example) llListen(1,"", NULL_KEY, ""  ;. Then to control the fire, an avatar would type "/1 light" or "/1 fire off". (You can use any positive integer up to 2147483646 for the channel). This prevents your listen handler from having to process everything any avatar says near your fire pit to see if it should turn on or off, saving a fair amount of load on the sim. 
|
|
Claire Silverspar
Pokes Badgers With Spoons
Join date: 31 Oct 2007
Posts: 5,375
|
08-13-2008 14:09
Thanks guys, managed to get it sorted out.  My first scripted item! wooo! 
_____________________
 I'll miss this damn place. I'll be over at SCII after the end has come.
|
|
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
|
08-13-2008 14:30
I would do it about like this, just to break everything up and make it easy to read and maintain (assuming your are doing it with particles and not glow/full-bright or whatever): (Note: Hasn't been compiled or tested; may need a couple minor syntax fixes--OBVIOUSLY for the particle and sound calls.) integer CHANNEL = 33; string FIRE_ON_CHAT = "fire on"; string FIRE_OFF_CHAT = "fire off";
integer effectsAreOn = FALSE;
particlesOn() { llParticleSystem([...]); }
particlesOff() { llParticleSystem([]); }
soundOn() { llLoopSound(...); }
soundOff() { llStopSound(); }
effectsOn() { particlesOn(); soundOn(); effectsAreOn = TRUE; }
effectsOff() { particlesOff(); soundOff(); effectsAreOn = FALSE; }
toggleEffects() { if (effectsAreOn) { effectsOff(); } else { effectsOn(); } }
default { state_entry() { effectsOff(); llListen(CHANNEL, "", NULL_KEY, FIRE_ON_CHAT); llListen(CHANNEL, "", NULL_KEY, FIRE_OFF_CHAT); }
touch_start(integer nDetected) { toggleEffects(); }
listen(integer channel, string name, key id, string message) { if (message == FIRE_ON_CHAT) { effectsOn(); } else if (message == FIRE_OFF_CHAT) { effectsOff(); } } }
|