The Ultimate Dynamic Light Script

Posted By: Orange Brat

The Ultimate Dynamic Light Script - 02/19/05 12:57

In its current form, this script REQUIRES any version of 3DGS with the stencil shadow feature. Even if you set the "castToggle" to "on", you'll need to be sure to set the "cast" flag of each entity whose shadow should be influenced by these lights to "on", as well. Also, make sure the "shadow_stencil" flag is set to "on" to enable stencil shadows or none of the shadow eyecandy will work to begin with.

I guess if you take out the "cast" part, at the beginning, it should work with older versions of A6. I don't know if there are any other instructions that are native to A6 only, but if not then you can use it with A5 after removal of those shadows sections. Possible candidates are "vec_dist" and "sleep". You can substitute "sleep" with "waitt"(for conversion purposes, sleep(1) is equal to waitt(16)) and you can probably figure out an alternative for "vec_dist" if it isn't a part of A5's instruction set.

This script should fulfill your every need except movement.

Code:

var killSwitch = 0; //0 = all lights active, 1 = all lights inactive
define range, skill1; //lightrange for this light
define rangeModifier, skill2; //used for random lightrange calculation...if random lights used, DO NOT set to 0 or script will crash
define redColor, skill3; //red color for this light
define greenColor, skill4; //green color for this light
define blueColor, skill5; //blue color for this light
define distToggle, skill6; //distance to toggle on/off lightrange...uses vec_dist(player.x, my.x)
define startDelay, skill7; //if > 0 then light object is invisible for this value in seconds at level start
//only use with constant blinking lights..unexpected results may occur with random blinkers
//this will only take affect if beginOn is true
define shortDelay, skill8; //shorter of two delays for blink
define longDelay, skill9; //longer of two delays for blink
//make short/long delays equal for a true constant light
//for example: 2 sec. on, 2 sec. off

define castToggle, flag1; //on = influence stencil shadow
define beginOn, flag2; //on = light object will be visible at level start unless startDelay > 0
//off = light object invisible at level start
define alwaysOn, flag3; //on = light is always on regardless of player's position from lightsource
define randomColorRange, flag4; //on = light will always be a random color and lightrange
//off = light is constant color & lightrange
define blink, flag5; //on = light will blink; off = light will not blink
define randBlink, flag6; //on = light will blink at a random rate if true...blink must be true
define localSwitch, flag7; //on = light is on; off = light is off



Code:

// uses: range, rangeModifier, redColor, greenColor, blueColor, distToggle
// uses: startDelay, shortDelay, longDelay, castToggle, beginOn, alwaysOn
// uses: randomColorRange, blink, randBlink, localSwitch
action dynamicLight //assign to a dynamic light entity
{
while(player == null) { wait(1); }
var tempShortDelay;
var tempLongDelay;
my.passable = on;
if(my.castToggle == on) //light will influence stencil shadows
{
my.cast = on;
}
else
{
my.cast = off;
}
while(1)
{
if(killSwitch == 0 && my.localSwitch == on)
{
if(my.beginOn == on) //light object is visible at level start, unless startDelay > 0
{
if(my.startDelay > 0) //useful for scrolling lights on marquees
{ //should ONLY be used with constant blinkers
sleep(my.startDelay); //you may experience unexpected results if you use with random blinkers
}
my.invisible = off;
}
else
{
my.invisible = on; //light object is invisible at level start
}
if((vec_dist(player.x, my.x) < my.distToggle && my.alwaysOn == off) ||
(my.alwaysOn == on)) //distance based and non-distance based/always on lights
{
if(my.randomColorRange == on) //random color and range
{
my.lightrange = max(random(my.range), my.range/my.rangeModifier); //make sure rangeModifier > 0
if(my.lightrange == 0) { my.lightrange = 1; }
my.red = int(random(my.redColor));
if(my.red == 0) { my.red = 1; }
my.green = int(random(my.greenColor));
if(my.green == 0) { my.green = 1; }
my.blue = int(random(my.blueColor));
if(my.blue == 0) { my.blue = 1; }
}
else //constant color and range
{
my.lightrange = my.range;
my.red = my.redColor;
my.green = my.greenColor;
my.blue = my.blueColor;
}
if(my.blink == on) //light will blink with 2 separate delays
{
if(my.randBlink == on) //random blinking
{
tempShortDelay = random(my.shortDelay);
if(tempShortDelay == 0) { tempShortDelay = 0.1; }
sleep(tempShortDelay); //shorter delays
my.lightrange = 0;
if(my.beginOn == on) //light object is now invisible
{
my.invisible = on;
}
tempLongDelay = random(my.longDelay);
if(tempLongDelay == 0) { tempLongDelay = 0.1; }
sleep(tempShortDelay + tempLongDelay); //longer delays
}
else //constant blinking
{
sleep(my.shortDelay); //shorter delays
my.lightrange = 0;
if(my.beginOn == on) //light object is now invisible
{
my.invisible = on;
}
sleep(my.longDelay); //longer delays
my.startDelay = 0; //zero out so it won't delay again
//after initial delay at level start..
//..only applies to constant blinkers
}
}
}
else //player is > my.distToggle from lightsource..turn light off and make object invisible
{
my.lightrange = 0;
my.invisible = on;
}
}
else
{
my.lightrange = 0;
my.invisible = on;
}
wait(1);
}
}


Posted By: Braxton

Re: The Ultimate Dynamic Light Script - 02/19/05 13:16

Wow, tons better than mine!
Posted By: ISG

Re: The Ultimate Dynamic Light Script - 02/19/05 13:18

Braxton, you seem suprised

Thanks for this contribution OB
Posted By: Orange Brat

Re: The Ultimate Dynamic Light Script - 02/19/05 13:19

Sorry for stepping on your script. I had thought about waiting a few days, but I was ready to post it. Here's Braxton's script for those who might want to use it instead:

http://www.conitecserver.com/ubbthreads/showflat.php?Cat=&Number=486436

It's somewhat similar, but not quite as flexible. Still, if that's all you need and script execution time is a factor......
Posted By: Braxton

Re: The Ultimate Dynamic Light Script - 02/19/05 13:26

i am not, just was surprised to see a better one so fast. The only difference between our scripts is that mine is editable in the behavior panel. His is still way better.

I have run into a problem. I can't get it to run... it says 'ultimateDynamicLigh' action not found. so I copy the 'ultimateDynamicLight' script and rename it 'ultimateDynamicLigh'. then when I build and run nothing is different.

BTW Orange Brat - It is ok, you didn't step all over my script. When someones script is better, it is better and you can't argue.
Posted By: Orange Brat

Re: The Ultimate Dynamic Light Script - 02/19/05 13:31

I think there might be a length limit for action/function names, since I've run into that problem before. I went ahead and renamed it to "dynamicLight".
Posted By: Anonymous

Re: The Ultimate Dynamic Light Script - 02/20/05 12:40

I think the limit is 15 characters for actions, but I may be wrong.
Posted By: Orange Brat

Re: The Ultimate Dynamic Light Script - 02/22/05 12:13

Made a small change which will allow you to see the "defined" skill and flag names in WED's behavior panel. Just copy & paste the three "// uses: " lines right before the action and add them to the same spot in your own code. I also changed the red, green, and blue defines to redColor, greenColor, and blueColor. This was done to eliminate any potential conflicts with the built in c-script instructions of the same name.
Posted By: Thomas_Nitschke

Re: The Ultimate Dynamic Light Script - 02/25/05 22:07

Hey, this is a nice contribution!
From now on, we don't have to re-invent the wheel all the time
Concerning the character-limits question: As fas as I know, there's still a limit of 8 characters for actions, although the limit fpr functions is much higher. Shame on you, Conitec, the times of DOS are over!
Posted By: Orange Brat

