Jump to content

campfire script


LAHIN Milo
 Share

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

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

Recommended Posts

Hi everyone,

I made a campfire with mesh flame, and my problem is that i'm using 3 scripts to make it work .

1 for the animation texture (that contain the crackling fire sound) , 1 for the light and glow and 1 for the transparent texture when its off, i click on it to turn it on/off it works well, but 3 scripts it's toomuch just for a mesh !

so my question is if it's possible to have thoses 3 script in 1 ? If yes how ?

Edited by LAHIN Milo
Link to comment
Share on other sites

Thx for your reply Fritigern :)

the 1st script is Flame with sound :

 

float volume = 0.5; //Set the sound effects volume (0-1)
float rate = 0.3; //Set the speed of the animation in frames per second

default
{
        touch_start(integer num_detected)
        {
         llLoopSound("3643f41e-fc7b-d44c-120a-35a9aecb4de7",volume);
        llSetTextureAnim(ANIM_ON | SMOOTH | LOOP, ALL_SIDES,
            1, 1,
            0, 1,
            rate
        );
         state loop;
        }
}
       

The second script is the light and glow :

 

// Touch the object to light it up.
// Lighting is configurable.
 
integer light_s    = TRUE;
vector  lightcolor = <1.0, 0.75, 0.5>;
float   intensity  = 1.0;             // 0.0 <= intensity <= 1.0
float   radius     = 10.0;            // 0.1 <= radius <= 20.0
float   falloff    = 0.01;            // 0.01 <= falloff <= 2.0
float   glow       = 0.30;
 
toggle()
{
    float thisglow = 0.0;
    light_s = !light_s;
 
    if (light_s)
        thisglow = glow;
 
    llSetPrimitiveParams([
        PRIM_POINT_LIGHT, light_s, lightcolor, intensity, radius, falloff,
        PRIM_FULLBRIGHT, ALL_SIDES, light_s,
        PRIM_GLOW,       ALL_SIDES, thisglow
    ]);
      llSetColor(lightcolor, ALL_SIDES);
}
 
default
{
    state_entry()
    {
        llSetText("", <1.0, 1.0, 1.0>, 1.0);
        toggle();
    }
 
    touch_start(integer total_number)
    {
        toggle();
    }
}

The thirsd script is the transparent texture when it's turned off :

 

 float transparency = 50.0;
float changeBy     = 100.0;

default
{
    touch_start(integer count)
    {
       

            
            transparency = transparency + changeBy;
            if (transparency > 100.0)
            {
                transparency = 0.0;
            }
           
            llSetAlpha(1.0 - (transparency / 100.0), ALL_SIDES);
       
    }
    changed(integer change)
    {
        
        if (change & CHANGED_OWNER)
        {
            llResetScript();
        }
    }
}

Link to comment
Share on other sites

This is very quick and dirty and leaves LOTS of room for improvement, but it works.
All I did was combine the 3 scripts and fix an issue or two to make the script work. Again, there is a lot of room for improvement, but I'm afraid that RL will not allow me to add more time to this.

 

float transparency = 50.0;
float changeBy     = 100.0;

float volume = 1.0; //Set the sound effects volume (0-1)
float rate = 0.3; //Set the speed of the animation in frames per second

integer light_s    = TRUE;
vector  lightcolor = <1.0, 0.75, 0.5>;
float   intensity  = 1.0;             // 0.0 <= intensity <= 1.0
float   radius     = 10.0;            // 0.1 <= radius <= 20.0
float   falloff    = 0.01;            // 0.01 <= falloff <= 2.0
float   glow       = 0.30;
 
toggle()
{
    float thisglow = 0.0;
    light_s = !light_s;
 
    if (light_s) {
        thisglow = glow;
        llLoopSound("3643f41e-fc7b-d44c-120a-35a9aecb4de7",volume);
    }
 
    llSetPrimitiveParams([
        PRIM_POINT_LIGHT, light_s, lightcolor, intensity, radius, falloff,
        PRIM_FULLBRIGHT, ALL_SIDES, light_s,
        PRIM_GLOW,       ALL_SIDES, thisglow
    ]);
      llSetColor(lightcolor, ALL_SIDES);
}


default
{
    state_entry()
    {
        llSetText("", <1.0, 1.0, 1.0>, 1.0);
        toggle();
    }

    touch_start(integer num_detected)
    {
        llStopSound(); //Stop the sound before toggle.
        toggle();
        
        llSetTextureAnim(ANIM_ON | SMOOTH | LOOP, ALL_SIDES, 1, 1, 0, 1, rate );
    }

    changed(integer change)
    {        
        if (change & CHANGED_OWNER)
        {
            llResetScript();
        }
    }
}

 

