Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

On/Off for particle system

Carl Greenstein
The Stickmans Alt
Join date: 14 Dec 2003
Posts: 15
08-21-2005 07:47
I've been working on a object that spits out particles on touch and thanks to cut and paste of various scripts, I've got a working model. Problem is, now I want a command activated one, since the particle emitting prim is being placed where no one could click it if they wanted to. I can't seem to find out any info on how to do this by the forums and I am a complete scripting moron. Only way I get anything to work is if its heavily commented and already made. :P If anyone could post up an example of how to turn on/off my particle system by a command (in a different channel than 0 of course) I would feel much less like throwing my computer out the window. :cool:

Heres my code so far:

CODE
// Particle Script 0.3
// Created by Ama Omega
// 10-10-2003

// Mask Flags - set to TRUE to enable
integer glow = FALSE; // Make the particles glow
integer bounce = FALSE; // Make particles bounce on Z plan of object
integer interpColor = FALSE; // Go from start to end color
integer interpSize = TRUE; // Go from start to end size
integer wind = FALSE; // Particles effected by wind
integer followSource = FALSE; // Particles follow the source
integer followVel = TRUE; // Particles turn to velocity direction

// Choose a pattern from the following:
// PSYS_SRC_PATTERN_EXPLODE
// PSYS_SRC_PATTERN_DROP
// PSYS_SRC_PATTERN_ANGLE_CONE_EMPTY
// PSYS_SRC_PATTERN_ANGLE_CONE
// PSYS_SRC_PATTERN_ANGLE
integer pattern = PSYS_SRC_PATTERN_ANGLE;

// Select a target for particles to go towards
// "" for no target, "owner" will follow object owner
// and "self" will target this object
// or put the key of an object for particles to go to
key target = "";

// Particle paramaters
float age = 1.3; // Life of each particle
float maxSpeed = 2; // Max speed each particle is spit out at
float minSpeed = 1; // Min speed each particle is spit out at
string texture = "grassclippings"; // Texture used for particles
float startAlpha = .3; // Start alpha (transparency) value
float endAlpha = 0; // End alpha (transparency) value
vector startColor = <35,100,15>; // Start color of particles <R,G,B>
vector endColor = <255,255,255>; // End color of particles <R,G,B> (if interpColor == TRUE)
vector startSize = <.3,.3,.3>; // Start size of particles
vector endSize = <1,1,1>; // End size of particles (if interpSize == TRUE)
vector push = <0,0,.1>; // Force pushed on particles

// System paramaters
float rate = .1; // How fast (rate) to emit particles
float radius = 1; // Radius to emit particles for BURST pattern
integer count = 6; // How many particles to emit per BURST
float outerAngle = 0; // Outer angle for all ANGLE patterns
float innerAngle = 0; // Inner angle for all ANGLE patterns
vector omega = <0,0,0>; // Rotation of ANGLE patterns around the source
float life = 0; // Life in seconds for the system to make particles

// Script variables
integer flags;

updateParticles()
{
flags = 0;
if (target == "owner") target = llGetOwner();
if (target == "self") target = llGetKey();
if (glow) flags = flags | PSYS_PART_EMISSIVE_MASK;
if (bounce) flags = flags | PSYS_PART_BOUNCE_MASK;
if (interpColor) flags = flags | PSYS_PART_INTERP_COLOR_MASK;
if (interpSize) flags = flags | PSYS_PART_INTERP_SCALE_MASK;
if (wind) flags = flags | PSYS_PART_WIND_MASK;
if (followSource) flags = flags | PSYS_PART_FOLLOW_SRC_MASK;
if (followVel) flags = flags | PSYS_PART_FOLLOW_VELOCITY_MASK;
if (target != "") flags = flags | PSYS_PART_TARGET_POS_MASK;

llParticleSystem([ PSYS_PART_MAX_AGE,age,
PSYS_PART_FLAGS,flags,
PSYS_PART_START_COLOR, startColor,
PSYS_PART_END_COLOR, endColor,
PSYS_PART_START_SCALE,startSize,
PSYS_PART_END_SCALE,endSize,
PSYS_SRC_PATTERN, pattern,
PSYS_SRC_BURST_RATE,rate,
PSYS_SRC_ACCEL, push,
PSYS_SRC_BURST_PART_COUNT,count,
PSYS_SRC_BURST_RADIUS,radius,
PSYS_SRC_BURST_SPEED_MIN,minSpeed,
PSYS_SRC_BURST_SPEED_MAX,maxSpeed,
PSYS_SRC_TARGET_KEY,target,
PSYS_SRC_INNERANGLE,innerAngle,
PSYS_SRC_OUTERANGLE,outerAngle,
PSYS_SRC_OMEGA, omega,
PSYS_SRC_MAX_AGE, life,
PSYS_SRC_TEXTURE, texture,
PSYS_PART_START_ALPHA, startAlpha,
PSYS_PART_END_ALPHA, endAlpha
]);
}

