Jump to content
Sign in to follow this  
LAHIN Milo

campfire script

Recommended Posts

Posted (edited)

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

Share this post


Link to post
Share on other sites

Yes, it is possible (and preferred!), and the way to do that is to combine all the scripts into one. 

I (or we) could help you with that, but we would have to see the scripts.

  • Like 1

Share this post


Link to post
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();
        }
    }
}

Share this post


Link to post
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();
        }
    }
}

 

Share this post


Link to post
Share on other sites
Posted (edited)

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

Share this post


Link to post
Share on other sites
Posted (edited)

@Fritigern Gothly Thank you ! it works, but ... my flame texture don't show up on the mesh .

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

i hope that i (or we or you :D ) will find the solution to make it work in only one script  :D

Edited by LAHIN Milo

Share this post


Link to post
Share on other sites
Posted (edited)
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

Share this post


Link to post
Share on other sites
9 minutes ago, LAHIN Milo said:

@Fritigern Gothly Thank you ! it works, but ... my flame texture don't show up on the mesh .

That's because your scripts do not contain the flame texture. I worked with what I had 🙂

  • Like 1

Share this post


Link to post
Share on other sites
Posted (edited)

@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 . With the combined scripts it doesnt work .

Edited by LAHIN Milo

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
Posted (edited)

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

@Mollymews hum i see ... but if you try on a cube .. put any texture in the edit menu (texture) and any UUID sound into the script you will see :)

Ifnot i can show you in world ...

If somebody know why i cant hear the sound .. please let me know :D 

Share this post


Link to post
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

 

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

in my script its: float transparency = 0.5:

in yours its: float transparency = 50.0;

change your 50.0 to say 80.0 or 90.0 or 100.0 or whatever works for you

 

  • Like 1

Share this post


Link to post
Share on other sites

Remember that scripts use alpha, opacity, measured 0.0 – 1.0, while in the build floater it's transparency, measured 0% – 100%. So, different scales and measured the other way around.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...