Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Library: Melting Candle with moving wick

Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
10-21-2008 18:43
alrighty, this is my first time posting a script for the library, any comments, corrections, etc welcomed.

this is a set of scripts i worked up to give some candles a "melting" effect. it basically shrinks the candle along the z axis and keeps the bottom fixed (the way it should be lol). the second 2 scripts are for the wick (if it's a seperate prim). it listens for a link message from the candle and moves to keep it's position relative to the candle. and the last is just a basic candle flame that i got from another thread. i'm providing 2 scripts for the wick movement because they act slightly different depending if the candle is the root prim or not

Melt Script
From: someone

//Melting Candle Script
//Written by Ruthven Willenov
//Use as desired
//all the owner say calls are for testing and debugging purposes, remove or comment out if you don't want them there
integer on = 1;
vector startscale;
vector startpos;
float meltpercent = 0.05;
float melt;//calculated in the default state entry, this is the result of the percent from above from the scale of the candle IE: 5% of 0.200 is 0.010, if the result is smaller, it will not function correctly. raise/lower the percent accordingly
float delay = 1.0;//how many seconds between each "melt" 1 second is for testing, i recommend 60 seconds between each melt

startover(){//puts the candle back where it started
llOwnerSay("scale and positon reset";);
llSetScale(startscale);
llSetPos(startpos);
llMessageLinked(LINK_SET,0, "startover","";);//tells the wick the candle has restarted
}

default {
state_entry() {
startscale = llGetScale();
startpos = llGetLocalPos();
melt = startscale.z * meltpercent;//this is how much it will shrink along the z axis for each "melt", it will also be the ending scale on the z axis before the candle restarts
llMessageLinked(LINK_SET, 0,"candlereset","";);//tells the wick the candle has been reset
llOwnerSay("new start scale and position saved";);
llOwnerSay("melt amount is " + (string) melt + ". if it is smaller than 0.010, the script will not function correctly";);
}
touch_start(integer total_number) {
if (on) {
llSetTimerEvent(delay);//turns on the timer for the melt action
llOwnerSay("melt on";);
}
else {
llOwnerSay("melt off";);
llSetTimerEvent(0.0);//turns off the timer
startover();//puts candle back where it started
}
on = !on;
}
timer() {
vector scale = llGetScale();
if (scale.z <= melt) {
startover();//start over if the scale on the z axis is smaller than the melt amount

}
else {//otherwise continue melting
llSetScale(llGetScale() - <0.0,0.0,melt>;);//shrinks the z axis by the melt amount
llSetPos(llGetLocalPos() - <0.0,0.0,melt/2> * llGetLocalRot());//moves the candle down the z axis by half of the melt amount
llMessageLinked(LINK_SET,0, "melted " + (string)melt,"";);//tells the wick the candle has melted and how much
llOwnerSay("melted";);
}
}
changed(integer change)
{
if (change & CHANGED_LINK)//used for testing between candle being the root or a child prim, remove this event if desired
llResetScript();
}
}


Wick Script 1
From: someone

//this one is for when the candle is NOT the root prim
//IE: if you have the candle on a base
vector startpos;

startover(){
llOwnerSay("moved back to start pos";);
llSetPos(startpos);
}

default {
state_entry()
{
startpos = llGetLocalPos();
llOwnerSay("new start position saved";);
}
link_message(integer sender_num,integer num, string str, key id)
{
if (llGetSubString(str,0,5) == "melted";)//if the beginning of the message is "melted"
{
llSetPos(llGetLocalPos() - <0.0,0.0,(float) llGetSubString(str,7,-1)> * llGetLocalRot());//moves the wick down the z axis by the amount given at the end of the message
}
else if (str == "startover";)
{
startover();//if the candle says it start over, the wick needs to start over as well
}
else if (str == "candlereset";)//reset this script if the candle script has reset (in case the candle was moved or a link was changed)
{
llResetScript();
}
}
}


Wick Script 2
From: someone

//this one acts the same was as the one above except it moves the wick by half of the amount given to it.
//this is for when the candle is the root prim

vector startpos;

startover(){
llOwnerSay("moved back to start pos";);
llSetPos(startpos);
}

default {
state_entry()
{
startpos = llGetLocalPos();
llOwnerSay("new start position saved";);
}
link_message(integer sender_num,integer num, string str, key id)
{
if (llGetSubString(str,0,5) == "melted";)//if the beginning of the message is "melted"
{
llSetPos(llGetLocalPos() - <0.0,0.0,(float) llGetSubString(str,7,-1)/2> * llGetLocalRot());//moves the wick down the z axis by half of the amount given at the end of the message
}
else if (str == "startover";)
{
startover();//if the candle says it start over, the wick needs to start over as well
}
else if (str == "candlereset";)//reset this script if the candle script has reset (in case the candle was moved or a link was changed)
{
llResetScript();
}
}
}


Candle Flame Script
From: someone

default
{
state_entry()
{
llParticleSystem([
PSYS_PART_FLAGS, 0x103,
PSYS_SRC_PATTERN, 0x004,
PSYS_PART_START_ALPHA, 1.00,
PSYS_PART_END_ALPHA, 0.500,
PSYS_PART_START_COLOR, <1.00,1.00,0.00>,
PSYS_PART_END_COLOR, <1.00,0.00,0.00>,
PSYS_PART_START_SCALE, <0.06,0.08,0.00>,
PSYS_PART_END_SCALE, <0.01,0.01,0.00>,
PSYS_PART_MAX_AGE, 0.70,
PSYS_SRC_MAX_AGE, 0.00,
PSYS_SRC_ACCEL, <0.00,0.00,0.04>,
PSYS_SRC_ANGLE_BEGIN, 0.00,
PSYS_SRC_ANGLE_END, 0.09,
PSYS_SRC_BURST_PART_COUNT, 1,
PSYS_SRC_BURST_RADIUS, 0.001,
PSYS_SRC_BURST_RATE, 0.05,
PSYS_SRC_BURST_SPEED_MIN, 0.09,
PSYS_SRC_BURST_SPEED_MAX, 0.13,
PSYS_SRC_OMEGA, <0.00,0.00,0.00>,
PSYS_SRC_TEXTURE, "b708e484-aeef-8cc9-3896-dd661d4e6807"
]);
}
}
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Abraxes Binder
Registered User
Join date: 23 May 2008
Posts: 205
10-23-2008 07:49
Nice idea :)
Im sure this will be handy for several people

