Fire Particles

Creating scripts
Post Reply
User avatar
Constance Peregrine
Posts: 2353
Joined: Sun Dec 23, 2012 11:35 am
Has thanked: 2784 times
Been thanked: 1489 times

Fire Particles

Post by Constance Peregrine »

Code: Select all

// Freebie Fire Script w/Environmental Sounds
// by Babu Oh (2008)
//
// - simple wrapper around particle fire script by Ama Omega (10-10-2003)
// and freebie environmental sound script by Apotheus Silverman
// (found within the "Giving Campfire" freebie by Cherry Asturias).
//
// - THIS SCRIPT IS OPEN SOURCE AND FREE. PLEASE DISTRIBUTE ACCORDINGLY.


// 2008-11-02
// - version 0.2
// - added simple menu to particle fire script
// - added link message functions to environmental sound script
//
// 2008-02-04
// - version 0.1
// - uses Ama Omega's freebie fire particle script
// and freebie environmental sound script




// =====================================================================
// VARS
// =====================================================================


// ================ [ menu dialog vars ]

// channel used for menu dialog
integer gChannel = -987654;

string MENU_DIALOG_TEXT = "Please choose an option:";

integer gDialogListener = 0;


// ================ [ link message vars ]

string ON_OFF = "SND_ON_OFF";
string RESET = "RESET";


// ================ [ script vars ]


// this is the "on" or "off" flag

integer gParticlesOn = 0;


// set to 1 if you want menu to be accessible by owner only
// set to 0 if you want everyone to access the menu

integer gControlByOwnerOnly = 0;

// sound

// set to 1 if you want environmental sounds
// set to 0 if you do not

integer gSoundOn = 0;

// sound params

string FIRE_SOUND = "fire";
float SOUND_VOLUME = 1.0;

// light params

vector gLightsOnVector = <1.0, 0.5, 0.0>;
float gLightIntensity = 1.0;
float gLightRadius = 10.0;
float gLightFalloff = 0.75;
float gLightAlpha = 1.0;
float gPrimGlow = 0.05;
integer gPrimFullbright = 1;


// =====================================================================






// =====================================================================
// FREEBIE PARTICLE SCRIPT FUNCTIONS
// =====================================================================

// This is the entire freebie script by Ama Omega

// Particle Script 0.3
// Created by Ama Omega
// 10-10-2003

// Mask Flags - set to TRUE to enable
integer glow = TRUE;            // Make the particles glow
integer bounce = FALSE;          // Make particles bounce on Z plan of object
integer interpColor = TRUE;     // Go from start to end color
integer interpSize = TRUE;      // Go from start to end size
integer wind = TRUE;           // Particles effected by wind
integer followSource = FALSE;    // Particles follow the source
integer followVel = TRUE;       // Particles turn to velocity direction

// Choose a pattern from the following:
// PSYS_SRC_PATTERN_EXPLODE
// PSYS_SRC_PATTERN_DROP
// PSYS_SRC_PATTERN_ANGLE_CONE_EMPTY
// PSYS_SRC_PATTERN_ANGLE_CONE
// PSYS_SRC_PATTERN_ANGLE
integer pattern = PSYS_SRC_PATTERN_EXPLODE;

// Select a target for particles to go towards
// "" for no target, "owner" will follow object owner 
//    and "self" will target this object
//    or put the key of an object for particles to go to
key target = "";

// Particle paramaters
float age = .9;                  // Life of each particle
float maxSpeed = .2;            // Max speed each particle is spit out at
float minSpeed = .01;            // Min speed each particle is spit out at
string texture;                 // Texture used for particles, default used if blank
float startAlpha = 1;           // Start alpha (transparency) value
float endAlpha = 0.1;           // End alpha (transparency) value
vector startColor = <1,1,0>;    // Start color of particles <R,G,B>
vector endColor = <1,0,0>;      // End color of particles <R,G,B> (if interpColor == TRUE)
vector startSize = <.5,.5,.5>;     // Start size of particles 
vector endSize = <.1,1,.1>;       // End size of particles (if interpSize == TRUE)
vector push = <0,0,3>;          // Force pushed on particles

// System paramaters
float rate = .1;            // How fast (rate) to emit particles
float radius = .1;          // Radius to emit particles for BURST pattern
integer count = 15;        // How many particles to emit per BURST 
float outerAngle = 1.75;    // Outer angle for all ANGLE patterns
float innerAngle = 1.55;    // Inner angle for all ANGLE patterns
vector omega = <5,1,10>;    // Rotation of ANGLE patterns around the source
float life = 0;             // Life in seconds for the system to make particles

// Script variables
integer flags;

