Jump to content

Particle Color Changer


Braun Ulrik
 Share

You are about to reply to a thread that has been inactive for 337 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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
Share on other sites

  • 3 years later...
On 5/6/2020 at 3:15 PM, marcin1995 Sharple said:

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!

hey man could you share how you did? im stuck on something similar, not really good with scripts, so im struggilng here

i need it to change the particle collor, and it does change when i save, but if a change the prim collor it stays the other collor

 

default
{
    state_entry()
 {
        llParticleSystem(
        [
            PSYS_SRC_PATTERN,PSYS_SRC_PATTERN_ANGLE_CONE_EMPTY,
            PSYS_SRC_BURST_RADIUS,0,
            PSYS_SRC_ANGLE_BEGIN,0,
            PSYS_SRC_ANGLE_END,0,
            PSYS_SRC_TARGET_KEY,llGetKey(),
            PSYS_PART_START_COLOR,llGetColor(1),  // Input Start LSL Color Here
            PSYS_PART_END_COLOR,llGetColor(1),    // Input End LSL Color Here
            PSYS_PART_START_ALPHA,1,
            PSYS_PART_END_ALPHA,0,
            PSYS_PART_START_GLOW,0.05,
            PSYS_PART_END_GLOW,0.02,
            PSYS_PART_BLEND_FUNC_SOURCE,PSYS_PART_BF_SOURCE_ALPHA,
            PSYS_PART_BLEND_FUNC_DEST,PSYS_PART_BF_ONE_MINUS_SOURCE_ALPHA,
            PSYS_PART_START_SCALE,<0.200000,0.200000,0.000000>,
            PSYS_PART_END_SCALE,<1.00000,1.00000,0.000000>, // Adjust Scale here
            PSYS_SRC_TEXTURE,"UUID",
            PSYS_SRC_MAX_AGE,0,
            PSYS_PART_MAX_AGE,10,
            PSYS_SRC_BURST_RATE,10, // Adjust rate here
            PSYS_SRC_BURST_PART_COUNT,2,
            PSYS_SRC_ACCEL,<0.000000,0.000000,0.000000>,
            PSYS_SRC_OMEGA,<0.000000,0.000000,0.000000>,
            PSYS_SRC_BURST_SPEED_MIN,0.1,
            PSYS_SRC_BURST_SPEED_MAX,0.1,
            PSYS_PART_FLAGS,
                0 |
                PSYS_PART_EMISSIVE_MASK |
                PSYS_PART_FOLLOW_SRC_MASK |
                PSYS_PART_INTERP_COLOR_MASK |
                PSYS_PART_INTERP_SCALE_MASK
        ]);
    }
}

 

Dont know if its missing something, cant make it change the collor this way

Link to comment
Share on other sites

That code is mostly correct, just as you say, it needs to change particle color when the object color changes. Fortunately, scripts can use a CHANGED_COLOR event to detect and respond to exactly that condition. So we may want to set the particle system in the state_entry() event so it's got some particles going right away, and also in the changed() event. Rather than repeat that particle system code in both places, we can use a user-defined function, "makeParticles()" here, and call it in both events. Then it will look like this:


makeParticles()
{
    // make particles, same code as in forums post (with PSYS_SRC_TEXTURE changed):
        llParticleSystem(
        [
            PSYS_SRC_PATTERN,PSYS_SRC_PATTERN_ANGLE_CONE_EMPTY,
            PSYS_SRC_BURST_RADIUS,0,
            PSYS_SRC_ANGLE_BEGIN,0,
            PSYS_SRC_ANGLE_END,0,
            PSYS_SRC_TARGET_KEY,llGetKey(),
            PSYS_PART_START_COLOR,llGetColor(1),  // Input Start LSL Color Here
            PSYS_PART_END_COLOR,llGetColor(1),    // Input End LSL Color Here
            PSYS_PART_START_ALPHA,1,
            PSYS_PART_END_ALPHA,0,
            PSYS_PART_START_GLOW,0.05,
            PSYS_PART_END_GLOW,0.02,
            PSYS_PART_BLEND_FUNC_SOURCE,PSYS_PART_BF_SOURCE_ALPHA,
            PSYS_PART_BLEND_FUNC_DEST,PSYS_PART_BF_ONE_MINUS_SOURCE_ALPHA,
            PSYS_PART_START_SCALE,<0.200000,0.200000,0.000000>,
            PSYS_PART_END_SCALE,<1.00000,1.00000,0.000000>, // Adjust Scale here
            PSYS_SRC_TEXTURE,"",    // CHANGED
            PSYS_SRC_MAX_AGE,0,
            PSYS_PART_MAX_AGE,10,
            PSYS_SRC_BURST_RATE,10, // Adjust rate here
            PSYS_SRC_BURST_PART_COUNT,2,
            PSYS_SRC_ACCEL,<0.000000,0.000000,0.000000>,
            PSYS_SRC_OMEGA,<0.000000,0.000000,0.000000>,
            PSYS_SRC_BURST_SPEED_MIN,0.1,
            PSYS_SRC_BURST_SPEED_MAX,0.1,
            PSYS_PART_FLAGS,
                0 |
                PSYS_PART_EMISSIVE_MASK |
                PSYS_PART_FOLLOW_SRC_MASK |
                PSYS_PART_INTERP_COLOR_MASK |
                PSYS_PART_INTERP_SCALE_MASK
        ]);
}

