import com.nolimitscoaster.*;
public class SpeakerSound extends Script implements TrackTriggerListener
{
//Constantes
private static final String SoundName = "sound.ogg";
private static final String TriggerName = "SpeakerSoundTrigger";
private static final String CoasterName = "Coaster";
//Variables membres
private SceneObject mSco;
private TrackTrigger mStartSoundTrigger;
private StaticSound mSound;
//Initialisation
public bool onInit()
{
mSco = sim.getSceneObjectForEntityId(getParentEntityId());
if (mSco == null)
{
System.err.println("This script must be attached to a scene object");
return false;
}
Coaster coaster = sim.getCoaster(CoasterName);
if (coaster == null)
{
System.err.println("Coaster not found: '" + CoasterName + "'");
return false;
}
mStartSoundTrigger = coaster.getTrackTrigger(TriggerName);
if (mStartSoundTrigger == null)
{
System.err.println("TrackTrigger not found: '" + TriggerName + "'");
return false;
}
mStartSoundTrigger.addTrackTriggerListener(this);
mSound = StaticSound.loadFromFile(SoundName, StaticSound.FLAG_SHARED);
if (mSound == null)
{
System.err.println("File not found: '" + SoundName + "'");
return false;
}
mSound.setPosition(mSco.getTranslation());
return true;
}
public void onNextFrame(float tick)
{
}
public void onTrainEntering(TrackTrigger trigger, Train train)
{
if (trigger == mStartSoundTrigger)
{
mSound.play();
}
}
public void onTrainLeaving(TrackTrigger trigger, Train train)
{
}
}