updateParticles()
{
    flags = 0;
    if (target == "owner") target = llGetOwner();
    if (target == "self") target = llGetKey();
    if (glow) flags = flags | PSYS_PART_EMISSIVE_MASK;
    if (bounce) flags = flags | PSYS_PART_BOUNCE_MASK;
    if (interpColor) flags = flags | PSYS_PART_INTERP_COLOR_MASK;
    if (interpSize) flags = flags | PSYS_PART_INTERP_SCALE_MASK;
    if (wind) flags = flags | PSYS_PART_WIND_MASK;
    if (followSource) flags = flags | PSYS_PART_FOLLOW_SRC_MASK;
    if (followVel) flags = flags | PSYS_PART_FOLLOW_VELOCITY_MASK;
    if (target != "") flags = flags | PSYS_PART_TARGET_POS_MASK;

    llParticleSystem([  PSYS_PART_MAX_AGE,age,
                        PSYS_PART_FLAGS,flags,
                        PSYS_PART_START_COLOR, startColor,
                        PSYS_PART_END_COLOR, endColor,
                        PSYS_PART_START_SCALE,startSize,
                        PSYS_PART_END_SCALE,endSize, 
                        PSYS_SRC_PATTERN, pattern,
                        PSYS_SRC_BURST_RATE,rate,
                        PSYS_SRC_ACCEL, push,
                        PSYS_SRC_BURST_PART_COUNT,count,
                        PSYS_SRC_BURST_RADIUS,radius,
                        PSYS_SRC_BURST_SPEED_MIN,minSpeed,
                        PSYS_SRC_BURST_SPEED_MAX,maxSpeed,
                        PSYS_SRC_TARGET_KEY,target,
                        PSYS_SRC_INNERANGLE,innerAngle, 
                        PSYS_SRC_OUTERANGLE,outerAngle,
                        PSYS_SRC_OMEGA, omega,
                        PSYS_SRC_MAX_AGE, life,
                        PSYS_SRC_TEXTURE, texture,
                        PSYS_PART_START_ALPHA, startAlpha,
                        PSYS_PART_END_ALPHA, endAlpha
                            ]);
}


// =====================================================================






// =====================================================================
// CONTROL FUNCTIONS
// =====================================================================


initialize()
{
    update_fire();
    update_sounds();
}


// update particle fire according to particle on/particle off status

update_fire()
{
    if (gParticlesOn)
    {
        updateParticles();
        loop_sound(FIRE_SOUND);
    }
    else
    {
        llParticleSystem([]);
        llStopSound();
    }
    
    update_light();
}


// update light

update_light()
{
    list params;

    if (gParticlesOn)
    {
        params = [ PRIM_POINT_LIGHT, TRUE,
                        gLightsOnVector, gLightIntensity,
                        gLightRadius, gLightFalloff,
                    PRIM_FULLBRIGHT, ALL_SIDES, gPrimFullbright,
                    PRIM_GLOW, ALL_SIDES, gPrimGlow ];
    }
    else
    {
        params = [ PRIM_POINT_LIGHT, FALSE,
                        <1.0,1.0,1.0>, 0.0,
                        0.0, 0.0,
                    PRIM_FULLBRIGHT, ALL_SIDES, 0,
                    PRIM_GLOW, ALL_SIDES, 0.0 ];
    }
    
    llSetPrimitiveParams(params);
}


// loop a sound

loop_sound(string sound)
{
    if (llGetInventoryType(sound) == INVENTORY_SOUND)
    {
        llLoopSound(sound, SOUND_VOLUME);
    }
}



// update environmental sounds
// - this sends a link message to the auxiliary environmental sound script

update_sounds()
{
    llMessageLinked(LINK_SET, gSoundOn, ON_OFF, NULL_KEY);
}


// =====================================================================







// =====================================================================
// STATES
// =====================================================================

default
{
    state_entry()
    {
        initialize();
        llSay(0, "Ready! Click for menu.");
    }

    
    touch_start(integer num)
    {
        integer channel;
        list menu_options = [];
        string display = "";
        string label = "";
        string text = "";
        key id;
        
        id = llDetectedKey(0);
        
        if ((id != llGetOwner()) && gControlByOwnerOnly)
            return;

        do
        {
            channel = (integer) (llFrand(-1000000000.0) - 1000000000.0);
        }
        while (channel == gChannel);
        
        gChannel = channel;
        gDialogListener = llListen(gChannel, "", id, "");

        
        if (id == llGetOwner())
        {        
            if (gControlByOwnerOnly)
            {
                text = "Locked";
                label = "Unlock";
            }
            else
            {
                text = "Unlocked";
                label = "Lock";
            }
    
            menu_options += label;
            display = "Menu control: " + text + "\n";
        }
        
        if (gParticlesOn)
        {
            menu_options += "Fire Off";
            text = "On";
        }
        else
        {
            menu_options += "Fire On";
            text = "Off";
        }
        
        display += "Fire is: " + text + "\n";
                
        if (gSoundOn)
        {
            menu_options += "Sound Off";
            text = "On";
        }
        else
        {
            menu_options += "Sound On";
            text = "Off";
        }
        
        menu_options += "Reset";

        display += "Environmental sounds are: " + text;
        
        display += "\n" + MENU_DIALOG_TEXT;
    
        llDialog(id, display, menu_options, gChannel);
    }


    listen(integer channel, string name, key id, string message)
    {
        if (channel != gChannel)
            return;

        llListenRemove(gDialogListener);
        gDialogListener = 0;
        
        if (message == "Lock")
        {
            gControlByOwnerOnly = 1;
        }
        else if (message == "Unlock")
        {
            gControlByOwnerOnly = 0;
        }
        else if (message == "Fire On")
        {
            gParticlesOn = 1;
            update_fire();
        }
        else if (message == "Fire Off")
        {
            gParticlesOn = 0;
            update_fire();
        }
        else if (message == "Sound On")
        {
            gSoundOn = 1;
            update_sounds();
        }
        else if (message == "Sound Off")
        {
            gSoundOn = 0;
            update_sounds();
        }
        else if (message == "Reset")
        {
            // reset scripts

            gParticlesOn = 0;
            update_fire();
            
            llMessageLinked(LINK_SET, 0, RESET, NULL_KEY);
            llResetScript();
        }
    }

}


