Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

llParticleSystem() -- some favorite tricks

Jopsy Pendragon
Perpetual Outsider
Join date: 15 Jan 2004
Posts: 1,906
09-07-2006 09:41
(I'm tired of the deathoftheforumdrama threads and felt like posting something different for a change)

Just some random particle script shortcuts I use often:

Setting up a simple "touch" on/off switch, with an auto-off timer.
CODE

default {
state_entry() {
llParticleSystem( [
// (your particle definition here )
] );
// llResetTime(); // edited - completely unnecessary, see next posts
llSetTimerEvent( 5.0 * 60.0 ); // 5 minute auto-off internval.
}

on_rez(integer n) { llResetScript(); }

touch_start(integer num_detected) { state particles_off; }

timer() { state particles_off; }

state_exit() { llParticleSystem( [ ] ); } // turns off particles
}


state particles_off {
touch_start( integer num_detected ) { state default; }
}


To automatically use the first texture in the prim's inventory for the particle effect:

CODE

default {
state_entry() {

string texture = "";

if ( llGetInventoryNumber( INVENTORY_TEXTURE ) > 0 )
texture = llGetInventoryName( INVENTORY_TEXTURE, 0 );

llParticleSystem( [
// (your particle definitions here and... ),
PSYS_SRC_TEXTURE, texture
] );
}

changed(integer change_type) {
// start over if prim's inventory changes
if ( change_type & CHANGED_INVENTORY ) { llResetScript(); }
}
}


Want a prim to target the parent object it's linked to?
Don't use listens! Try this:

CODE

default {
state_entry() {
key target = NULL_KEY;
if ( llGetLinkNumber() > 1 ) target = llGetLinkKey( 1 );

llParticleSystem( [
// (your particle definitions here ),
// PSYS_PART_FLAGS, (your flags)
| PSYS_PART_TARGET_POS_MASK,
PSYS_SRC_TARGET_KEY, target
] );
}

changed(integer change_type) {
// start over if the object's links change
if ( change_type & CHANGED_LINK ) { llResetScript(); }
}

on_rez(integer n) { llResetScript(); }
}


If you want to target a child prim of the object (instead of the parent prim), replace the 1 in llGetLinkKey(1) with the # of the child prim. You can get the child prim to tell you it's link number with: llOwnerSay( llGetLinkNumber() );
_____________________
* The Particle Laboratory * - One of SecondLife's Oldest Learning Resources.
Free particle, control and targetting scripts. Numerous in-depth visual demonstrations, and multiple sandbox areas.
-
Stop by and try out Jopsy's new "Porgan 1800" an advanced steampunk styled 'particle organ' and the new particle texture store!
Kayla Stonecutter
Scripting Oncalupen
Join date: 9 Sep 2005
Posts: 224
09-07-2006 13:38
Just one minor little thing I noticed: llResetTime() has nothing to do with the timer event. All it does is reset the running time of the script for use with llGetTime(). :)
_____________________
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
09-07-2006 19:20
may i add llResetTime / llGetTime / llGetAndResetTime are not things to be using for "mission critical" things

wiki
From: someone

Gets the time in seconds since the last script reset, or since the time was last reset (or when the server resets, or when the system decides to reset the time unexpectedly. Basically, don't use this function for anything!).


while true, i think that statement is abit harsh, and it does have its uses (altho not many)
Jopsy Pendragon
Perpetual Outsider
Join date: 15 Jan 2004
Posts: 1,906
09-08-2006 01:37
From: Osgeld Barmy
may i add llResetTime / llGetTime / llGetAndResetTime are not things to be using for "mission critical" things

wiki


while true, i think that statement is abit harsh, and it does have its uses (altho not many)


Like detecting when the last time the server was reset perhaps! :)

Kayla/Osgeld- You're absolutely right: llResetTime() has no impact at all on llSetTimerEvent(). I'd started using it in error when I thought I was seeing event() being called immediately after setting an llSetTimerEvent(n), or called in less than 'n' seconds from being set, and figured llSetTimerEvent() was doing modulus operation on llGetTime(). Oops :)

Anyway, myth dispelled, thanks for pointing that out!! =)
_____________________
* The Particle Laboratory * - One of SecondLife's Oldest Learning Resources.
Free particle, control and targetting scripts. Numerous in-depth visual demonstrations, and multiple sandbox areas.
-
Stop by and try out Jopsy's new "Porgan 1800" an advanced steampunk styled 'particle organ' and the new particle texture store!