Basically, I have an animated flat ride that I want to include bound lights when the ride vehicle moves on the tower.
Any help?
import com.nolimitscoaster.*;
import nlvm.math3d.*;
/**
* This script simulates a simple light, that switches on when the sun sets
*/
public class QuattroLightScript extends Script
{
private static final String c_aLightSourceName = "thelight1";
private static final String c_bLightSourceName = "thelight2";
private static final String c_cLightSourceName = "thelight3";
private static final String c_dLightSourceName = "thelight4";
private static final double c_fSwitchOnAngle = 18.0; // degrees
private static final float c_fMaxInitialDelay = 0.6f; // seconds
private static final float c_fSwitchOnTime = 10.0f; // seconds
private static final float c_fSwitchOffTime = 1.3f; // seconds
private static final float c_fStartBrightness = 0.2f;
private SceneObjectLight m_aLight;
private SceneObjectLight m_bLight;
private SceneObjectLight m_cLight;
private SceneObjectLight m_dLight;
private SceneObject m_aSCO;
private float m_fInitialDelayTime;
private float m_fCurBrightness;
private float m_fNewBrightness;
private float m_fElevationLimit;
private Vector3f m_aOrgColor;
private Vector4f m_aEntCol;
private bool m_bEnabled;
public bool onInit()
{
m_aSCO = sim.getSceneObjectForEntityId(getParentEntityId());
m_aLight = m_aSCO.getLightForName(c_aLightSourceName);
m_bLight = m_aSCO.getLightForName(c_bLightSourceName);
m_cLight = m_aSCO.getLightForName(c_cLightSourceName);
m_dLight = m_aSCO.getLightForName(c_dLightSourceName);
if (m_aLight == null)
{
System.err.println("Scene object has no light with name '" + c_aLightSourceName + "'");
return false;
}
m_fCurBrightness = 0;
m_fNewBrightness = 0;
m_aLight.setEnabled(false);
m_bEnabled = false;
m_aOrgColor = new Vector3f();
m_aLight.getColor(m_aOrgColor);
m_aEntCol = new Vector4f(1,1,1,0);
m_fElevationLimit = (float)Math.toRadians(c_fSwitchOnAngle);
m_fInitialDelayTime = (float)Math.random() * c_fMaxInitialDelay;
if (m_bLight == null)
{
System.err.println("Scene object has no light with name '" + c_bLightSourceName + "'");
return false;
}
m_fCurBrightness = 0;
m_fNewBrightness = 0;
m_bLight.setEnabled(false);
m_bEnabled = false;
m_aOrgColor = new Vector3f();
m_bLight.getColor(m_aOrgColor);
m_aEntCol = new Vector4f(1,1,1,0);
m_fElevationLimit = (float)Math.toRadians(c_fSwitchOnAngle);
m_fInitialDelayTime = (float)Math.random() * c_fMaxInitialDelay;
if (m_cLight == null)
{
System.err.println("Scene object has no light with name '" + c_cLightSourceName + "'");
return false;
}
m_fCurBrightness = 0;
m_fNewBrightness = 0;
m_cLight.setEnabled(false);
m_bEnabled = false;
m_aOrgColor = new Vector3f();
m_cLight.getColor(m_aOrgColor);
m_aEntCol = new Vector4f(1,1,1,0);
m_fElevationLimit = (float)Math.toRadians(c_fSwitchOnAngle);
m_fInitialDelayTime = (float)Math.random() * c_fMaxInitialDelay;
if (m_dLight == null)
{
System.err.println("Scene object has no light with name '" + c_bLightSourceName + "'");
return false;
}
m_fCurBrightness = 0;
m_fNewBrightness = 0;
m_dLight.setEnabled(false);
m_bEnabled = false;
m_aOrgColor = new Vector3f();
m_dLight.getColor(m_aOrgColor);
m_aEntCol = new Vector4f(1,1,1,0);
m_fElevationLimit = (float)Math.toRadians(c_fSwitchOnAngle);
m_fInitialDelayTime = (float)Math.random() * c_fMaxInitialDelay;
return true;
}
public void onNextFrame(float tick)
{
bool bEnable = sim.getCurSunElevation() <= m_fElevationLimit;
if (bEnable != m_bEnabled)
{
if (bEnable)
{
// switching on
m_fCurBrightness = c_fStartBrightness;
m_fNewBrightness = 1.0f;
m_bEnabled = true;
}
else
{
// switching off
m_fNewBrightness = 0.0f;
m_bEnabled = false;
}
}
if (m_fCurBrightness < m_fNewBrightness)
{
// switching on
m_fCurBrightness += tick / c_fSwitchOnTime;
if (m_fCurBrightness > m_fNewBrightness)
{
m_fCurBrightness = m_fNewBrightness;
}
}
else if (m_fCurBrightness > m_fNewBrightness)
{
// switching off
m_fCurBrightness -= tick / c_fSwitchOffTime;
if (m_fCurBrightness < m_fNewBrightness)
{
m_fCurBrightness = m_fNewBrightness;
}
}
bEnable = m_fCurBrightness > 0;
m_aLight.setEnabled(bEnable);
if (bEnable)
{
m_aLight.setColor(m_fCurBrightness * m_aOrgColor.x, m_fCurBrightness * m_aOrgColor.y, m_fCurBrightness * m_aOrgColor.z);
}
bEnable = m_fCurBrightness > 0;
m_bLight.setEnabled(bEnable);
if (bEnable)
{
m_cLight.setColor(m_fCurBrightness * m_aOrgColor.x, m_fCurBrightness * m_aOrgColor.y, m_fCurBrightness * m_aOrgColor.z);
}
bEnable = m_fCurBrightness > 0;
m_cLight.setEnabled(bEnable);
if (bEnable)
{
m_cLight.setColor(m_fCurBrightness * m_aOrgColor.x, m_fCurBrightness * m_aOrgColor.y, m_fCurBrightness * m_aOrgColor.z);
}
bEnable = m_fCurBrightness > 0;
m_dLight.setEnabled(bEnable);
if (bEnable)
{
m_dLight.setColor(m_fCurBrightness * m_aOrgColor.x, m_fCurBrightness * m_aOrgColor.y, m_fCurBrightness * m_aOrgColor.z);
}
// This controls the fading between normal object color and completely white, using a special material (fade_to_white)
m_aEntCol.w = m_fCurBrightness;
m_aSCO.setEntityColor(m_aEntCol);
}
}
import com.nolimitscoaster.*;
import nlvm.math3d.*;
/**
* This script simulates a simple light, that switches on when the sun sets
*/
public class QuattroLightScript extends Script
{
private static final String c_aLightSourceName = "thelight1";
private static final String c_bLightSourceName = "thelight2";
private static final String c_cLightSourceName = "thelight3";
private static final String c_dLightSourceName = "thelight4";
private static final double c_fSwitchOnAngle = 18.0; // degrees
private static final float c_fMaxInitialDelay = 0.6f; // seconds
private static final float c_fSwitchOnTime = 10.0f; // seconds
private static final float c_fSwitchOffTime = 1.3f; // seconds
private static final float c_fStartBrightness = 0.2f;
private SceneObjectLight m_aLight;
private SceneObjectLight m_bLight;
private SceneObjectLight m_cLight;
private SceneObjectLight m_dLight;
private SceneObject m_aSCO;
private float m_fInitialDelayTime;
private float m_fCurBrightness;
private float m_fNewBrightness;
private float m_fElevationLimit;
private Vector3f m_aOrgColor;
private Vector3f m_bOrgColor;
private Vector3f m_cOrgColor;
private Vector3f m_dOrgColor;
private Vector4f m_aEntCol;
private Vector4f m_bEntCol;
private Vector4f m_cEntCol;
private Vector4f m_dEntCol;
private bool m_bEnabled;
public bool onInit()
{
m_aSCO = sim.getSceneObjectForEntityId(getParentEntityId());
m_aLight = m_aSCO.getLightForName(c_aLightSourceName);
m_bLight = m_aSCO.getLightForName(c_bLightSourceName);
m_cLight = m_aSCO.getLightForName(c_cLightSourceName);
m_dLight = m_aSCO.getLightForName(c_dLightSourceName);
if (m_aLight == null)
{
System.err.println("Scene object has no light with name '" + c_aLightSourceName + "'");
return false;
}
m_fCurBrightness = 0;
m_fNewBrightness = 0;
m_aLight.setEnabled(false);
m_bEnabled = false;
m_aOrgColor = new Vector3f();
m_aLight.getColor(m_aOrgColor);
m_aEntCol = new Vector4f(1,1,1,0);
m_fElevationLimit = (float)Math.toRadians(c_fSwitchOnAngle);
m_fInitialDelayTime = (float)Math.random() * c_fMaxInitialDelay;
if (m_bLight == null)
{
System.err.println("Scene object has no light with name '" + c_bLightSourceName + "'");
return false;
}
m_fCurBrightness = 0;
m_fNewBrightness = 0;
m_bLight.setEnabled(false);
m_bEnabled = false;
m_bOrgColor = new Vector3f();
m_bLight.getColor(m_bOrgColor);
m_bEntCol = new Vector4f(1,1,1,0);
m_fElevationLimit = (float)Math.toRadians(c_fSwitchOnAngle);
m_fInitialDelayTime = (float)Math.random() * c_fMaxInitialDelay;
if (m_cLight == null)
{
System.err.println("Scene object has no light with name '" + c_cLightSourceName + "'");
return false;
}
m_fCurBrightness = 0;
m_fNewBrightness = 0;
m_cLight.setEnabled(false);
m_bEnabled = false;
m_cOrgColor = new Vector3f();
m_cLight.getColor(m_cOrgColor);
m_cEntCol = new Vector4f(1,1,1,0);
m_fElevationLimit = (float)Math.toRadians(c_fSwitchOnAngle);
m_fInitialDelayTime = (float)Math.random() * c_fMaxInitialDelay;
if (m_dLight == null)
{
System.err.println("Scene object has no light with name '" + c_bLightSourceName + "'");
return false;
}
m_fCurBrightness = 0;
m_fNewBrightness = 0;
m_dLight.setEnabled(false);
m_bEnabled = false;
m_dOrgColor = new Vector3f();
m_dLight.getColor(m_dOrgColor);
m_dEntCol = new Vector4f(1,1,1,0);
m_fElevationLimit = (float)Math.toRadians(c_fSwitchOnAngle);
m_fInitialDelayTime = (float)Math.random() * c_fMaxInitialDelay;
return true;
}
public void onNextFrame(float tick)
{
bool bEnable = sim.getCurSunElevation() <= m_fElevationLimit;
if (bEnable != m_bEnabled)
{
if (bEnable)
{
// switching on
m_fCurBrightness = c_fStartBrightness;
m_fNewBrightness = 1.0f;
m_bEnabled = true;
}
else
{
// switching off
m_fNewBrightness = 0.0f;
m_bEnabled = false;
}
}
if (m_fCurBrightness < m_fNewBrightness)
{
// switching on
m_fCurBrightness += tick / c_fSwitchOnTime;
if (m_fCurBrightness > m_fNewBrightness)
{
m_fCurBrightness = m_fNewBrightness;
}
}
else if (m_fCurBrightness > m_fNewBrightness)
{
// switching off
m_fCurBrightness -= tick / c_fSwitchOffTime;
if (m_fCurBrightness < m_fNewBrightness)
{
m_fCurBrightness = m_fNewBrightness;
}
}
bEnable = m_fCurBrightness > 0;
m_aLight.setEnabled(bEnable);
if (bEnable)
{
m_aLight.setColor(m_fCurBrightness * m_aOrgColor.x, m_fCurBrightness * m_aOrgColor.y, m_fCurBrightness * m_aOrgColor.z);
}
bEnable = m_fCurBrightness > 0;
m_bLight.setEnabled(bEnable);
if (bEnable)
{
m_bLight.setColor(m_fCurBrightness * m_bOrgColor.x, m_fCurBrightness * m_bOrgColor.y, m_fCurBrightness * m_bOrgColor.z);
}
bEnable = m_fCurBrightness > 0;
m_cLight.setEnabled(bEnable);
if (bEnable)
{
m_cLight.setColor(m_fCurBrightness * m_cOrgColor.x, m_fCurBrightness * m_cOrgColor.y, m_fCurBrightness * m_cOrgColor.z);
}
bEnable = m_fCurBrightness > 0;
m_dLight.setEnabled(bEnable);
if (bEnable)
{
m_dLight.setColor(m_fCurBrightness * m_dOrgColor.x, m_fCurBrightness * m_dOrgColor.y, m_fCurBrightness * m_dOrgColor.z);
}
// This controls the fading between normal object color and completely white, using a special material (fade_to_white)
m_aEntCol.w = m_fCurBrightness;
m_bEntCol.w = m_fCurBrightness;
m_cEntCol.w = m_fCurBrightness;
m_dEntCol.w = m_fCurBrightness;
m_aSCO.setEntityColor(m_aEntCol);
}
}
import com.nolimitscoaster.*;
import nlvm.math3d.*;
/**
* This script simulates a simple light, that switches on when the sun sets
*/
public class QuattroLightScript extends Script
{
private static final String c_aLightSourceName = "thelight1";
private static final String c_bLightSourceName = "thelight2";
private static final String c_cLightSourceName = "thelight3";
private static final String c_dLightSourceName = "thelight4";
private static final double c_fSwitchOnAngle = 18.0; // degrees
private static final float c_fMaxInitialDelay = 0.6f; // seconds
private static final float c_fSwitchOnTime = 10.0f; // seconds
private static final float c_fSwitchOffTime = 1.3f; // seconds
private static final float c_fStartBrightness = 0.2f;
private SceneObjectLight m_aLight;
private SceneObjectLight m_bLight;
private SceneObjectLight m_cLight;
private SceneObjectLight m_dLight;
private SceneObject m_aSCO;
private float m_fInitialDelayTime;
private float m_fCurBrightness;
private float m_fNewBrightness;
private float m_fElevationLimit;
private Vector3f m_aOrgColor;
private Vector3f m_bOrgColor;
private Vector3f m_cOrgColor;
private Vector3f m_dOrgColor;
private Vector4f m_aEntCol;
private Vector4f m_bEntCol;
private Vector4f m_cEntCol;
private Vector4f m_dEntCol;
private bool m_bEnabled;
public bool onInit()
{
m_aSCO = sim.getSceneObjectForEntityId(getParentEntityId());
m_aLight = m_aSCO.getLightForName(c_aLightSourceName);
m_bLight = m_aSCO.getLightForName(c_bLightSourceName);
m_cLight = m_aSCO.getLightForName(c_cLightSourceName);
m_dLight = m_aSCO.getLightForName(c_dLightSourceName);
if (m_aLight == null)
{
System.err.println("Scene object has no light with name '" + c_aLightSourceName + "'");
return false;
}
m_fCurBrightness = 0;
m_fNewBrightness = 0;
m_aLight.setEnabled(false);
m_bEnabled = false;
m_aOrgColor = new Vector3f();
m_aLight.getColor(m_aOrgColor);
m_aEntCol = new Vector4f(1,1,1,0);
m_fElevationLimit = (float)Math.toRadians(c_fSwitchOnAngle);
m_fInitialDelayTime = (float)Math.random() * c_fMaxInitialDelay;
if (m_bLight == null)
{
System.err.println("Scene object has no light with name '" + c_bLightSourceName + "'");
return false;
}
m_fCurBrightness = 0;
m_fNewBrightness = 0;
m_bLight.setEnabled(false);
m_bEnabled = false;
m_bOrgColor = new Vector3f();
m_bLight.getColor(m_bOrgColor);
m_bEntCol = new Vector4f(1,1,1,0);
m_fElevationLimit = (float)Math.toRadians(c_fSwitchOnAngle);
m_fInitialDelayTime = (float)Math.random() * c_fMaxInitialDelay;
if (m_cLight == null)
{
System.err.println("Scene object has no light with name '" + c_cLightSourceName + "'");
return false;
}
m_fCurBrightness = 0;
m_fNewBrightness = 0;
m_cLight.setEnabled(false);
m_bEnabled = false;
m_cOrgColor = new Vector3f();
m_cLight.getColor(m_cOrgColor);
m_cEntCol = new Vector4f(1,1,1,0);
m_fElevationLimit = (float)Math.toRadians(c_fSwitchOnAngle);
m_fInitialDelayTime = (float)Math.random() * c_fMaxInitialDelay;
if (m_dLight == null)
{
System.err.println("Scene object has no light with name '" + c_bLightSourceName + "'");
return false;
}
m_fCurBrightness = 0;
m_fNewBrightness = 0;
m_dLight.setEnabled(false);
m_bEnabled = false;
m_dOrgColor = new Vector3f();
m_dLight.getColor(m_dOrgColor);
m_dEntCol = new Vector4f(1,1,1,0);
m_fElevationLimit = (float)Math.toRadians(c_fSwitchOnAngle);
m_fInitialDelayTime = (float)Math.random() * c_fMaxInitialDelay;
return true;
}
public void onNextFrame(float tick)
{
bool bEnable = sim.getCurSunElevation() <= m_fElevationLimit;
if (bEnable != m_bEnabled)
{
if (bEnable)
{
// switching on
m_fCurBrightness = c_fStartBrightness;
m_fNewBrightness = 1.0f;
m_bEnabled = true;
}
else
{
// switching off
m_fNewBrightness = 0.0f;
m_bEnabled = false;
}
}
if (m_fCurBrightness < m_fNewBrightness)
{
// switching on
m_fCurBrightness += tick / c_fSwitchOnTime;
if (m_fCurBrightness > m_fNewBrightness)
{
m_fCurBrightness = m_fNewBrightness;
}
}
else if (m_fCurBrightness > m_fNewBrightness)
{
// switching off
m_fCurBrightness -= tick / c_fSwitchOffTime;
if (m_fCurBrightness < m_fNewBrightness)
{
m_fCurBrightness = m_fNewBrightness;
}
}
bEnable = m_fCurBrightness > 0;
m_aLight.setEnabled(bEnable);
if (bEnable)
{
m_aLight.setColor(m_fCurBrightness * m_aOrgColor.x, m_fCurBrightness * m_aOrgColor.y, m_fCurBrightness * m_aOrgColor.z);
}
bEnable = m_fCurBrightness > 0;
m_bLight.setEnabled(bEnable);
if (bEnable)
{
m_bLight.setColor(m_fCurBrightness * m_bOrgColor.x, m_fCurBrightness * m_bOrgColor.y, m_fCurBrightness * m_bOrgColor.z);
}
bEnable = m_fCurBrightness > 0;
m_cLight.setEnabled(bEnable);
if (bEnable)
{
m_cLight.setColor(m_fCurBrightness * m_cOrgColor.x, m_fCurBrightness * m_cOrgColor.y, m_fCurBrightness * m_cOrgColor.z);
}
bEnable = m_fCurBrightness > 0;
m_dLight.setEnabled(bEnable);
if (bEnable)
{
m_dLight.setColor(m_fCurBrightness * m_dOrgColor.x, m_fCurBrightness * m_dOrgColor.y, m_fCurBrightness * m_dOrgColor.z);
}
// This controls the fading between normal object color and completely white, using a special material (fade_to_white)
m_aEntCol.w = m_fCurBrightness;
m_bEntCol.w = m_fCurBrightness;
m_cEntCol.w = m_fCurBrightness;
m_dEntCol.w = m_fCurBrightness;
m_aSCO.setEntityColor(m_aEntCol);
}
}
Return to NoLimits Coaster 2 Scripting