Link to comment
Share on other sites

another way to get started then something like this maybe

integer light_s;
vector  lightcolor = <1.0, 0.75, 0.5>;
float   intensity  = 1.0;             // 0.0 <= intensity <= 1.0
float   radius     = 10.0;            // 0.1 <= radius <= 20.0
float   falloff    = 0.01;            // 0.01 <= falloff <= 2.0
float   glow       = 0.30;
float transparency = 0.5;

float rate = 0.5;
float volume = 0.5;

toggle(integer on)
{
    llSetPrimitiveParams( 
    [
        PRIM_POINT_LIGHT, on, lightcolor, intensity, radius, falloff,
        PRIM_FULLBRIGHT, ALL_SIDES, light_s,
        PRIM_GLOW, ALL_SIDES, (float)on * glow,
        PRIM_COLOR, ALL_SIDES, lightcolor, (float)on * transparency,
    ]);

    llSetTextureAnim(on|SMOOTH|LOOP, ALL_SIDES, 1, 1, 0.0, 0.0, (float)on * rate); 
    llLoopSound("3643f41e-fc7b-d44c-120a-35a9aecb4de7", (float)on * volume);
}

default
{
    state_entry()
    {
       toggle(light_s = 0);  // douse the fire
    }    

    touch_start(integer n)
    {
       toggle(light_s = !light_s);  // light or douse the fire on touch
    }
}

 

Edited by Mollymews
another way
Link to comment
Share on other sites

12 minutes ago, LAHIN Milo said:

 

@Mollymews Thank you, I tried your script but it doesnt work.. it says syntax error on 19 & 4 .

 

is what happens when type stuff off the top of  our head and not use a actual code editor :)

i will have to log in now and test it

just looking at it though line 19 has a spurious comma at the end of the line after "transparency"

edit: yes. remove the spurious comma at the end of the line

Edited by Mollymews
  • Like 1
Link to comment
Share on other sites

1 hour ago, LAHIN Milo said:

@Mollymews so it works now, but i cant hear the sound of the fire :D maybe i've to fix something . I increased the volume but cant hear it ..

@Fritigern Gothly well in the flame script i gave you before (with the 2 others scripts) the texture show up on the mesh . there's no UUID texture in the script, i have to slide it in the texture tab .

first the texture issue,  You should apply the fire texture manually to your object

with the sound then it may be that the UUID of the sound clip in the script is invalid.  If so then best to get your own sound clip, and put it in the script

Link to comment
Share on other sites

Hi @Mollymews yes that's what i did. i've made my own sound with audacity. I took the UUID and paste it into the script but it doesnt work... i cant hear it ...

And for texture issue, i slided the texture into the texture tab in edit menu... Still nothing i even tried to slide the texture in the content object but nothing change.

Edited by LAHIN Milo
Link to comment
Share on other sites

19 hours ago, LAHIN Milo said:

Hi @Mollymews yes that's what i did. i've made my own sound with audacity. I took the UUID and paste it into the script but it doesnt work... i cant hear it ...

And for texture issue, i slided the texture into the texture tab in edit menu... Still nothing i even tried to slide the texture in the content object but nothing change.

without seeing the object, I don't know

Link to comment
Share on other sites

15 minutes ago, LAHIN Milo said:

@Mollymews hum i see ... but if you try on a cube .. put any texture in the edit menu (texture) 

like Fritigern said we work with what we got :)

in your scripts "glow" is set to 0.30, and "transparency is set to 0.5.  If you change "glow" to some other value like 0.01 or 0.03 and  "transparency" to say 0.8 or 1.0 then you can better see the manually applied texture

 

Link to comment
Share on other sites

i had a quick look a the wiki about sound. Seems we can't change the volume of llLoopSound() without stopping the sound first. Try this:

   llStopSound();
   llLoopSound("seagull1", (float)on * volume);

to test this the seagull1 sound clip  can be taken from Library \ Objects \ DPW Items for Library \ Sea Gulls \ Sea Gull Sounds object, and copied to your object Contents

 

  • Thanks 1
Link to comment
Share on other sites

yay ! now i can hear the sound ! Thank you for your patience :)

About the glow and transparency , i can see the glow line set to 0.30 but i dont see any line with transparency set to 0.5. I just see transparency to 50.0 .

Anyway now everything works fine !

thank you Fritigern Thank you Mollymews ! 👍:)

  • Like 1
Link to comment
Share on other sites

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