Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

discussion: Particle system script

Teffler Detritus
Registered User
Join date: 14 Dec 2005
Posts: 19
04-13-2006 20:22
After fighting with a particle script from http://www.sluniverse.com/forums/Topic44-10-1.aspx
in an attempt to get just the effect I want it, after numerous recompiles I decied i could write a script to stream line the process a little.

Hopefully this will be useful to some other people too.

CODE

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

// // http://www.sluniverse.com/forums/Topic44-10-1.aspx

// Modified by Teffler Detritus

// List of variable names
list var_name = ["pattern", "target", "age", "maxSpeed", "minSpeed", "texture", "startAlpha", "endAlpha", "startColor", "endColor", "startSize", "endSize", "push", "rate", "radius", "count", "angleBegin", "angleEnd", "omega", "life"];

// List of variable types
list var_type = ["integer", "string", "float", "float", "float", "string", "float", "float", "vector", "vector", "vector", "vector", "vector", "float", "float", "integer", "float", "float", "vector", "integer"];

// List of variable values
list var_cont = ["8", "", "2.0", "15.0", "10.0", "NULL_KEY", "1.0", "0.1", "<1,0.5,0.1>", "<1,0.5,0.1>", "<1,1,1>", "<0,0,0>", "<0,0,-1>", "0.0", "15.0", "100", "0.15", "0.05", "<0,0,0>", "0.0"];

// List of help for variables
list var_help = ["pattern: The emission pattern of the particles.\n 1 for DROP,\n 2 for EXPLODE,\n 4 for ANGLE,\n 8 for ANGLE_CONE,\n 10 for ANGLE_CONE_EMPTY.",
"target: Target to emit particles towards. (object rezzed by owner) Owner for the owner of the object, self for the object itself, NULL_KEY for no target.",
"age: how long they will last from creation to death.",
"maxSpeed: The maximum speed of a particle been emitted.",
"minSpeed: The minimum speed of a particle been emitted.",
"texture: The key or inventory name of a texture to apply to the particle. (place the texture in the object contents along with the script)",
"startAlpha: How visible the particle will be at emission.",
"endAlpha: How visible the particle will be at death.",
"startColor: The color the particle will be at emission.",
"endColor: The color the particle will be at death.",
"startSize: The size the particle will be at emission.",
"endSize: The size the particle will be at death.",
"push: The acceleration of the particle.",
"rate: The burst speed that they particles are emitted at, 0 for constant stream",
"radius: The radius from the centre source in metres to create particles.",
"count: How many particles to emit on each burst.",
"angleBegin: Area in radians where particles will not fill (angle patterns).",
"angleEnd: Area in radians where particles will fill (angle patterns).",
"omega: Rotation, src of particle emission will appear to rotate (angle patterns).",
"life: How long particles will be emitted for in seconds."];

// Particle behaviour
integer glow = TRUE;
integer bounce = FALSE;
integer interpColor = TRUE;
integer interpSize = TRUE;
integer wind = TRUE;
integer followSource = TRUE;
integer followVel = TRUE;

integer flags;

updateParticles()
{
key target;

flags = 0;
if (llList2String(var_cont, 1) == "owner") target = llGetOwner();
if (llList2String(var_cont, 1) == "self") target = llGetKey();
if (llList2String(var_cont, 1) == "NULL_KEY") target = "";
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 (llList2String(var_cont, 1) != "NULL_KEY") flags = flags | PSYS_PART_TARGET_POS_MASK;

llParticleSystem([ PSYS_PART_MAX_AGE,(float)llList2String(var_cont,2),
PSYS_PART_FLAGS,flags,
PSYS_PART_START_COLOR,(vector)llList2String(var_cont,8),
PSYS_PART_END_COLOR,(vector)llList2String(var_cont,9),
PSYS_PART_START_SCALE,(vector)llList2String(var_cont,10),
PSYS_PART_END_SCALE,(vector)llList2String(var_cont,11),
PSYS_SRC_PATTERN,(integer)llList2String(var_cont,0),
PSYS_SRC_BURST_RATE,(float)llList2String(var_cont,13),
PSYS_SRC_ACCEL,(vector)llList2String(var_cont,12),
PSYS_SRC_BURST_PART_COUNT,(integer)llList2String(var_cont,15),
PSYS_SRC_BURST_RADIUS,(float)llList2String(var_cont,14),
PSYS_SRC_BURST_SPEED_MIN,(float)llList2String(var_cont,4),
PSYS_SRC_BURST_SPEED_MAX,(float)llList2String(var_cont,3),
PSYS_SRC_TARGET_KEY,target,
PSYS_SRC_ANGLE_BEGIN,(float)llList2String(var_cont,17),
PSYS_SRC_ANGLE_END,(float)llList2String(var_cont,16),
PSYS_SRC_OMEGA,(vector)llList2String(var_cont,18),
PSYS_SRC_MAX_AGE,(float)llList2String(var_cont,19),
PSYS_SRC_TEXTURE,llGetInventoryKey(llList2String(var_cont,5)),
PSYS_PART_START_ALPHA,(float)llList2String(var_cont,6),
PSYS_PART_END_ALPHA,(float)llList2String(var_cont,7)
]);
}