default
{
    state_entry()
    {
        makeParticles();
    }
    changed(integer change)
    {
        if (CHANGED_COLOR & change)
            makeParticles();
    }
}

Note that I also changed the PSYS_SRC_TEXTURE to use the default hazy blob you get by specifying an empty string. That value needs to be either the name of a texture included in the object's contents, or the UUID ("key") of a texture asset (for which there are some handy pre-defined constants such as TEXTURE_BLANK, TEXTURE_PLYWOOD, etc).

Link to comment
Share on other sites

On 6/2/2023 at 7:32 AM, Qie Niangao said:

That code is mostly correct, just as you say, it needs to change particle color when the object color changes. Fortunately, scripts can use a CHANGED_COLOR event to detect and respond to exactly that condition. So we may want to set the particle system in the state_entry() event so it's got some particles going right away, and also in the changed() event. Rather than repeat that particle system code in both places, we can use a user-defined function, "makeParticles()" here, and call it in both events. Then it will look like this:


makeParticles()
{
    // make particles, same code as in forums post (with PSYS_SRC_TEXTURE changed):
        llParticleSystem(
        [
            PSYS_SRC_PATTERN,PSYS_SRC_PATTERN_ANGLE_CONE_EMPTY,
            PSYS_SRC_BURST_RADIUS,0,
            PSYS_SRC_ANGLE_BEGIN,0,
            PSYS_SRC_ANGLE_END,0,
            PSYS_SRC_TARGET_KEY,llGetKey(),
            PSYS_PART_START_COLOR,llGetColor(1),  // Input Start LSL Color Here
            PSYS_PART_END_COLOR,llGetColor(1),    // Input End LSL Color Here
            PSYS_PART_START_ALPHA,1,
            PSYS_PART_END_ALPHA,0,
            PSYS_PART_START_GLOW,0.05,
            PSYS_PART_END_GLOW,0.02,
            PSYS_PART_BLEND_FUNC_SOURCE,PSYS_PART_BF_SOURCE_ALPHA,
            PSYS_PART_BLEND_FUNC_DEST,PSYS_PART_BF_ONE_MINUS_SOURCE_ALPHA,
            PSYS_PART_START_SCALE,<0.200000,0.200000,0.000000>,
            PSYS_PART_END_SCALE,<1.00000,1.00000,0.000000>, // Adjust Scale here
            PSYS_SRC_TEXTURE,"",    // CHANGED
            PSYS_SRC_MAX_AGE,0,
            PSYS_PART_MAX_AGE,10,
            PSYS_SRC_BURST_RATE,10, // Adjust rate here
            PSYS_SRC_BURST_PART_COUNT,2,
            PSYS_SRC_ACCEL,<0.000000,0.000000,0.000000>,
            PSYS_SRC_OMEGA,<0.000000,0.000000,0.000000>,
            PSYS_SRC_BURST_SPEED_MIN,0.1,
            PSYS_SRC_BURST_SPEED_MAX,0.1,
            PSYS_PART_FLAGS,
                0 |
                PSYS_PART_EMISSIVE_MASK |
                PSYS_PART_FOLLOW_SRC_MASK |
                PSYS_PART_INTERP_COLOR_MASK |
                PSYS_PART_INTERP_SCALE_MASK
        ]);
}

default
{
    state_entry()
    {
        makeParticles();
    }
    changed(integer change)
    {
        if (CHANGED_COLOR & change)
            makeParticles();
    }
}

Note that I also changed the PSYS_SRC_TEXTURE to use the default hazy blob you get by specifying an empty string. That value needs to be either the name of a texture included in the object's contents, or the UUID ("key") of a texture asset (for which there are some handy pre-defined constants such as TEXTURE_BLANK, TEXTURE_PLYWOOD, etc).

hey man sorry to bother again, but this one i really dont know how to do as it wasnt mine

its the other script im using for the change color here, wat im trying is to make it owner only to use, as it is now anyone can change, and it changes everything that have the script, anyone who i send it can change for everyone and its just a mess, if you could save this soul again pls

 

integer HS_PLANE_FACE = 2;
integer L_AXIS_FACE = 4;
integer CMD_CH  = -1024;
vector HSL = <0.0, 0.0, 0.5>;


//Set new color and (optionally) preview
new_hsl_color(vector color)
{
    //llSetColor(hsl_2_rgb(<color.x, color.y, 0.5>), L_AXIS_FACE);
    llSay(CMD_CH, (string)hsl_2_rgb(color));
    llSleep(0.1);
}

//Wrap value to between 0 and 1
float scale_f(float f)
{
    if (f < 0.0)
    {
        f += 1.0;
    }
    else if(f > 1.0)
    {
        f -= 1.0;
    }
    
    return f;
}

