Jump to content

Turning On / Off a particle effect based on height above water


Miguelito Shilova
 Share

You are about to reply to a thread that has been inactive for 3229 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I am having a little bit of trouble with a mod to a particle script. The intent is to have the particle turn on when the prim is at or below water level, and off when above water. The existing script uses messaging to turn on and off based on 'start' and 'stop' messages coming from another script, but what I'm trying to do is add a do / while loop when the message is 'start' ...

generalParticleEmitterOn()

{
llParticleSystem([
PSYS_PART_FLAGS , 0
| PSYS_PART_INTERP_COLOR_MASK //Colors fade from start to end
| PSYS_PART_INTERP_SCALE_MASK //Scale fades from beginning to end
| PSYS_PART_FOLLOW_VELOCITY_MASK//Particles are created at the velocity of the emitter

,PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_ANGLE

,PSYS_SRC_TEXTURE, "f622a6dd-e15d-33f9-a7e5-57504926b1d4" //UUID of the desired particle texture, or inventory name
,PSYS_SRC_MAX_AGE, 0.0 //Time, in seconds, for particles to be emitted. 0 = forever
,PSYS_PART_MAX_AGE, 6.0 //Lifetime, in seconds, that a particle lasts. Original Value = 8
,PSYS_SRC_BURST_RATE, 0.0 //How long, in seconds, between each emission
,PSYS_SRC_BURST_PART_COUNT, 20 //Number of particles per emission
,PSYS_SRC_BURST_RADIUS, 0.0 //Radius of emission
,PSYS_SRC_BURST_SPEED_MIN, 0.5 //Minimum speed of an emitted particle
,PSYS_SRC_BURST_SPEED_MAX, 0.5 //Maximum speed of an emitted particle
,PSYS_SRC_ACCEL, <0,0,-0.3> //Acceleration of particles each second
,PSYS_PART_START_COLOR, <1.0,1.0,1.0> //Starting RGB color
,PSYS_PART_END_COLOR, <1.0,1.0,1.0> //Ending RGB color, if INTERP_COLOR_MASK is on
,PSYS_PART_START_ALPHA, 0.5 //Starting transparency, 1 is opaque, 0 is transparent.
,PSYS_PART_END_ALPHA, 0.0 //Ending transparency
,PSYS_PART_START_SCALE, <1.0,1.0,0.0> //Starting particle size
,PSYS_PART_END_SCALE, <2.5,2.5,0.0> //Ending particle size, if INTERP_SCALE_MASK is on
,PSYS_SRC_ANGLE_BEGIN, 60.0* DEG_TO_RAD //Inner angle for ANGLE patterns
,PSYS_SRC_ANGLE_END, 120.0* DEG_TO_RAD//Outer angle for ANGLE patterns
,PSYS_SRC_OMEGA, <0.0,0.0,0.0> //Rotation of ANGLE patterns, similar to llTargetOmega()
]);
}

generalParticleEmitterOff()
{
llParticleSystem([]);
}

default
{
state_entry()
{
generalParticleEmitterOff();

}
link_message(integer sender_num, integer num, string str, key id)
{
vector pos = llGetPos(); //Gets your Current position in world
float water = llWater(<0,0,19>); // Water height in the current Sim
if(str=="stop")
{
generalParticleEmitterOff();
}
if(str=="start")
{
do
{
generalParticleEmitterOn();
}
while (pos.z <= water);
}
}
}

The 'start' and 'stop' appear to work fine, however the do / while isn't recognizing the water height, and not shutting off the effect when the prim is above water. I'm not sure why.

Thanks in advance for the help!

Mig

Link to comment
Share on other sites

I wouldn't use a do..while loop here.

