How do i add timer on lights?
by Melker Simonsson · in Torque 3D Beginner · 02/16/2015 (5:26 pm) · 8 replies
Hi!
I just wonder if its possible to add a timer for point lights?
I want the lights to go on when its starts to get night, just like street lights in real life.
I tried to do an animation on it but i have a hard time getting it to match the "time of the day" cycle. Sometimes it´s perfect next time i go in-game its way off.
Is it anyway to sett a trigger that starts the animations of the lights so it will match the tod cycle?
Or if its possible, that it follows the time of the tod cycle.
//Melker S
I just wonder if its possible to add a timer for point lights?
I want the lights to go on when its starts to get night, just like street lights in real life.
I tried to do an animation on it but i have a hard time getting it to match the "time of the day" cycle. Sometimes it´s perfect next time i go in-game its way off.
Is it anyway to sett a trigger that starts the animations of the lights so it will match the tod cycle?
Or if its possible, that it follows the time of the tod cycle.
//Melker S
#2
02/17/2015 (3:02 am)
Thanks Jason! I will check it out :)
#3
Or rather where do i put it in?
I tested to do a folder called "script" and made a .cs file that was named "onAdd.cs" with this script in it.
When i rightclick on the "tod" > inspect > Methods > scripted i can see the onAdd() right there and the search way is right.
But it wont work.
I have tried to find an answer on the documentations and getting started and so on, but with no success.
Do someone know what is the problem?
(sorry if I´m dumb, but I´m new to this)
function TimeOfDay::onAdd( %this )
{
%this.addTimeOfDayEvent( 0, "Sunrise" );
%this.addTimeOfDayEvent( 180, "Sunset" );
}
function TimeOfDay::onTimeEvent( %this, %identifier, %currentTime, %currentElevation )
{
echo( %identifier );
%lightsEnabled = ( ( %identifier $= "Sunrise" ) ? false : true );
if ( isObject( DynamicLights ) )
DynamicLights.setAllLightsEnabled( %lightsEnabled );
if ( isObject( MissionLights ) )
MissionLights.setAllLightsEnabled( %lightsEnabled );
}
function SimSet::setAllLightsEnabled( %this, %enabled )
{
for ( %i = 0; %i < %this.getCount(); %i++ )
{
%light = %this.getObject( %i );
%light.setLightEnabled( %enabled );
}
}
02/17/2015 (1:37 pm)
Cant get it to work. Or rather where do i put it in?
I tested to do a folder called "script" and made a .cs file that was named "onAdd.cs" with this script in it.
When i rightclick on the "tod" > inspect > Methods > scripted i can see the onAdd() right there and the search way is right.
But it wont work.
I have tried to find an answer on the documentations and getting started and so on, but with no success.
Do someone know what is the problem?
(sorry if I´m dumb, but I´m new to this)
function TimeOfDay::onAdd( %this )
{
%this.addTimeOfDayEvent( 0, "Sunrise" );
%this.addTimeOfDayEvent( 180, "Sunset" );
}
function TimeOfDay::onTimeEvent( %this, %identifier, %currentTime, %currentElevation )
{
echo( %identifier );
%lightsEnabled = ( ( %identifier $= "Sunrise" ) ? false : true );
if ( isObject( DynamicLights ) )
DynamicLights.setAllLightsEnabled( %lightsEnabled );
if ( isObject( MissionLights ) )
MissionLights.setAllLightsEnabled( %lightsEnabled );
}
function SimSet::setAllLightsEnabled( %this, %enabled )
{
for ( %i = 0; %i < %this.getCount(); %i++ )
{
%light = %this.getObject( %i );
%light.setLightEnabled( %enabled );
}
}
#4
Hopefully I can help get this working tonight.
02/17/2015 (4:03 pm)
I think it might go in gamecore.cs, gamecore::onMissionLoaded.Hopefully I can help get this working tonight.
#5
I´m Making a race track on BeamNG drive that uses this game engine. The only thing i have left is getting this lights to start when it gets dark.
skype name: melkerfox
02/17/2015 (5:02 pm)
That would be awesome Jason. I´m Making a race track on BeamNG drive that uses this game engine. The only thing i have left is getting this lights to start when it gets dark.
skype name: melkerfox
#6
You were on the right track. I just made a new .cs file in scripts/server. I called it dynamicLights.cs but it can be anything. Open scriptExec.cs, of course and add:
exec("./dynamicLights.cs");
The time of day events are added when the TimeOfDay object is added to the level. It doesn't matter what you name your Time of Day object from the Library/Level/Level but I added it and called it TimeODay.
James set this to affect SimGroups containing the lights. So I added two SimGroups from Library/Level/System in the Scene Tree. I named the SimGroups, DynamicLights and MissionLights. I then dropped some lights in the level and dragged them into the folders and it just works. You don't need to name the lights anything special since it is looking for the SimGroup names specified in the code.
This is a very nice bit of script and can most likely be used as a framework to do all kinds of dynamic things like change the ambient sounds to night-time and what not.
02/17/2015 (6:46 pm)
Okay, got it. Great piece of code here by James Ford.You were on the right track. I just made a new .cs file in scripts/server. I called it dynamicLights.cs but it can be anything. Open scriptExec.cs, of course and add:
exec("./dynamicLights.cs");
The time of day events are added when the TimeOfDay object is added to the level. It doesn't matter what you name your Time of Day object from the Library/Level/Level but I added it and called it TimeODay.
James set this to affect SimGroups containing the lights. So I added two SimGroups from Library/Level/System in the Scene Tree. I named the SimGroups, DynamicLights and MissionLights. I then dropped some lights in the level and dragged them into the folders and it just works. You don't need to name the lights anything special since it is looking for the SimGroup names specified in the code.
This is a very nice bit of script and can most likely be used as a framework to do all kinds of dynamic things like change the ambient sounds to night-time and what not.
#7
02/18/2015 (4:30 am)
Yes!! Thank you Jason! Now i can finally release the track! :D
#8
02/18/2015 (6:03 am)
No problem.
Jason Campbell
www.garagegames.com/community/forums/viewthread/107155/1