integer emit = FALSE;

default
{
state_entry()
{
llSay(0, "Listening..");
llListen(0,"",llGetOwner(),"");
}

listen(integer channel, string name, key id, string message)
{
if (llGetSubString(message, 0, 1) == "EM")
{
list msg_list = llParseString2List(message, [" "], []);
if (llGetListLength(msg_list) >= 2)
{
string com = llList2String(msg_list, 1);

if (com == "go")
{
updateParticles();
llSay(0, "Emitting particles..");
emit = TRUE;
}
else if (com == "stop")
{
llParticleSystem([]);
llSay(0, "Stopping particle emission..");
emit = FALSE;
}
else if (com == "reset")
{
llParticleSystem([]);
llResetScript();
llSay(0, "Emitter Reset..");
}
else if (com == "status")
{
integer x;
integer list_len = llGetListLength(var_name);
for (x=0; x < list_len; x++)
{
llSay(0, "("+llList2String(var_type, x)+")" + llList2String(var_name, x) + " = " + llList2String(var_cont, x));
}

}
else if (com == "dump")
{
llInstantMessage(id, "Dumping variables to string...");
if (llGetListLength(msg_list) == 2) llInstantMessage(id, llDumpList2String(var_cont, "+"));
else if (llList2String(msg_list, 2) == "list") llInstantMessage(id, llDumpList2String(var_cont, ","));
llInstantMessage(id, "Dump complete!");
}
else if (com == "upload")
{
llSay(0, "Processing string...");
string new_vars = llList2String(msg_list, 2);
var_cont = llListReplaceList(var_cont, llParseString2List(new_vars, ["+"], []), 0, -1);
if (emit)
{
llParticleSystem([]);
updateParticles();
}
llSay(0, "Variables updated!");
}
else if (com == "help")
{
if (llGetListLength(msg_list) == 2)
{
llSay(0, "Particle Emitter script for perfecting particle system variables");
llSay(0, "For help of individual variables type: EM help <variable name>.");
llSay(0, "For further help on the particle system see: http://secondlife.com/badgeo/wakka.php?wakka=llParticleSystem");
llSay(0, "To start the emitter type EM go");
llSay(0, "To stop the emitter type EM stop");
llSay(0, "To reset the emitter type EM reset");
llSay(0, "For a list of variables type EM help list");
llSay(0, "To see current setup type EM status");
llSay(0, "To see single variable assignment type EM <variable name>");
llSay(0, "To change a variable type EM <variable name> <value>");
llSay(0, "To dump the variables to file for reuploading to continue adjusting type EM dump and save to a note");
llSay(0, "To dump a CSV of variables for use with the particle script in an object type EM dump list");
llSay(0, "To continue adjusting a previously saved variable copy from the notepad and type EM upload <+ seperated variable list>");
llSay(0, "------------------------------");
}
else if (llList2String(msg_list, 2) == "list")
{
llSay(0, "Listing editable variables...");
integer x;
integer list_len = llGetListLength(var_name);
for (x=0; x < list_len; x++)
{
llSay(0, "("+llList2String(var_type, x)+")" + llList2String(var_name, x));
}
}
else
{
integer listpos = llListFindList(var_name, llList2List(msg_list, 2, 2));
if (listpos != -1)
{
llSay(0, "Variable: " + llList2String(var_name, listpos));
llSay(0, llList2String(var_help, listpos));
}
else llSay(0, "Variable not found!");
}
}
else
{
integer listpos = llListFindList(var_name, llList2List(msg_list, 1, 1));
if (listpos != -1)
{
if (llGetListLength(msg_list) == 2)
{
llSay(0, "Variable: " + llList2String(var_name, listpos));
llSay(0, "Value: " + llList2String(var_cont, listpos));
llSay(0, "Type: " + llList2String(var_type, listpos));
}
else
{
string type = llList2String(var_type, listpos);
list parse = llList2List(msg_list, 2, -1);
string content = llDumpList2String(parse, " ");
llSay(0, content);
var_cont = llListReplaceList(var_cont, [content], listpos, listpos);
llSay(0, "Variable: " + llList2String(var_name, listpos) + " updated too value: " + llList2String(var_cont, listpos));
if (emit)
{
llParticleSystem([]);
updateParticles();
}
}

}
else llSay(0, "Variable not found!");

}
}
}
}
}


