Jump to content
  • 0

Timers, sounds and sensors?


Queenship3001
 Share

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

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

Question

Okay, so in my store I have a phantom prim along the length/width of the floor, and when people walk on it, a small invisible prim follows them leaving a trail of sparkley particles. It's just a little effect for my store and the prim deletes as soon as they step off them phantom prim. Now, I thought it would be cool to add some little sound effects to make it cute to go with the particles when people move. However, this has not been easy....

 

The prim that gets rezzed controls the particle engine, and I also want it to trigger the sound, but it also has to move. A and C work but B (sound) doesn't.

 

Here is the script I'm using:

 

integer gCount;
list particle_parameters=[];
list parse_parameters = [];
vector pos;
key avatar_key;
vector water_min;
vector water_max;
integer lh;

ripple()
{
    particle_parameters = [
       PSYS_SRC_TEXTURE, llGetInventoryName(INVENTORY_TEXTURE, 0), 
       PSYS_PART_START_SCALE, <0.1, .1, FALSE>, PSYS_PART_END_SCALE, <.2,.2, FALSE>, 
       PSYS_PART_START_COLOR, <1,1,1>,    PSYS_PART_END_COLOR, <.5,.6,1>, 
       PSYS_PART_START_ALPHA,  (float)0.5,            PSYS_PART_END_ALPHA, (float)0.1,   
       PSYS_SRC_BURST_PART_COUNT, (integer)30, 
       PSYS_SRC_BURST_RATE, (float) 0.6,  
       PSYS_PART_MAX_AGE, (float)3.0, 
       PSYS_SRC_MAX_AGE,(float) 0.0,  
       PSYS_SRC_PATTERN, (integer)4,
       PSYS_SRC_BURST_SPEED_MIN, (float).5,   PSYS_SRC_BURST_SPEED_MAX, (float).5, 
       PSYS_SRC_ANGLE_BEGIN, (float) 0.9*PI,    PSYS_SRC_ANGLE_END, (float)0*PI,  
       PSYS_SRC_ACCEL, <0.0,0.0, 0.0 >,      
       PSYS_PART_FLAGS, (integer)( 0  
                            | PSYS_PART_INTERP_COLOR_MASK   
                            | PSYS_PART_INTERP_SCALE_MASK   
                            | PSYS_PART_EMISSIVE_MASK   
                            | PSYS_PART_FOLLOW_VELOCITY_MASK 
                        ) 
                     
    ];    
}
wave()
{
    particle_parameters = [
       PSYS_SRC_TEXTURE, "*****************"
       PSYS_PART_START_SCALE, <0.3,0.3,0.3>, PSYS_PART_END_SCALE, <0.1,0.1,0.1>, 
       PSYS_PART_START_COLOR, <1,1,1>,    PSYS_PART_END_COLOR, <1,1,1>, 
       PSYS_PART_START_ALPHA,  (float)1,            PSYS_PART_END_ALPHA, (float)0.1,   
     
       PSYS_SRC_BURST_PART_COUNT, (integer)8, 
       PSYS_SRC_BURST_RATE, (float) 0.1,  
       PSYS_PART_MAX_AGE, (float)5, 
       PSYS_SRC_MAX_AGE,(float) 0.0,  
    
       PSYS_SRC_PATTERN, (integer)4,
       PSYS_SRC_BURST_SPEED_MIN, (float)0.05,   PSYS_SRC_BURST_SPEED_MAX, (float)0.1, 
    PSYS_SRC_BURST_RADIUS, 0.0,
       PSYS_SRC_ANGLE_BEGIN, (float) 0,    PSYS_SRC_ANGLE_END, (float)0,  
       PSYS_SRC_OMEGA, <0,0,1>, 
       PSYS_SRC_ACCEL, <0,0,0>,  
      
          
       PSYS_PART_FLAGS, (integer)( 0     
                            | PSYS_PART_INTERP_COLOR_MASK   
                            | PSYS_PART_INTERP_SCALE_MASK   
                            | PSYS_PART_EMISSIVE_MASK   
                            | PSYS_PART_FOLLOW_VELOCITY_MASK
 
                        )                    
    ];    
}
default {
    state_entry()
    {
        ripple();
        llSetScale(<0.010, 0.010, 0.010>);
        llSetColor(<1.0, 1.0, 1.0>, ALL_SIDES);
        llSetAlpha(0, ALL_SIDES);
        llParticleSystem([]);
    }
    on_rez(integer rez_param)
    {
        
        if (rez_param != 0)
        {
            
            lh = llListen(rez_param, "", NULL_KEY, "");
            llParticleSystem( particle_parameters );
            llSetTimerEvent(1.8);
        }
        else
        {
            llSetScale(<1.0, 1.0, 1.0>);
            llSetColor(<1.0, 1.0, 1.0>, ALL_SIDES);
            llSetAlpha(1, ALL_SIDES);            
        }
    }
    listen (integer ch, string name, key id, string msg)
    {        
        llListenRemove(lh);
        parse_parameters = llParseString2List(msg, ["##"], [""]);
        avatar_key = (key)llList2String(parse_parameters, 0);
        water_min = (vector)llList2String(parse_parameters, 1);
        water_max = (vector)llList2String(parse_parameters, 2);
        llSensorRepeat("", avatar_key, AGENT, 10.0, PI, 0.1);
        wave();
    }
    sensor(integer num_detected) 
    {
        pos = llDetectedPos(0);
        if (llVecDist(<pos.x, pos.y, water_max.z>, llGetPos()) > 0.1)
        {
            if (pos.x > water_min.x &&
                pos.y > water_min.y &&
                pos.x < water_max.x &&
                pos.y < water_max.y &&
                pos.z > (water_min.z - 0.5) &&
                pos.z < (water_max.z + 0.5))
            {
                    llSetLinkPrimitiveParamsFast(0, [PRIM_POSITION, <pos.x, pos.y, water_max.z>]);
                    llParticleSystem( particle_parameters );
                    llSetTimerEvent(0.8);
            }
            else 
                llDie();
        }
    }  
    no_sensor()
    {
        llDie();
    }
    timer()
    {
        llSetTimerEvent(0.0);
        llParticleSystem([]);
        if (gCount%3 == 0)
        {
            llPlaySound(llGetInventoryName(INVENTORY_SOUND,0), 1.0);
        }

        else if (gCount%3 == 1)
        {
            llPlaySound(llGetInventoryName(INVENTORY_SOUND,1), 1.0);
        }

        else if (gCount%3 == 2)
        {
            llPlaySound(llGetInventoryName(INVENTORY_SOUND,2), 1.0);
        }
    }        
}

 Now I've tried a few things.