Instead, I would call a fast timer (like 0.2 of a second) and, in it, do something based on this logic

	timer()	{		//float fGround 	= llGround(ZERO_VECTOR);//ground level where I am at the moment -- not needed for this but maybe for other tests		float fWater	= llWater(ZERO_VECTOR);	//water level where I am at the moment		vector myPos	= llGetPos();	//where I am		if(myPos.z<fWater){//my centre is below the water line			//start swimming		}	}
Link to comment
Share on other sites

Thanks for the reply Innula ... I tried placing the timer () routine in the script and I get a syntax error where it is called ...

generalParticleEmitterOn()

{
llParticleSystem([
PSYS_PART_FLAGS , 0
| PSYS_PART_INTERP_COLOR_MASK //Colors fade from start to end
| PSYS_PART_INTERP_SCALE_MASK //Scale fades from beginning to end
| PSYS_PART_FOLLOW_VELOCITY_MASK//Particles are created at the velocity of the emitter

,PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_ANGLE

,PSYS_SRC_TEXTURE, "f622a6dd-e15d-33f9-a7e5-57504926b1d4" //UUID of the desired particle texture, or inventory name
,PSYS_SRC_MAX_AGE, 0.0 //Time, in seconds, for particles to be emitted. 0 = forever
,PSYS_PART_MAX_AGE, 6.0 //Lifetime, in seconds, that a particle lasts. Original Value = 8
,PSYS_SRC_BURST_RATE, 0.0 //How long, in seconds, between each emission
,PSYS_SRC_BURST_PART_COUNT, 20 //Number of particles per emission
,PSYS_SRC_BURST_RADIUS, 0.0 //Radius of emission
,PSYS_SRC_BURST_SPEED_MIN, 0.5 //Minimum speed of an emitted particle
,PSYS_SRC_BURST_SPEED_MAX, 0.5 //Maximum speed of an emitted particle
,PSYS_SRC_ACCEL, <0,0,-0.3> //Acceleration of particles each second
,PSYS_PART_START_COLOR, <1.0,1.0,1.0> //Starting RGB color
,PSYS_PART_END_COLOR, <1.0,1.0,1.0> //Ending RGB color, if INTERP_COLOR_MASK is on
,PSYS_PART_START_ALPHA, 0.5 //Starting transparency, 1 is opaque, 0 is transparent.
,PSYS_PART_END_ALPHA, 0.0 //Ending transparency
,PSYS_PART_START_SCALE, <1.0,1.0,0.0> //Starting particle size
,PSYS_PART_END_SCALE, <2.5,2.5,0.0> //Ending particle size, if INTERP_SCALE_MASK is on
,PSYS_SRC_ANGLE_BEGIN, 60.0* DEG_TO_RAD //Inner angle for ANGLE patterns
,PSYS_SRC_ANGLE_END, 120.0* DEG_TO_RAD//Outer angle for ANGLE patterns
,PSYS_SRC_OMEGA, <0.0,0.0,0.0> //Rotation of ANGLE patterns, similar to llTargetOmega()
]);
}

generalParticleEmitterOff()
{
llParticleSystem([]);
}

default
{
state_entry()
{
generalParticleEmitterOff();
llSetTimerEvent(.2);

}
link_message(integer sender_num, integer num, string str, key id)
{
if(str=="stop")
{
generalParticleEmitterOff();
}
if(str=="start")
{
timer()
{
float fGround = llGround(ZERO_VECTOR);//ground level where I am at the moment
float fWater = llWater(ZERO_VECTOR); //water level where I am at the moment
vector myPos = llGetPos(); //where I am
if(fWater>fGround && myPos.z<fWater)
{
generalParticleEmitterOn();
}
}
}
}
}

Do I have an extra or missing bracket? I went on the presumption that I should call the timer routine after the if statement for when the message was 'start'

Mig

Link to comment
Share on other sites

You don't need the llGround stuff for this particular solution, so I've taken it out.    

The timer event (or event handler, to be pedantic) isn't contained inside another event.   That's where you're going wrong.   When you start at timer event, which you do here in state_entry, you're telling the simulator to execute the block of code inside the timer event every n seconds -- in this case, check every 0.2 seconds if you're above or below the water;   if you're below the water and not already emitting particles, turn the particles on, and if you're above the water and still emitting particles, turn them off.

I don't quite understand what the link message is there for, so I guessed it's to turn the particles on and off independent of whether you're in the water or not.

I didn't bother to reproduce the particle system, but I think this should do it.   If it doesn't and you need to post more code, please use the little post code button on the top of the editor window ( the <>, in between the spoiler icon and  the smiley icon).   It makes code easier to read.

integer AmEmittingParticles = FALSE;default{	state_entry()	{		generalParticleEmitterOff();		AmEmittingParticles = FALSE;		llSetTimerEvent(.2);	}		timer()	{		float fWater = llWater(ZERO_VECTOR); //water level where I am at the moment		vector myPos = llGetPos(); //where I am		if(myPos.z<fWater && AmEmittingParticles == FALSE)		{ //my waist is below the waterline and I am not already emitting particles			generalParticleEmitterOn();			AmEmittingParticles = TRUE;		}		else if (myPos.z>=fWater && AmEmittingParticles == TRUE){			//my waist is above the waterline and I am still emitting particles			generalParticleEmitterOff();			AmEmittingParticles = FALSE;		}	}	link_message(integer sender_num, integer num, string str, key id)	{		if(str=="stop")		{			generalParticleEmitterOff();			AmEmittingParticles = FALSE;		}		else if(str=="start")		{			generalParticleEmitterOn();			AmEmittingParticles = TRUE;		}	}}

 

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3229 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...