Simply drop this script into a prim along with any textures you might want to apply to the particles.

Once its there simply type "EM" followed by a command. EM help will give you a list of commands but they are as follows:

EM go : sets the particle system going and likewise
EM stop : stops it
EM reset : resets the script to its default state
EM status : shows all the current values for the variables
EM help : help text :P
EM help list : list the variables and their types
EM help <variable> : list detailed help for the variable
EM dump : dump the variables to a "+" seperated list that can be saved in a note card to come back to again later.
EM dump list : to dump the list directly as a csv to be dropped into the script below.
EM upload <+ seperated list> : upload a line of variables seperated by + that you saved before.
EM <variable> : display the current value for the variable.
EM <variable> <value> : update a value with a new variable, if the emitter is on it will restart with the new value.

to use the csv list use this code clipping:
CODE

// List of variable values
list var_cont = ["8", "", "2.0", "15.0", "10.0", "NULL_KEY", "1.0", "0.1", "<1,0.5,0.1>", "<1,0.5,0.1>", "<1,1,1>", "<0,0,0>", "<0,0,-1>", "0.0", "15.0", "100", "0.15", "0.05", "<0,0,0>", "0.0"]; // replace this list with your list from the above script.

// Particle behaviour
integer glow = TRUE;
integer bounce = FALSE;
integer interpColor = TRUE;
integer interpSize = TRUE;
integer wind = TRUE;
integer followSource = TRUE;
integer followVel = TRUE;

integer flags;

updateParticles()
{
key target;

flags = 0;
if (llList2String(var_cont, 1) == "owner") target = llGetOwner();
if (llList2String(var_cont, 1) == "self") target = llGetKey();
if (llList2String(var_cont, 1) == "NULL_KEY") target = "";
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 (llList2String(var_cont, 1) != "NULL_KEY") flags = flags | PSYS_PART_TARGET_POS_MASK;

llParticleSystem([ PSYS_PART_MAX_AGE,(float)llList2String(var_cont,2),
PSYS_PART_FLAGS,flags,
PSYS_PART_START_COLOR,(vector)llList2String(var_cont,8),
PSYS_PART_END_COLOR,(vector)llList2String(var_cont,9),
PSYS_PART_START_SCALE,(vector)llList2String(var_cont,10),
PSYS_PART_END_SCALE,(vector)llList2String(var_cont,11),
PSYS_SRC_PATTERN,(integer)llList2String(var_cont,0),
PSYS_SRC_BURST_RATE,(float)llList2String(var_cont,13),
PSYS_SRC_ACCEL,(vector)llList2String(var_cont,12),
PSYS_SRC_BURST_PART_COUNT,(integer)llList2String(var_cont,15),
PSYS_SRC_BURST_RADIUS,(float)llList2String(var_cont,14),
PSYS_SRC_BURST_SPEED_MIN,(float)llList2String(var_cont,4),
PSYS_SRC_BURST_SPEED_MAX,(float)llList2String(var_cont,3),
PSYS_SRC_TARGET_KEY,target,
PSYS_SRC_ANGLE_BEGIN,(float)llList2String(var_cont,17),
PSYS_SRC_ANGLE_END,(float)llList2String(var_cont,16),
PSYS_SRC_OMEGA,(vector)llList2String(var_cont,18),
PSYS_SRC_MAX_AGE,(float)llList2String(var_cont,19),
PSYS_SRC_TEXTURE,llGetInventoryKey(llList2String(var_cont,5)),
PSYS_PART_START_ALPHA,(float)llList2String(var_cont,6),
PSYS_PART_END_ALPHA,(float)llList2String(var_cont,7)
]);
}


Then you simply have to call updateParticles() from your script.


Hope its not too confusing, I'm pretty sure it could be a bit cleaner, and if anyone see's anything immediately wrong feel free to correct me :P.
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Thread
04-14-2006 09:00
/15/26/100139/1.html
_____________________
i've got nothing. ;)