default
{
state_entry()
{
updateParticles();
}

touch_start( integer num ) //Turn particles off when touched
{
state off; //Switch to the off state
}
}

state off
{
state_entry()
{
llParticleSystem([]); //Stop making particles
}

touch_start( integer num ) //Turn particles back on when touched
{
state default;
}
}
Ushuaia Tokugawa
Nobody of Consequence
Join date: 22 Mar 2005
Posts: 268
08-21-2005 08:24
remove your default state and off state and replace them with this:

CODE

integer channel = 123;
string offMessage = "particles off";
string onMessage = "particles on";

default
{
state_entry()
{
updateParticles();

llListen(channel, "", llGetOwner(), offMessage);
}

listen(integer channel, string name, key id, string message)
{
state off; //Switch to the off state
}
}

state off
{
state_entry()
{
llParticleSystem([]); //Stop making particles

llListen(channel, "", llGetOwner(), onMessage);
}

listen(integer channel, string name, key id, string message)
{
state default;
}
}
_____________________
Carl Greenstein
The Stickmans Alt
Join date: 14 Dec 2003
Posts: 15
08-21-2005 08:35
Error was taken care of, thanks for the help!
Keknehv Psaltery
Hacker
Join date: 11 Apr 2005
Posts: 1,185
08-21-2005 13:15
Personally, I would recommend my own particle script... It's very efficient, and is encapsulated in one function.

Keknehv's Particle Script
Morphy Mousehold
Registered User
Join date: 11 May 2005
Posts: 5
08-25-2005 16:11
I've noticed that if the particles are on and I delete the script from the prim that contained the click-on/off particle script without turning them off... they never turn off. They keep spitting particles forever. Ever rezzed version spitting out particles forever. Augh!

Considering this is a complex object with 40 or so linked prims, do I have to rebuild from scratch or put a copy of your click-on/off particle script on every prim and manually turn them all off?
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
08-25-2005 16:54
From: Morphy Mousehold
I've noticed that if the particles are on and I delete the script from the prim that contained the click-on/off particle script without turning them off... they never turn off. They keep spitting particles forever. Ever rezzed version spitting out particles forever. Augh!

Considering this is a complex object with 40 or so linked prims, do I have to rebuild from scratch or put a copy of your click-on/off particle script on every prim and manually turn them all off?
I've sent you the flollowing useful script for killing particles:

CODE
default
{
state_entry()
{
llParticleSystem([ ]);
llSleep(0.1);
llRemoveInventory(llGetScriptName());
}
}
_____________________
Lucas Sion
Registered User
Join date: 25 Aug 2005
Posts: 16
Particles For Anyone
08-26-2005 16:47
So to make it so anyone can say the command, would you just delete llGetOwner?\
or is there a separate command string for everyone?
a lost user
Join date: ?
Posts: ?
08-26-2005 19:16
yes just remove llGetOwner() from the llListen() event-declaration (ie. the configuration of the listen event).
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
08-26-2005 19:22
Not remove, but replace with the constant NULL_KEY.
_____________________
a lost user
Join date: ?
Posts: ?
08-26-2005 19:29
yes my bad :P

actually "" is better than NULL_KEY.. uses less memory

eg. llListen(channel,"","","";); uses less memory than llListen(channel,NULL_KEY,"","";);

Ok.. not much more memory but "" is quicker to type as well :P
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
08-26-2005 19:34
NULL_KEY != ""

Keep that in mind when you choose which to use.

EDIT: I best explain: I mean that in situations where you need to look for NULL_KEY you can't replace it with an empty string. The empty string works just dandy in this case, I just have the habit of using NULL_KEY. :)
_____________________