Initially I was using llTriggerSound under the "sensor" section, so it would play the sound when the prim and avatar moved. The initial sound was too long and was spammed pretty bad, so I figured I'd need a timer and shorter sounds to play at intervals, so I found: http://community.secondlife.com/t5/Scripting/One-after-the-play-from-several-sound/td-p/499736

But, I needed it to be under the sensor area still, and so far as I know, I can't make a timer event in nother event (despite how much I want it to >.>). So I made the counter and put all the stuff I needed to in a new argument within the argument containing "llSetLinkPrimitiveParamsFast".

 

That ALMOST worked, but the counter wasn't so once again, the 3 short audio files I had were being smashed together and played as one. (several retries by editing the counter and even adding "float gap = 0.2" also failed)

So as a final effort that I knew would fail but decided to do anyway, was to put everything under that last part in the timer event (it was already there to end the script). And, like I thought it would, the sound only played when the prim stopped moving.

 

SO! How do I get my sound(s) to play properly under the "Sensor" event where I need them to? Any ideas?

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

You don't.  You're doing it a logical way already.... almost.  You can trigger the first sound in the sensor event, but the other two will have to wait and be triggered in the timer event.  To do that, initiate the counter and make the call to llSetTimerEvent in your sensor event.  Then turn the timer OFF when gCount == 2.

BTW, right now gCount may or may not be doing what you expect.  Instead of using gCount%2 or whatever, you'll get more reliable results if you reset gCount to zero in the sensor event and then just increment it by 1 each time the timer fires.

As Amethyst says, this is a good question for the LSL Scripting forum.  Try there next time.  :)

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3546 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...