Jump to content

Particle Color Changer


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

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

Recommended Posts

Hi, I'm looking for some help with my particles at the moment. I've created a HUD that can tell an object with a particle system to turn on and off, but I'm stumped on how to get my particle's color to change. I've created a dialog box that gives options for some basic colors that when clicked, sends a message on a chat channel. Pretty basic stuff there. The only problem I'm running into is actually getting those messages to tell my particle script to do something. That something is to obviously change the particle's colors. Any help on this would be greatly appreciated. Thanks in advance for helping.
Link to post
Share on other sites

Particle color is determined by the two parameters PSYS_PART_START_COLOR and PSYS_PART_END_COLOR.  If you want to change them in your script, trigger your llParticleSystem command again with different vectors for those two parameters.  Treat it like toggling a light switch.  Just toggle between colors instead of off and on.

Link to post
Share on other sites

In addition to having to call llParticleSystem() again each time you want to change something ...

Do you want the particles to change colour during their lifetime? If so you specify a different colour for the start and end settings (per Rolig's post) and also set PSYS_PART_INTERP_COLOR_MASK in the PSYS_PART_FLAGS

Link to post
Share on other sites

I'm not looking for them to change color in their lifetime as a gradient. I want them to change color altogether. I currently own the Porgan 1800. I can choose a color from the color swatches on the Porgan, and the particle display will change to that color. I'm basically trying to get that kind of setup except with a HUD with basic color options.

Link to post
Share on other sites

After some though, I'm guessing a simpler way to do this is to have different particle systems in one script or multiple particle system scripts in an object's contents. Then I would have a script that would tell each of them to turn on and off based on what color I choose from the dialog box.

Link to post
Share on other sites

The 'simpler' way is to have parameters that you adjust from the HUD then call llParticleSystem() again with (all) the updated values.  Would you really want a different set of fixed, pre-written parameters/functions for each colour option?  And each speed option?  And each cone, bright, wind ....

Link to post
Share on other sites

It's much easier and a much better use of resources to do the switching in a single script.  Heck, all you have to do is define a variable to carry the color vector for your particles and put that variable into the llParticleSystem list.  Then put llParticleSystem into a user defined function and call it with a different value of your color vector each time you want to change particle colors.

 

particle(vector NewColor){    llParticleSystem([  // Your huge list of parameters goes here, including        PSYS_PART_START_COLOR,NewColor,PSYS_PART_END_COLOR,NewColor ]);}integer gON;integer gChan;integer gLisn;default{    state_entry()    {        gChan = (integer)("0xF" + llGetSubString(llGetKey(),0,6));    }    touch (integer num)    {        if(!gON)        {            gLisn = llListen(gChan,"","","");            llDialog(llDetectedKey(0),"What color would you like?",["Red","Green","Blue"],gChan);        }        else        {            llParticleSystem([]};        }        gON = !gON;    }    listen(integer channel, string name, key id, string msg)    {        llListenRemove(gLisn);        vector color;        if(msg == "Red")        {            color = <1.0,0.0,0.0>;        }        else if (msg == "Green")        {            color = <0.0,1.0,0.0>;        }        else if (color == "Blue")        {            color = <0.0,0.0,1.0>;        }        particle(color);    }}

 

 

Link to post
Share on other sites

I wrote the script below to change weapon particle effect colors.  It triggers on the change of color of the prim in which it resides.   So, you can set the color using the SL color picker, and the exact color vector will be sent region wide to a receiver.  Then, you can pass the color vector to your particle script as discussed above.    I also integrated this script with a menu system that had nine preset colors. as well.  But, this script will give you over 16,500,000 colors.

Hope you find this useful:

 

vector color=<1.0,1.0,1.0>;
integer CHANNEL;  //Channel for sending  color vector
key owner;
 
//This script relays the color of face 0 of this prim to a receiver anywhere in the same region
default
{
    state_entry()
    {
        owner=llGetOwner();
        color=llGetColor(0);
       
    }
    link_message( integer sender_num, integer num, string str, key id )
    {
        if (str=="command codes") //This is the channel used by the receiver
        {
            CHANNEL=num;
            llListen(CHANNEL,"","","");
            llMessageLinked(LINK_SET,96, (string)color,"");
        }
    }
    changed (integer type)
    {
        if (type & CHANGED_COLOR)
        {
            color=llGetColor(0);
            if(CHANNEL!=0)
            {
                llRegionSay(CHANNEL, "/weapon "+(string)color);
                llMessageLinked(LINK_SET, 96, (string)color,"");
            }
        }
    }
    listen (integer channel, string name, key id, string message)
    {//If colors are changed by the menu system on the ship, we update the color of our HUD button accordingly
        if (channel==CHANNEL && llGetOwnerKey(id) == owner && llGetSubString(message, 0, 6)=="/weapon")
        {
            color=(vector)llGetSubString(message, 8, -1);
            llSetColor(color, 0);
        }
    }
}

Link to post
Share on other sites
  • 8 years later...
On 9/27/2011 at 9:37 PM, Rolig Loon said:

It's much easier and a much better use of resources to do the switching in a single script.  Heck, all you have to do is define a variable to carry the color vector for your particles and put that variable into the llParticleSystem list.  Then put llParticleSystem into a user defined function and call it with a different value of your color vector each time you want to change particle colors.

 


particle(vector NewColor){    llParticleSystem([  // Your huge list of parameters goes here, including        PSYS_PART_START_COLOR,NewColor,PSYS_PART_END_COLOR,NewColor ]);}integer gON;integer gChan;integer gLisn;default{    state_entry()    {        gChan = (integer)("0xF" + llGetSubString(llGetKey(),0,6));    }    touch (integer num)    {        if(!gON)        {            gLisn = llListen(gChan,"","","");            llDialog(llDetectedKey(0),"What color would you like?",["Red","Green","Blue"],gChan);        }        else        {            llParticleSystem([]};        }        gON = !gON;    }    listen(integer channel, string name, key id, string msg)    {        llListenRemove(gLisn);        vector color;        if(msg == "Red")        {            color = <1.0,0.0,0.0>;        }        else if (msg == "Green")        {            color = <0.0,1.0,0.0>;        }        else if (color == "Blue")        {            color = <0.0,0.0,1.0>;        }        particle(color);    }}

Hello Rolig! :D

So i made a script that triggers the particles when i walk, which works well.

Now i am trying to control the color by a HUD but the Script gives me missmatch of type or number of arguments

when i use this:

    control(key owner, integer level, integer edge)
    {

        if (level & (CONTROL_FWD | CONTROL_BACK))
        {
            particle();
        llSetTimerEvent(0.5);
        }

i don't really understand why since the particle is mentioned in the beginning with

particle(vector NewColor){ llParticleSystem([

Link to post
Share on other sites
9 hours ago, marcin1995 Sharple said:

            particle();

 i don't really understand why since the particle is mentioned in the beginning with

particle(vector NewColor){ llParticleSystem([

the particle() function needs a vector value passed in the parameter: (vector NewColor)

in your OP script you defined a global variable: vector color  So pass this vector as the parameter

particle(color);

Link to post
Share on other sites
8 hours ago, Mollymews said:

the particle() function needs a vector value passed in the parameter: (vector NewColor)

in your OP script you defined a global variable: vector color  So pass this vector as the parameter

particle(color);

I forgot to mention it. I already tried particle(color); and just for fun particle(NewColor); and it says name not defined within scope

Link to post
Share on other sites
4 hours ago, marcin1995 Sharple said:

I forgot to mention it. I already tried particle(color); and just for fun particle(NewColor); and it says name not defined within scope

is there a function particle() in your script ?

  • Like 1
Link to post
Share on other sites
On 5/2/2020 at 10:47 PM, Mollymews said:

is there a function particle() in your script ?

Sorry i had no internet for a few days.

So this is

 

 


integer particleTriggered = 0;

particle(vector NewColor){    

llParticleSystem([             PSYS_PART_FLAGS,( 0
                |PSYS_PART_INTERP_COLOR_MASK
                |PSYS_PART_INTERP_SCALE_MASK
                |PSYS_PART_WIND_MASK

                |PSYS_PART_EMISSIVE_MASK ),
            PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_EXPLODE ,
            PSYS_PART_START_ALPHA,0.6,
            PSYS_PART_END_ALPHA,0,
            PSYS_PART_START_COLOR,NewColor ,
            PSYS_PART_END_COLOR,NewColor ,
            PSYS_PART_START_SCALE,<0.859,1.970,0>,
            PSYS_PART_END_SCALE,<0.777,1.780,0>,
            PSYS_PART_MAX_AGE,0.5,
            PSYS_SRC_MAX_AGE,0.0,
            PSYS_SRC_ACCEL,<0,0,0.0>,
            PSYS_SRC_BURST_PART_COUNT,1,
            PSYS_SRC_BURST_RADIUS,0,
            PSYS_SRC_BURST_RATE,0.05,
            PSYS_SRC_BURST_SPEED_MIN,0,
            PSYS_SRC_BURST_SPEED_MAX,0.0078125,
            PSYS_SRC_ANGLE_BEGIN,0,
            PSYS_SRC_ANGLE_END,3.125,
            PSYS_SRC_OMEGA,<0,0,0>,
            PSYS_SRC_TEXTURE, (key)"textureuuid",
            PSYS_SRC_TARGET_KEY, (key)"00000000-0000-0000-0000-000000000000"
         ]); }
integer gON;
integer gChan;
integer gLisn;

 

stopParticle()
{
    llLinkParticleSystem(LINK_SET,[]);
}

default
{
    state_entry()    {        
    gChan =  (integer)("0xF" + llGetSubString(llGetOwner(),0,6))+11;
    gLisn = llListen(gChan,"","","");
    gON = !gON;    }
    run_time_permissions(integer perm)
    {
        if (perm)
        {
                llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_ROT_LEFT | CONTROL_LEFT | CONTROL_RIGHT | CONTROL_ROT_RIGHT, TRUE, TRUE);
        }
    }
    attach(key on)
    {
        if (on != NULL_KEY)
        {
            integer perm = llGetPermissions();
            stopParticle();
            gLisn = llListen(gChan,"","","");
            
            if (perm != (PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION))
            {
                llRequestPermissions(on, PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION);
                stopParticle();
                gLisn = llListen(gChan,"","","");
            }
            else
            {
                llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_ROT_LEFT | CONTROL_LEFT | CONTROL_RIGHT | CONTROL_ROT_RIGHT, TRUE, TRUE);
                stopParticle();
                gLisn = llListen(gChan,"","","");
            }
            
        }
        else
        {
        stopParticle();
        gLisn = llListen(gChan,"","","");;
        }
    }
    
   
    control(key owner, integer level, integer edge)
    {

        if (level & (CONTROL_FWD | CONTROL_BACK))
        {
            particle();
        llSetTimerEvent(0.5);
        }
        else if (edge & (CONTROL_RIGHT | CONTROL_ROT_RIGHT))
        {
            particle();
        llSetTimerEvent(0.00);
        }
        else if (edge & (CONTROL_LEFT | CONTROL_ROT_LEFT))
        {
            stopParticle();
        llSetTimerEvent(0.00);
        }

    }
        listen(integer channel, string name, key id, string msg)         {        
       
        vector color;        
            if(msg == "Red")        
            {            
                color = <1.0,0.0,0.0>;        
            }        
            else if (msg == "Green")        
            {            
                color = <0.0,1.0,0.0>;        
            }        
            else if (msg == "Blue")        
            {            
                color = <0.0,0.0,1.0>;        
            }        
            else if (msg == "Yellow")        
            {            
                color = <1.0,1.0,0.0>;        
            }        
            else if (msg == "Pink")        
            {            
                color = <0.9,0.14,0.9>;        
            }        
            else if (msg == "Purple")        
            {            
                color = <0.7,0.0,1.0>;        
            }        
            else if (msg == "White")        
            {            
                color = <1.0,1.0,1.0>;        
            }        
            else if (msg == "Black")        
            {            
                color = <0.0,0.0,0.0>;        
            }        
            else if (msg == "Grey")        
            {            
                color = <0.5,0.5,0.5>;        
            }        
            particle(color);    
            }
    timer()
    {
        particleTriggered = 0;
        stopParticle();
    }
}

 

Sorry if thats a bit messy, i am still a noob xD

So i also tried to use "particleTriggered = 1;" instead of "particle();" but it also doesnt work. Same for "gON = !gON;"

And i am not sure about the gLisn, i pasted it on every if or else to make sure that it always accepts a color change.

The working version without color changing option is this one:

 


integer particleTriggered = 0;
particle()
{


{

    {
        llParticleSystem([
            PSYS_PART_FLAGS,( 0
                |PSYS_PART_INTERP_COLOR_MASK
                |PSYS_PART_INTERP_SCALE_MASK
                |PSYS_PART_WIND_MASK

                |PSYS_PART_EMISSIVE_MASK ),
            PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_EXPLODE ,
            PSYS_PART_START_ALPHA,0.6,
            PSYS_PART_END_ALPHA,0,
            PSYS_PART_START_COLOR,<1.0,0.2,0.2> ,
            PSYS_PART_END_COLOR,<1,0.4,0.4> ,
            PSYS_PART_START_SCALE,<0.960,2.2,0>,
            PSYS_PART_END_SCALE,<0.894,2.048,0>,
            PSYS_PART_MAX_AGE,0.5,
            PSYS_SRC_MAX_AGE,0.0,
            PSYS_SRC_ACCEL,<0,0,0.0>,
            PSYS_SRC_BURST_PART_COUNT,1,
            PSYS_SRC_BURST_RADIUS,0,
            PSYS_SRC_BURST_RATE,0.05,
            PSYS_SRC_BURST_SPEED_MIN,0,
            PSYS_SRC_BURST_SPEED_MAX,0.0078125,
            PSYS_SRC_ANGLE_BEGIN,0,
            PSYS_SRC_ANGLE_END,3.125,
            PSYS_SRC_OMEGA,<0,0,0>,
            PSYS_SRC_TEXTURE, (key)"textureuuid",
            PSYS_SRC_TARGET_KEY, (key)"00000000-0000-0000-0000-000000000000"
         ]);
    }
}

}

stopParticle()
{
    llLinkParticleSystem(LINK_SET,[]);
}

default
{
    run_time_permissions(integer perm)
    {
        if (perm)
        {
                llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_ROT_LEFT | CONTROL_LEFT | CONTROL_RIGHT | CONTROL_ROT_RIGHT, TRUE, TRUE);
        }
    }
    attach(key on)
    {
        if (on != NULL_KEY)
        {
            integer perm = llGetPermissions();
            stopParticle();
            llListen(0,"", NULL_KEY,"");
            
            if (perm != (PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION))
            {
                llRequestPermissions(on, PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION);
                stopParticle();
                llListen(0,"", NULL_KEY,"");
            }
            else
            {
                llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_ROT_LEFT | CONTROL_LEFT | CONTROL_RIGHT | CONTROL_ROT_RIGHT, TRUE, TRUE);
                stopParticle();
                llListen(0,"", NULL_KEY,"");
            }
            
        }
        else
        {
        stopParticle();
        llListen(0,"", NULL_KEY,"");
        }
    }
    
   
    control(key owner, integer level, integer edge)
    {

        if (level & (CONTROL_FWD | CONTROL_BACK))
        {
            particle();
        llSetTimerEvent(0.5);
        }
        else if (edge & (CONTROL_RIGHT | CONTROL_ROT_RIGHT))
        {
            stopParticle();
        llSetTimerEvent(0.00);
        }
        else if (edge & (CONTROL_LEFT | CONTROL_ROT_LEFT))
        {
            stopParticle();
        llSetTimerEvent(0.00);
        }

    }
    timer()
    {
        particleTriggered = 0;
        stopParticle();
    }
}

 

Link to post
Share on other sites

Okay i tried it now differently with changing the prims color instead of the particle itself.

I get no errors but also the particles wont trigger...

 


integer particleTriggered = 0;

particle()
{


{

    {
llParticleSystem([             PSYS_PART_FLAGS,( 0
                |PSYS_PART_INTERP_COLOR_MASK
                |PSYS_PART_INTERP_SCALE_MASK
                |PSYS_PART_WIND_MASK

                |PSYS_PART_EMISSIVE_MASK ),
            PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_EXPLODE ,
            PSYS_PART_START_ALPHA,0.6,
            PSYS_PART_END_ALPHA,0,
            PSYS_PART_START_COLOR,llGetColor(0) ,
            PSYS_PART_END_COLOR,llGetColor(0) ,
            PSYS_PART_START_SCALE,<0.859,1.970,0>,
            PSYS_PART_END_SCALE,<0.777,1.780,0>,
            PSYS_PART_MAX_AGE,0.5,
            PSYS_SRC_MAX_AGE,0.0,
            PSYS_SRC_ACCEL,<0,0,0.0>,
            PSYS_SRC_BURST_PART_COUNT,1,
            PSYS_SRC_BURST_RADIUS,0,
            PSYS_SRC_BURST_RATE,0.05,
            PSYS_SRC_BURST_SPEED_MIN,0,
            PSYS_SRC_BURST_SPEED_MAX,0.0078125,
            PSYS_SRC_ANGLE_BEGIN,0,
            PSYS_SRC_ANGLE_END,3.125,
            PSYS_SRC_OMEGA,<0,0,0>,
            PSYS_SRC_TEXTURE, (key)"textureuuid",
            PSYS_SRC_TARGET_KEY, (key)"00000000-0000-0000-0000-000000000000"
         ]);     }
}

}
integer gON;
integer gChan;
integer gLisn;

 

stopParticle()
{
    llLinkParticleSystem(LINK_SET,[]);
}

default
{
    state_entry()    {        
    gChan =  (integer)("0xF" + llGetSubString(llGetOwner(),0,6))+11;
    gLisn = llListen(gChan,"","","");
    gON = !gON;    }
    run_time_permissions(integer perm)
    {
        if (perm)
        {
                llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_ROT_LEFT | CONTROL_LEFT | CONTROL_RIGHT | CONTROL_ROT_RIGHT, TRUE, TRUE);
        }
    }
    attach(key on)
    {
        if (on != NULL_KEY)
        {
            integer perm = llGetPermissions();
            stopParticle();
            gLisn = llListen(gChan,"","","");
            
            if (perm != (PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION))
            {
                llRequestPermissions(on, PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION);
                stopParticle();
                gLisn = llListen(gChan,"","","");
            }
            else
            {
                llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_ROT_LEFT | CONTROL_LEFT | CONTROL_RIGHT | CONTROL_ROT_RIGHT, TRUE, TRUE);
                stopParticle();
                gLisn = llListen(gChan,"","","");
            }
            
        }
        else
        {
        stopParticle();
        gLisn = llListen(gChan,"","","");;
        }
    }
    
   
    control(key owner, integer level, integer edge)
    {

        if (level & (CONTROL_FWD | CONTROL_BACK))
        
        {                                    

        particle();    
        llSetTimerEvent(0.5);
        }
        else if (edge & (CONTROL_RIGHT | CONTROL_ROT_RIGHT))
        {                                    

        particle();     
        llSetTimerEvent(0.5);
        }
        else if (edge & (CONTROL_LEFT | CONTROL_ROT_LEFT))
        {
        stopParticle();
        llSetTimerEvent(0.00);
        }

    }
    changed(integer change)
    {
        if     (change & CHANGED_COLOR) particle();
     
    }    
        listen(integer channel, string name, key id, string msg)         {        
       
               
            if(msg == "Red")        
            {            
                llSetColor(<1.0,0.0,0.0>,ALL_SIDES);        
            }        
            else if (msg == "Green")        
            {            
                llSetColor(<0.0,1.0,0.0>,ALL_SIDES);        
            }        
            else if (msg == "Blue")        
            {            
                llSetColor(<0.0,0.0,1.0>,ALL_SIDES);        
            }        
            else if (msg == "Yellow")        
            {            
                llSetColor(<1.0,1.0,0.0>,ALL_SIDES);        
            }        
            else if (msg == "Pink")        
            {            
                llSetColor(<0.9,0.14,0.9>,ALL_SIDES);        
            }        
            else if (msg == "Purple")        
            {            
                llSetColor(<0.7,0.0,1.0>,ALL_SIDES);        
            }        
            else if (msg == "White")        
            {            
                llSetColor(<1.0,1.0,1.0>,ALL_SIDES);        
            }        
            else if (msg == "Black")        
            {            
                llSetColor(<0.0,0.0,0.0>,ALL_SIDES);        
            }        
            else if (msg == "Grey")        
            {            
                llSetColor(<0.5,0.5,0.5>,ALL_SIDES);        
            }        
            particle();    
            }
    timer()
    {
        
        particleTriggered = 0;
        stopParticle();
    }
}

 

 

 

I am really losing my mind on this one...

Link to post
Share on other sites

Okay its not exactly the same thing but i got it to work now.

I took my working version of the script and just replaced the color numbers with llGetColor(0) and added another script that changes the prim colors when chosen on the HUD. i dont really know why it didn't work before but i am happy now!

  • Like 1
Link to post
Share on other sites
You are about to reply to a thread that has been inactive for 370 days.

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...