//Calculate RGB from (t, p, q)
float rgb_color(float c, float p, float q)
{
    if(c < 0.166667)
    {
        return p+(q-p)*6*c;
    }
    else if(c >= 0.166667 && c < 0.5)
    {
        return q;
    }
    else if(c >= 0.5 && c < 0.666667)
    {
        return p+(q-p)*6*(0.666667 - c);
    }
    else
    {
        return p;
    }
}

//Convert HSL color to RGB color
vector hsl_2_rgb(vector color)
{
    float p;
    float q;
    vector t = <scale_f(color.x + 0.333333), scale_f(color.x), scale_f(color.x - 0.333333)>;
    
    if (HSL.z < 0.5)
    {
        q = color.z * (1 + color.y);
    }
    else
    {
        q = color.z + color.y - (color.z * color.y);
    }
    
    p = 2*color.z - q;
    
    return <rgb_color(t.x, p, q), rgb_color(t.y, p, q), rgb_color(t.z, p, q)>;
}

default
{
    state_entry()
    {   //Initial color
        //new_hsl_color(HSL);
    }

    touch_start(integer n)
    {
        integer face = llDetectedTouchFace(0);
        if(face == HS_PLANE_FACE)
        {   //HS plane
            vector v = llDetectedTouchST(0);
            HSL = <v.y, 1.0 - v.x, HSL.z>;
            
            new_hsl_color(HSL);
        }
        else if(face == L_AXIS_FACE)
        {   //L axis
            vector v = llDetectedTouchST(0);
            HSL = <HSL.x, HSL.y, v.y>;
            
            new_hsl_color(HSL);
        }
        else if(face == -1)
        {   //TOUCH_INVALID_FACE ~ outdated viewer
            llInstantMessage(llDetectedKey(0), "Please update your viewer to use this color picker :P");
        }
    }

    touch(integer n)
    {
        integer face = llDetectedTouchFace(0);
        if(face == HS_PLANE_FACE)
        {   //HS plane
            vector v = llDetectedTouchST(0);
            HSL = <v.y, 1.0 - v.x, HSL.z>;
            
            new_hsl_color(HSL);
        }
        else if(face == L_AXIS_FACE)
        {   //L axis
            vector v = llDetectedTouchST(0);
            HSL = <HSL.x, HSL.y, v.x>;
            
            new_hsl_color(HSL);
        }
    }
}
 

 

ive read in another place to put (llDetectedKey(0)  == llGetOwner()) after 'start touch' but it didnt seem to work

Link to comment
Share on other sites

A simplistic view of the problem is that this script for some reason has both touch_start() and touch() handlers that do the same thing. Most scripts don't use a touch() handler but I'm honestly not sure what's more natural in this color-picker application because maybe the idea is to keep updating the item's color as fast as possible while the user holds down the mouse button, generating a constant stream of touch() events. If you want it to keep doing that, we can just add the owner only logic to both touch_start and touch events

Just to keep it simple, I'd change the sense of the test to make it self-contained, rather than embedding the whole event handler inside the tested condition. That is, I'd add a one-liner at the top of touch() and touch_start():

if (llDetectedKey(0) != llGetOwner()) return;

Now, however, a potentially harder problem: This tests for owner, and you said you wanted "to make it owner only to use" but you also said the problem is "anyone who i send it can change for everyone", but if you send it to them, they'll be the owner, right? At least they'll own the thing you sent them, and if that's the thing with the script, they'll be the owner in that script.

If I guess correctly, it seems this color picker script might go in a HUD or something, and tries to tell another script to change color, a la:
    llSay(CMD_CH, (string)hsl_2_rgb(color));
and that's cool, but it means that other script (maybe the one making particles) in the to-be-recolored object is waiting on a listen() event on that same channel. And if that's correct, then it's really the other script that needs to be checking whether its owner is the same as the person touching the color-picker.

Fortunately, that's probably easy, too. With the above logic, the color-pickers are only responding to their owners, so we just need to make sure our color-changing object only listens to a color picker owned by its owner. Assuming that color-changing object's script is not also listening for other stuff from other places, you can simply check at the top of its listen() handler whether the owner of the sending object matches its own owner, a la:

if (llGetOwnerKey(id) != llGetOwner()) return;

where id is replaced by whatever variable name is the key parameter of that listen() handler.

 

  • Like 3
Link to comment
Share on other sites

Yes, as you said, it goes on a hud, and the listener is on the item

as for the key parameter its marked as 'id' too on the listen () 

integer CMD_CH = -1024;

default
{
    state_entry()
    {
        llListen(CMD_CH, "", "", "");
    }
    
    listen(integer ch, string name, key id, string msg)
    {
        llSetColor((vector)msg, ALL_SIDES);
    }
}
 

when i tried the getowner i noticed the two touch parameters here, but as it worked just fine i didnt chenge there just put } before the second one to close

and for the listener being the same didnt think the problem could be there

Link to comment
Share on other sites

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