BR
ab
_____________________
BR ab
Dekka Raymaker
thinking very hard
Join date: 4 Feb 2007
Posts: 3,898
10-23-2008 09:02
very nice, I am sure I can make a work of art using this, thanks.
Lectrici Vlodovic
Registered User
Join date: 28 Jun 2008
Posts: 3
01-21-2009 06:16
I am using a torus as the candle and need to change the melt axis from z to x. Not having any scripting experience, what changes to the above candle script do I need to make? I tried changing all "Z" references to "X" but the candle still melts sideways instead of down.

I realize that by using a torus and rotating it I changed the axis, but I would like to get that hollow effect at the base of the flame.

Thanks in advance
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
01-21-2009 06:38
are you saying the wick is moving sideways or the candle is? i just tried it with a torus candle and made the root an odd rotation and it worked fine

edit: if you're using the wick script:
make sure the axises you used are aligned, the wick can use it's z axis as long as it is aligned with the x. axis of the torus. the script moves the prim along it's own axis regardless of it's rotation, or the rotation of the other prims in the object

edit2: i think i see what you mean, you in the timer event you need to change

From: someone

llSetScale(llGetScale() - <0.0,0.0,melt>;);//shrinks the z axis by the melt amount
llSetPos(llGetLocalPos() - <0.0,0.0,melt/2> * llGetLocalRot());//moves the candle down the z axis by half of the melt amount


into

From: someone