// =====================================================================
These users thanked the author Constance Peregrine for the post (total 3):
Ilan TochnerDundridge DreadlowAdagio Greenwood
Laissez faire et laissez passer, le monde va de lui même!
My little sounds store https://www.kitely.com/market?store=2040306

Ephemeral wanderer...
User avatar
Constance Peregrine
Posts: 2353
Joined: Sun Dec 23, 2012 11:35 am
Has thanked: 2784 times
Been thanked: 1489 times

Re: Fire Particles numero dos

Post by Constance Peregrine »

another one works...

Code: Select all

// Particle Fire created by Vichal Beck
// Copyright © 2008
// This script was written for Tutorials 2 Go 
// This script is free to use for any learning activity.
// You may also use this script for any non-commercial use. 
// Feel free to modify this script as you wish so long as you leave these header comments in tact.
// Please add any comments on what you added with your name so people may know who did what part of this script.



integer fireOn=TRUE; // Initializes the fireOn value to TRUE as fire starts on when script is started.

particlesys()
{
    llParticleSystem([
        PSYS_PART_FLAGS,PSYS_PART_EMISSIVE_MASK|PSYS_PART_INTERP_COLOR_MASK,PSYS_SRC_PATTERN,PSYS_SRC_PATTERN_ANGLE_CONE,
        PSYS_PART_START_COLOR,<1.0,1.0,0.0>, // The starting color of the fire.
        PSYS_PART_END_COLOR,<1.0,0.0,0.0>,   // What color the fire fades too
        PSYS_PART_START_ALPHA,0.7,           // Sets the transparancy of the fire 0= invis 1= not transparent.
        PSYS_PART_END_ALPHA,0.0,             // The ending transparency what the fire fades into.
        PSYS_PART_START_SCALE,<0.1,0.2,0.0>, // Sets the starting size of the fire particle
        PSYS_PART_MAX_AGE,2.0,               // How long each particle will exist before it dies.
        PSYS_SRC_ACCEL,<0.0,0.0,0.3>,        // Vector <x,y,z> of which way particle is pushed. <0,0,0.3> means gently pushed upward
        PSYS_SRC_ANGLE_BEGIN,0.0,            // angular pattern has a begin and end area they are interchangable. 0 is no angle or strait up.
        PSYS_SRC_ANGLE_END,0.5,              // .5 is just out a bit from the top. downward would be PI.
        PSYS_SRC_BURST_PART_COUNT,10,        // How many particles sent out per burst (only really matters if RATE is set to a number instead of 0.
        PSYS_SRC_BURST_SPEED_MIN,0.0,        // speed at which particle gets pushed out. Speed will be between this minimum value
        PSYS_SRC_BURST_SPEED_MAX,0.5,        // and this maximum value.
        PSYS_SRC_OMEGA,<3.0,6.0,0.0>,        // how much the particles move around in an x,y,z circle from the prim.
        PSYS_SRC_BURST_RATE,0.0              // how often to send particles out 0 = always.
        ]);
}

default
{
    // State entry is the first function called when script is reset. (not just rezzed)
    state_entry()
    {
        particlesys(); // Start the fire
        if(llGetInventoryNumber(INVENTORY_SOUND)>0) // if there is a sound file in the object
            llLoopSound(llGetInventoryName(INVENTORY_SOUND, 0), 1);  // Play the first sound file found in object
    }
    
    // This event fires when object is put out.
    on_rez(integer start_param)
    {
        llResetScript();
    }

    // This event is started when object is touched. 
    //(If object is the root prim, last selected when linked, then touching any of the linked objects will fire this event off.)
    touch_start(integer total_number)
    {
        // If fire is already on.
        if ( fireOn )
        {
            // Turn fire and sound off. Set fireOn=FALSE.
            fireOn = FALSE;
            llStopSound(); // Turns the sound off.
            llParticleSystem([]); // Start empty particle to clear them.
        }
        else // if fire was off.
        {
            // Turn fire and sound on. Set fireOn=TRUE.
            fireOn = TRUE;
            if(llGetInventoryNumber(INVENTORY_SOUND)>0) // Check for a sound file in the object.
                llLoopSound(llGetInventoryName(INVENTORY_SOUND, 0), 1); // Play first sound file found in object.
            particlesys();  // Turns the fire on.
        } 
    }
}
Laissez faire et laissez passer, le monde va de lui même!
My little sounds store https://www.kitely.com/market?store=2040306

Ephemeral wanderer...
Post Reply