Re: The Ultimate Dynamic Light Script - 02/26/05 05:05

Added a light switch toggle. Required a new flag(#7) and an addition to a single line right after the "while". Don't forget to add the flag name to the "uses" section.
Posted By: Greenmonkey824

Re: The Ultimate Dynamic Light Script - 03/28/05 05:38

Quote:


This script should fulfill your every need except movement.





Meaning if the entity I attach the light to moves, the script won't work?
Posted By: Orange Brat

Re: The Ultimate Dynamic Light Script - 03/28/05 08:06

If you attach it to something then of course it will move. I meant that my script doesn't provide any built in movement.
Posted By: oliver2s

Re: The Ultimate Dynamic Light Script - 03/28/05 08:19

Does the script works right in this situation: You have 10 dynamic lights very near behind the camera. And you have 2 dynamic light far away in front of the camera. Does the script switch on the 2 light in front of?
Posted By: Orange Brat

Re: The Ultimate Dynamic Light Script - 03/28/05 08:41

It doesn't take into account what's in the view. You can either have an always on light or one that can be switched on and off depending on how far away it is from the player(using vec_dist).

Code:

if((vec_dist(player.x, my.x) < my.distToggle && my.alwaysOn == off) ||(my.alwaysOn == on))


Posted By: prophet

Re: The Ultimate Dynamic Light Script - 07/01/05 20:26

Why am I getting an error with the cast being an undefined variable?
Posted By: AndrewSwallow

Re: The Ultimate Dynamic Light Script - 07/01/05 20:46

Is there a screenshot you can post so everyone can see without setting it up?

thanks
andrewds
Posted By: Orange Brat

Re: The Ultimate Dynamic Light Script - 07/01/05 20:49

Quote:

Why am I getting an error with the cast being an undefined variable?




The my.cast part? Make sure you have the newest version of A6.
Posted By: Neuro

Re: The Ultimate Dynamic Light Script - 07/01/05 23:18

I cant seem to get any light to show up. Is there a specific settings I'm suppose to have?
Posted By: prophet

Re: The Ultimate Dynamic Light Script - 07/03/05 04:45

Need to probably remove the random code and have my.lightrange = 100 or something like that.
Posted By: prophet

Re: The Ultimate Dynamic Light Script - 07/03/05 04:51

I was wrong, I am trying to figure that out now. Got the cast fixed with an update though.
Posted By: Orange Brat

Re: The Ultimate Dynamic Light Script - 07/03/05 04:51

There's no reason to change anything given it has both a random path and a constant one. If you don't want randomness, then set the appropriate flag/skill, and set a range to whatever you want.

Code:

define range, skill1; //lightrange for this light
define randomColorRange, flag4; //on = light will always be a random color and lightrange
//off = light is constant color & lightrange
define blink, flag5; //on = light will blink; off = light will not blink
define randBlink, flag6; //on = light will blink at a random rate if true...blink must be true



I don't know why it wouldn't show up. It works, and I've been using this script in one form or another for years. Maybe one of the defined flag/skills is getting overridden in your other code? It could also have something to do with "distToggle" or "alwaysOn".
Posted By: prophet

Re: The Ultimate Dynamic Light Script - 07/03/05 05:08

I now kiss your royal feet and praise your greatness. I aplogize for my ignarance to not read your comments in the code or my impatience for not thinking of right clicking my light and clicking behavior instead of properties.


Thanks for the great code. I will fine tune the setting and it will work nicely.
Posted By: Orange Brat

Re: The Ultimate Dynamic Light Script - 07/03/05 05:15

No need to get all mushy I try to make the comments at least halfway understandable, so I'm glad you finally got it figured out. At first, it appears to be a convuluted looking monster, but it is really a very simple function.
© 2024 lite-C Forums