SHARE
TWEET

Untitled

a guest May 26th, 2017 4 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import com.nolimitscoaster.*;
  2.  
  3. public class CarScript extends Script implements TrackTriggerListener {
  4.    
  5.     private CarHandler handlers[];
  6.     private Coaster coaster;
  7.    
  8.     private String startTriggerName = "start";
  9.     private String stopTriggerName = "stop";
  10.    
  11.     private TrackTrigger startTrigger;
  12.     private TrackTrigger stopTrigger;
  13.    
  14.     public bool onInit() {
  15.         coaster = sim.getCoaster("Track");
  16.         handlers = new CarHandler[coaster.getTrainCount()];
  17.         for (int i = 0; i < coaster.getTrainCount(); i++) {
  18.             Train train = coaster.getTrainAt(i);
  19.             handlers[i] = new CarHandler(this, sim, coaster, train, i);
  20.         }
  21.        
  22.         startTrigger = coaster.getTrackTrigger(startTriggerName);
  23.         if (startTrigger == null) {
  24.             System.err.println("CarScript: Can't find trigger " + startTriggerName + "!");
  25.             return false;
  26.         }
  27.         startTrigger.addTrackTriggerListener(this);
  28.        
  29.         stopTrigger = coaster.getTrackTrigger(stopTriggerName);
  30.         if (stopTrigger == null) {
  31.             System.err.println("CarScript: Can't find trigger " + startTriggerName + "!");
  32.             return false;
  33.         }
  34.         stopTrigger.addTrackTriggerListener(this);
  35.        
  36.         return true;
  37.     }
  38.    
  39.     public void onNextFrame(float tick) {
  40.         for (int i = 0; i < coaster.getTrainCount(); i++) {
  41.             handlers[i].process(tick);
  42.         }
  43.     }
  44.    
  45.     public void onTrainEntering(TrackTrigger trigger, Train train) {
  46.         if (trigger == startTrigger) {
  47.             for (int i = 0; i < coaster.getTrainCount(); i++) {
  48.                 if (handlers[i].getTrain() == train) {
  49.                     handlers[i].start();
  50.                 }
  51.             }
  52.         }
  53.        
  54.         if (trigger == stopTrigger) {
  55.             for (int i = 0; i < coaster.getTrainCount(); i++) {
  56.                 if (handlers[i].getTrain() == train) {
  57.                     handlers[i].stop();
  58.                 }
  59.             }
  60.         }
  61.     }
  62.    
  63.     public void onTrainLeaving(TrackTrigger trigger, Train train) {
  64.        
  65.     }
  66. }
RAW Paste Data
Top