llSetScale(llGetScale() - <melt,0.0,0.0>;);//shrinks the x axis by the melt amount
llSetPos(llGetLocalPos() - <melt/2,0.0,0.0> * llGetLocalRot());//moves the candle down the x axis by half of the melt amount
Lectrici Vlodovic
Registered User
Join date: 28 Jun 2008
Posts: 3
01-21-2009 06:59
From: Ruthven Willenov
are you saying the wick is moving sideways or the candle is? i just tried it with a torus candle and made the root an odd rotation and it worked fine

edit: if you're using the wick script:
make sure the axises you used are aligned, the wick can use it's z axis as long as it is aligned with the x. axis of the torus. the script moves the prim along it's own axis regardless of it's rotation, or the rotation of the other prims in the object

edit2: i think i see what you mean, you in the timer event you need to change



into



what is happening is:

When I used a cylinder as the candle, the candle melted downwards from the top down. i.e. the height of the cylinder changed. When I used a torus as the candle, I had to rotate it to get the dimpled end in the up position. When it burns, the width of the torus changes, getting skinnier instead of shorter. It was late last night when I was playing with this and maybe I needed to use the y axis instead. I'm at work right now (ssshhh don't tell anyone) so I can't try any changes at the moment.

The wick seems to be fine and remains centered on the candle.
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
01-21-2009 07:35
i reworked the script a little to simplify the desired axis

CODE

//Melting Candle Script
//Written by Ruthven Willenov
//Use as desired
//all the owner say calls are for testing and debugging purposes, remove or comment out if you don't want them there
string axis = "x";//change this to the axis you need, accepts upper or lower case

integer on = 1;
integer highendfixed = FALSE;//change to TRUE or FALSE to make the candle move up or down along the axis

vector startscale;
vector startpos;
vector melt;
vector move;

float meltpercent = 0.05;
float MELT;
float delay = 1.0;

startover(){
llOwnerSay("scale and positon reset");
llSetPrimitiveParams([PRIM_SIZE,startscale,PRIM_POSITION,startpos]);
llMessageLinked(LINK_SET,0, "startover","");
}

default {
state_entry() {
startscale = llGetScale();
startpos = llGetLocalPos();
if(llToLower(axis) == "z")
{
MELT = startscale.z * meltpercent;
melt = <0.0,0.0,MELT>;
move = <0.0,0.0,MELT/2>;
}
else if (llToLower(axis) == "y")
{
MELT = startscale.y * meltpercent;
melt = <0.0,MELT,0.0>;
move = <0.0,MELT/2,0.0>;
}
else if (llToLower(axis) == "x")
{
MELT = startscale.x * meltpercent;
melt = <MELT,0.0,0.0>;
move = <MELT/2,0.0,0.0>;
}
if (!highendfixed)
{
move = -move;
}
llMessageLinked(LINK_SET, 0,"candlereset","");
llOwnerSay("new start scale and position saved");
llOwnerSay("melt amount is " + (string) melt + ". if it is smaller than 0.010, the script will not function correctly");
}
touch_start(integer total_number) {
if (on) {
llSetTimerEvent(delay);
llOwnerSay("melt on");
}
else {
llOwnerSay("melt off");
llSetTimerEvent(0.0);
startover();
}
on = !on;
}
timer() {
vector scale = llGetScale();
float curr;
if (llToLower(axis) == "z"){curr = scale.z;}
else if (llToLower(axis) == "y"){curr = scale.y;}
else if (llToLower(axis) == "x"){curr = scale.x;}
if (curr <= MELT) {
startover();
}

else {
llSetPrimitiveParams([PRIM_SIZE,llGetScale() - melt,PRIM_POSITION,llGetLocalPos() - move * llGetLocalRot()]);
llMessageLinked(LINK_SET,0, "melted " + (string)melt,"");
llOwnerSay("melted");
}
}
changed(integer change)
{
if (change & CHANGED_LINK)
llResetScript();
}
}
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Lectrici Vlodovic
Registered User
Join date: 28 Jun 2008
Posts: 3
01-21-2009 17:41
Thank you. It is working now. Now I just have to figure out what I'm going to do with the candle lantern I made (smile).