Advertisement
nyapoleon_legionary

Soundlib Keikyu 21000

Jun 4th, 2023
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.88 KB | None | 0 0
  1. importPackage(Packages.jp.ngt.rtm);
  2. importPackage(Packages.jp.ngt.rtm.render);
  3. importPackage(Packages.jp.ngt.rtm.entity.train.util);
  4. importPackage(Packages.jp.ngt.ngtlib.util);
  5. importPackage(Packages.jp.ngt.rtm.sound);
  6. importPackage(Packages.jp.ngt.ngtlib.io);
  7.  
  8. function onUpdate(su) {
  9. updateSoundMaker(su);
  10. updateSoundEffects(su);
  11. }
  12.  
  13. /*
  14. ## RTM Sound Maker ##
  15. Version 1.0
  16.  
  17. Copyright (c) 2021 hi03
  18.  
  19. This software is released under the MIT License.
  20. http://opensource.org/licenses/mit-license.php
  21. */
  22.  
  23. //Input data
  24. var Dmain = 'sound_baru';
  25. var SoundMap = {"2100_00":"train.2100_00","2100_01":"train.2100_01","2100_02":"train.2100_02","2100_03":"train.2100_03","2100_03b":"train.2100_03b","2100_04":"train.2100_04","2100_05":"train.2100_05","2100_06":"train.2100_06","2100_07":"train.2100_07","2100_08":"train.2100_08","2100_09":"train.2100_09","2100_10":"train.2100_10","2100_11":"train.2100_11","2100_12":"train.2100_12","2100_13":"train.2100_13","2100_run01":"train.2100_run01","2100_run02":"train.2100_run02","2100_run03":"train.2100_run03","2100_14":"train.2100_14","2100_15":"train.2100_15","2100_16":"train.2100_16","2100_17":"train.2100_17","2100_18":"train.2100_18","2100_19":"train.2100_19","2100_20":"train.2100_20"};
  26. var SoundData = [{"soundName":"2100_00","pitchData":[[{"speed":3,"value":0.5,"func":"1"},null,{"speed":28,"value":0.5,"func":"1"},null,null,null,null],[],[{"speed":0,"value":0.5,"func":"1"},null,{"speed":19,"value":0.5,"func":"1"},null]],"volumeData":[[{"speed":3,"value":0,"func":"0"},{"speed":7,"value":0.6,"func":"0.6"},{"speed":28,"value":0,"func":"0"},null,null,null,null,null,null,null],[],[{"speed":0,"value":0,"func":"0"},{"speed":3,"value":1,"func":"1"},{"speed":5,"value":1,"func":"1"},{"speed":19,"value":0,"func":"0"},null,null,null]]},{"soundName":"2100_01","pitchData":[[{"speed":3,"value":0.5,"func":"1"},null,{"speed":28,"value":0.5,"func":"1"},null],[],[{"speed":3,"value":0.5,"func":"1"},null,{"speed":25,"value":0.5,"func":"1"}]],"volumeData":[[{"speed":3,"value":0,"func":"0"},{"speed":27.9,"value":0.8,"func":"0.8"},{"speed":28,"value":0,"func":"0"},null,null,null,null,null,null,null],[],[{"speed":3,"value":0,"func":"0"},{"speed":17,"value":1,"func":"1"},{"speed":24.9,"value":1,"func":"1"},{"speed":25,"value":0,"func":"0"},null,null]]},{"soundName":"2100_02","pitchData":[[null,{"speed":5,"value":0.385,"func":"0.1555*x+0"},{"speed":12,"value":0.93,"func":"0.1555*x+0"},null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],[],[null,{"speed":5,"value":0.385,"func":"0.1555*x+0"},{"speed":12,"value":0.93,"func":"0.1555*x+0"},null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null]],"volumeData":[[{"speed":5,"value":0,"func":"0"},{"speed":7,"value":1,"func":"1"},{"speed":8,"value":0.3,"func":"0.3"},{"speed":12,"value":0,"func":"0"},null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],[],[{"speed":5,"value":0,"func":"0"},{"speed":7,"value":1,"func":"1"},{"speed":8,"value":0.3,"func":"0.3"},{"speed":12,"value":0,"func":"0"},null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null]]},{"soundName":"2100_03","pitchData":[[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],[],[{"speed":2,"value":0.33,"func":"0.3333*x+0"},{"speed":4.2,"value":0.695,"func":"0.3333*x+0"},{"speed":4.3,"value":0.395,"func":"0.1851*x+0"},{"speed":7,"value":0.645,"func":"0.1851*x+0"},null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null]],"volumeData":[[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],[],[{"speed":2,"value":0,"func":"0"},{"speed":3.5,"value":0.6,"func":"0.6"},{"speed":4.2,"value":0,"func":"0"},{"speed":4.3,"value":0,"func":"0"},{"speed":5.5,"value":0.5,"func":"0.5"},{"speed":7,"value":0,"func":"0"},null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null]]},{"soundName":"2100_03b","pitchData":[[null,null,null,null,null,null,null,null,null,null,null],[],[{"speed":3,"value":0.375,"func":"0.25*x+0"},{"speed":6,"value":0.75,"func":"0.25*x+0"},null,null,null,null,null,null,null,null,null]],"volumeData":[[null,null,null,null,null,null,null,null,null,null,null],[],[{"speed":3,"value":0,"func":"0"},{"speed":4,"value":0.5,"func":"0.5"},{"speed":6,"value":0,"func":"0"},null,null,null,null,null,null,null,null]]},{"soundName":"2100_04","pitchData":[[{"speed":9,"value":0.36,"func":"0.0806*x+0"},{"speed":24,"value":0.965,"func":"0.0806*x+0"},null,null,null,null,null,null,null,null,null,null,null,null],[],[{"speed":9,"value":0.36,"func":"0.0806*x+0"},{"speed":24,"value":0.965,"func":"0.0806*x+0"},null,null,null,null,null,null,null,null,null,null,null,null]],"volumeData":[[{"speed":9,"value":0,"func":"0"},{"speed":15,"value":1,"func":"1"},{"speed":24,"value":0,"func":"0"},null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],[],[{"speed":9,"value":0,"func":"0"},{"speed":15,"value":1,"func":"1"},{"speed":24,"value":0,"func":"0"},null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null]]},{"soundName":"2100_05","pitchData":[[null,{"speed":6.5,"value":0.26,"func":"0.0806*x+0"},{"speed":16,"value":0.64,"func":"0.0806*x+0"},null,null,null,null,null,null,null,null],[],[null,{"speed":6.5,"value":0.26,"func":"0.0806*x+0"},{"speed":16,"value":0.64,"func":"0.0806*x+0"},null,null,null,null,null,null,null,null]],"volumeData":[[null,{"speed":6.5,"value":0,"func":"0"},{"speed":10,"value":1,"func":"1"},{"speed":16,"value":0,"func":"0"},null,null,null,null,null,null,null,null,null,null,null,null],[],[null,{"speed":6.5,"value":0,"func":"0"},{"speed":10,"value":1,"func":"1"},{"speed":16,"value":0,"func":"0"},null,null,null,null,null,null,null,null,null,null,null,null]]},{"soundName":"2100_06","pitchData":[[null,null,null,null,null,null,null,null],[],[{"speed":14,"value":0.31,"func":"0.0444*x+0"},{"speed":26,"value":0.575,"func":"0.0444*x+0"},null,null,null,null]],"volumeData":[[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null],[],[{"speed":14,"value":0,"func":"0"},{"speed":23,"value":1,"func":"1"},{"speed":24.9,"value":1,"func":"1"},{"speed":26,"value":0,"func":"0"},null,null,null,null,null,null,null]]},{"soundName":"2100_07","pitchData":[[null,null,null],[],[{"speed":24.9,"value":0.48,"func":"0.0389*x+0"},{"speed":36,"value":0.7,"func":"0.0389*x+0"},null]],"volumeData":[[null,null,null,null,null,null,null,null],[],[{"speed":24.9,"value":0,"func":"0"},{"speed":25,"value":1,"func":"1"},{"speed":30,"value":1,"func":"1"},{"speed":36,"value":0,"func":"0"},null,null,null,null]]},{"soundName":"2100_08","pitchData":[[null,null,null,null],[],[{"speed":24.9,"value":0.48,"func":"0.0389*x+0"},{"speed":40,"value":0.775,"func":"0.0389*x+0"},null,null]],"volumeData":[[null,null,null,null,null,null,null,null,null,null,null],[],[{"speed":24.9,"value":0,"func":"0"},{"speed":25,"value":1,"func":"1"},{"speed":26,"value":1,"func":"1"},{"speed":27,"value":0.4,"func":"0.4"},{"speed":30,"value":0.6,"func":"0.6"},{"speed":31,"value":0.2,"func":"0.2"},{"speed":40,"value":0,"func":"0"},null,null,null,null]]},{"soundName":"2100_09","pitchData":[[null,null,null,null,null],[],[{"speed":28,"value":0.355,"func":"0.0256*x+0"},{"speed":53,"value":0.675,"func":"0.0256*x+0"},null]],"volumeData":[[null,null,null,null,null,null,null,null,null,null,null,null,null],[],[{"speed":28,"value":0,"func":"0"},{"speed":34,"value":1,"func":"1"},{"speed":43,"value":1,"func":"1"},{"speed":53,"value":0,"func":"0"},null,null,null,null]]},{"soundName":"2100_10","pitchData":[[null,null,null,null,null,null,null,null],[],[{"speed":40,"value":0.4,"func":"0.02*x+0"},{"speed":70,"value":0.7,"func":"0.02*x+0"},null,null,null,null,null,null]],"volumeData":[[null,null,null,null,null,null,null,null,null],[],[{"speed":40,"value":0,"func":"0"},{"speed":50,"value":1,"func":"1"},{"speed":60,"value":1,"func":"1"},{"speed":70,"value":0,"func":"0"},null,null,null,null,null]]},{"soundName":"2100_11","pitchData":[[{"speed":57,"value":0.42,"func":"0.0149*x+0"},{"speed":90,"value":0.67,"func":"0.0149*x+0"}],[],[{"speed":57,"value":0.42,"func":"0.0149*x+0"},{"speed":90,"value":0.67,"func":"0.0149*x+0"}]],"volumeData":[[{"speed":57,"value":0,"func":"0"},{"speed":67,"value":1,"func":"1"},{"speed":80,"value":1,"func":"1"},{"speed":90,"value":0,"func":"0"},null,null],[],[{"speed":57,"value":0,"func":"0"},{"speed":67,"value":1,"func":"1"},{"speed":80,"value":1,"func":"1"},{"speed":90,"value":0,"func":"0"},null,null]]},{"soundName":"2100_12","pitchData":[[{"speed":77,"value":0.435,"func":"0.0113*x+0"},{"speed":110,"value":0.62,"func":"0.0113*x+0"}],[],[{"speed":77,"value":0.435,"func":"0.0113*x+0"},{"speed":110,"value":0.62,"func":"0.0113*x+0"}]],"volumeData":[[{"speed":77,"value":0,"func":"0"},{"speed":87,"value":1,"func":"1"},{"speed":100,"value":1,"func":"1"},{"speed":110,"value":0,"func":"0"},null],[],[{"speed":77,"value":0,"func":"0"},{"speed":87,"value":1,"func":"1"},{"speed":100,"value":1,"func":"1"},{"speed":110,"value":0,"func":"0"},null]]},{"soundName":"2100_13","pitchData":[[{"speed":97,"value":0.46,"func":"0.0095*x+0"},{"speed":130,"value":0.615,"func":"0.0095*x+0"}],[],[{"speed":97,"value":0.46,"func":"0.0095*x+0"},{"speed":130,"value":0.615,"func":"0.0095*x+0"}]],"volumeData":[[{"speed":97,"value":0,"func":"0"},{"speed":107,"value":1,"func":"1"},{"speed":120,"value":1,"func":"1"},{"speed":130,"value":0,"func":"0"}],[],[{"speed":97,"value":0,"func":"0"},{"speed":107,"value":1,"func":"1"},{"speed":120,"value":1,"func":"1"},{"speed":130,"value":0,"func":"0"}]]},{"soundName":"2100_run01","pitchData":[[{"speed":61,"value":0.28,"func":"0.0093*x+0"},{"speed":130,"value":0.6,"func":"0.0093*x+0"}],[{"speed":61,"value":0.28,"func":"0.0093*x+0"},{"speed":130,"value":0.6,"func":"0.0093*x+0"}],[{"speed":61,"value":0.28,"func":"0.0093*x+0"},{"speed":130,"value":0.6,"func":"0.0093*x+0"}]],"volumeData":[[{"speed":61,"value":0,"func":"0"},{"speed":85,"value":0.79,"func":"0.79"},{"speed":107.5,"value":1,"func":"1"},{"speed":120,"value":1,"func":"1"},{"speed":130,"value":0,"func":"0"}],[{"speed":61,"value":0,"func":"0"},{"speed":85,"value":0.79,"func":"0.79"},{"speed":107.5,"value":1,"func":"1"},{"speed":120,"value":1,"func":"1"},{"speed":130,"value":0,"func":"0"}],[{"speed":61,"value":0,"func":"0"},{"speed":85,"value":0.79,"func":"0.79"},{"speed":107.5,"value":1,"func":"1"},{"speed":120,"value":1,"func":"1"},{"speed":130,"value":0,"func":"0"}]]},{"soundName":"2100_run02","pitchData":[[{"speed":34,"value":0.25,"func":"0.0149*x+0"},{"speed":90,"value":0.67,"func":"0.0149*x+0"}],[{"speed":34,"value":0.25,"func":"0.0149*x+0"},{"speed":90,"value":0.67,"func":"0.0149*x+0"}],[{"speed":34,"value":0.25,"func":"0.0149*x+0"},{"speed":90,"value":0.67,"func":"0.0149*x+0"}]],"volumeData":[[{"speed":34,"value":0,"func":"0"},{"speed":53,"value":0.8,"func":"0.8"},{"speed":66,"value":1,"func":"1"},{"speed":90,"value":0,"func":"0"}],[{"speed":34,"value":0,"func":"0"},{"speed":53,"value":0.8,"func":"0.8"},{"speed":66,"value":1,"func":"1"},{"speed":90,"value":0,"func":"0"}],[{"speed":34,"value":0,"func":"0"},{"speed":53,"value":0.8,"func":"0.8"},{"speed":66,"value":1,"func":"1"},{"speed":90,"value":0,"func":"0"}]]},{"soundName":"2100_run03","pitchData":[[{"speed":0,"value":0.25,"func":"0.5"},{"speed":20,"value":0.25,"func":"0.5"},{"speed":56,"value":0.7,"func":"0.025*x+0"}],[{"speed":0,"value":0.25,"func":"0.5"},{"speed":20,"value":0.25,"func":"0.5"},{"speed":56,"value":0.7,"func":"0.025*x+0"}],[{"speed":0,"value":0.25,"func":"0.5"},{"speed":20,"value":0.25,"func":"0.5"},{"speed":56,"value":0.7,"func":"0.025*x+0"}]],"volumeData":[[{"speed":0,"value":0,"func":"0"},{"speed":36,"value":1,"func":"1"},{"speed":56,"value":0,"func":"0"}],[{"speed":0,"value":0,"func":"0"},{"speed":36,"value":1,"func":"1"},{"speed":56,"value":0,"func":"0"}],[{"speed":0,"value":0,"func":"0"},{"speed":36,"value":1,"func":"1"},{"speed":56,"value":0,"func":"0"}]]},{"soundName":"2100_14","pitchData":[[null,{"speed":36,"value":0.525,"func":"1.05"},{"speed":40,"value":0.525,"func":"1.05"},null,null,null,null,null,null],[],[{"speed":32,"value":0.5,"func":"1"},null,{"speed":36,"value":0.5,"func":"1"},null,null,null,null,null,null,null,null]],"volumeData":[[null,{"speed":36,"value":0,"func":"0"},{"speed":38,"value":1,"func":"1"},{"speed":40,"value":0,"func":"0"},null,null,null,null,null,null,null],[],[{"speed":32,"value":0,"func":"0"},{"speed":34,"value":1,"func":"1"},{"speed":36,"value":0,"func":"0"},null,null,null,null,null,null,null,null,null,null,null]]},{"soundName":"2100_15","pitchData":[[{"speed":46,"value":0.38,"func":"0.0166*x+0"},{"speed":70,"value":0.58,"func":"0.0166*x+0"},null,null,null,null,null,null],[],[]],"volumeData":[[{"speed":46,"value":0,"func":"0"},{"speed":56,"value":1,"func":"1"},{"speed":60,"value":1,"func":"1"},{"speed":70,"value":0,"func":"0"},null,null,null,null,null,null,null,null],[],[]]},{"soundName":"2100_16","pitchData":[[null,{"speed":40,"value":0.405,"func":"0.0204*x+0"},{"speed":58,"value":0.59,"func":"0.0204*x+0"},null],[],[]],"volumeData":[[null,{"speed":40,"value":0,"func":"0"},{"speed":45,"value":1,"func":"1"},{"speed":48,"value":1,"func":"1"},{"speed":58,"value":0,"func":"0"}],[],[]]},{"soundName":"2100_17","pitchData":[[{"speed":30,"value":0.375,"func":"0.0253*x+0"},{"speed":47,"value":0.59,"func":"0.0253*x+0"}],[],[]],"volumeData":[[{"speed":30,"value":0,"func":"0"},{"speed":40,"value":1,"func":"1"},{"speed":42,"value":1,"func":"1"},{"speed":47,"value":0,"func":"0"},null],[],[]]},{"soundName":"2100_18","pitchData":[[null,{"speed":27.9,"value":0.445,"func":"0.0322*x+0"},{"speed":42,"value":0.675,"func":"0.0322*x+0"}],[],[]],"volumeData":[[{"speed":27.9,"value":0,"func":"0"},{"speed":28,"value":1,"func":"1"},{"speed":32,"value":1,"func":"1"},{"speed":42,"value":0,"func":"0"},null,null],[],[]]},{"soundName":"2100_19","pitchData":[[{"speed":13,"value":0.28,"func":"0.0434*x+0"},{"speed":29,"value":0.625,"func":"0.0434*x+0"},null],[],[]],"volumeData":[[{"speed":13,"value":0,"func":"0"},{"speed":23,"value":1,"func":"1"},{"speed":27.9,"value":1,"func":"1"},{"speed":29,"value":0,"func":"0"},null],[],[]]},{"soundName":"2100_20","pitchData":[[{"speed":38,"value":0.48,"func":"0.0253*x+0"},{"speed":47,"value":0.59,"func":"0.0253*x+0"},null,null,null,null],[],[]],"volumeData":[[{"speed":38,"value":0,"func":"0"},{"speed":44.5,"value":0.5,"func":"0.5"},{"speed":47,"value":0,"func":"0"},null,null,null,null,null,null,null,null,null],[],[]]}];
  27. //Input data <END>
  28.  
  29. var delayTick = 6;
  30. var fadeTick = 4;
  31.  
  32. function updateSoundMaker(su) {
  33. var entity = su.getEntity();
  34. var dataMap = entity.getResourceState().getDataMap();
  35. var speed = su.getSpeed();
  36. var notch = su.getNotch();
  37. var notchIndex = 0;
  38.  
  39. if (notch === 0) notchIndex = 1;
  40. if (notch > 0) notchIndex = 2;
  41.  
  42. var fadeCnt = dataMap.getInt("fadeCnt");
  43. if (notchIndex != 1 && fadeCnt < delayTick + fadeTick) fadeCnt ++;
  44. if (notchIndex == 1 && fadeCnt > 0) fadeCnt --;
  45. dataMap.setInt("fadeCnt", fadeCnt, 0);
  46.  
  47. if((notchIndex != 1 && fadeCnt == delayTick + fadeTick) || (notchIndex == 1 && fadeCnt == 0)) dataMap.setInt("notchIndexF", notchIndex, 0);
  48. var notchIndexF = dataMap.getInt("notchIndexF");
  49.  
  50. var pitData = [];
  51. var volData = [];
  52. var soundNameList = [];
  53.  
  54. SoundData.forEach(function (layer) {
  55. soundNameList.push(layer.soundName);
  56. pitData.push(layer.pitchData);
  57. volData.push(layer.volumeData);
  58. });
  59. soundNameList.forEach(function (name, layerIndex) {
  60. var pitch = notchIndexF == 1 ? getValue(pitData[layerIndex], speed, notchIndex) * 2 : getValue(pitData[layerIndex], speed, notchIndexF) * 2;
  61. var volume = 0.0;
  62. if(fadeCnt > 0 && fadeCnt < delayTick + fadeTick){
  63. var volN = getValue(volData[layerIndex], speed, 1);
  64. var volM = notchIndexF == 1 ? getValue(volData[layerIndex], speed, notchIndex) : getValue(volData[layerIndex], speed, notchIndexF);
  65. if(notchIndex != 1) volume = fadeCnt < delayTick ? volN : (volN * (delayTick + fadeTick - fadeCnt) + volM * (fadeCnt - delayTick)) / fadeTick;
  66. else volume = fadeCnt > fadeTick ? volM : (volN * (fadeTick - fadeCnt) + volM * fadeCnt) / fadeTick;
  67. }else{
  68. volume = getValue(volData[layerIndex], speed, notchIndexF);
  69. }
  70. su.playSound(Dmain, SoundMap[name], volume, pitch, true);
  71. });
  72. }
  73.  
  74. function getValue(data, speed, notchIndex) {//pitchData or volumeData
  75. var points = data[notchIndex];
  76. var currentPoint = null;
  77. var nextPoint = null;
  78. var value = 0;
  79. for(var i = 0; i < points.length; i++){
  80. currentPoint = points[i];
  81. if (!currentPoint) continue;
  82. if (i < points.length) nextPoint = points[i + 1];
  83. if (!nextPoint) {
  84. value = currentPoint.value;
  85. break;
  86. }
  87. if (currentPoint.speed <= speed && speed <= nextPoint.speed) {
  88. var x1 = currentPoint.speed;
  89. var y1 = currentPoint.value;
  90. var x2 = nextPoint.speed;
  91. var y2 = nextPoint.value;
  92. var a = ((y2 - y1) / (x2 - x1));
  93. var b = ((x2 * y1 - x1 * y2) / (x2 - x1));
  94. var r = a * speed + b;
  95. if (r > 1.0) r = 1.0;
  96. if (r < 0.0) r = 0.0;
  97. value = r;
  98. break;
  99. }
  100. }
  101. return value;
  102. }
  103. //RTM Sound Maker <END>
  104.  
  105. var releaseTick = 7;
  106.  
  107. function updateSoundEffects(su){
  108. var entity = su.getEntity();
  109. var dataMap = entity.getResourceState().getDataMap();
  110. var speed = su.getSpeed();
  111.  
  112. var releaseNotch = dataMap.getInt("releaseNotch");
  113. var tickCnt = dataMap.getInt("tickCnt");
  114. var prevNotch = dataMap.getInt("prevNotch");
  115. var prevDoorState = dataMap.getInt("prevDoorState");
  116.  
  117. var notch = 0;
  118. if(entity != null) notch = entity.getNotch();
  119.  
  120. try {
  121. var doorState = entity.getVehicleState(TrainState.getStateType(4));
  122. }
  123. catch(e){
  124. var doorState = entity.getTrainStateData(4);
  125. }
  126.  
  127. if((doorState == 1 && prevDoorState == 0) || (doorState == 3 && prevDoorState == 2)){
  128. su.stopSound('sound_baru', 'train.2100_door_cls_l');
  129. su.stopSound('sound_baru', 'train.2100_door_opn_l');
  130. su.playSound('sound_baru', 'train.2100_door_opn_l', 1.0, 1.0, false);
  131. }
  132.  
  133. if((doorState == 0 && prevDoorState == 1) || (doorState == 2 && prevDoorState == 3)){
  134. su.stopSound('sound_baru', 'train.2100_door_opn_l');
  135. su.stopSound('sound_baru', 'train.2100_door_cls_l');
  136. su.playSound('sound_baru', 'train.2100_door_cls_l', 1.0, 1.0, false);
  137. }
  138.  
  139. if((doorState == 2 && prevDoorState == 0) || (doorState == 3 && prevDoorState == 1)){
  140. su.stopSound('sound_baru', 'train.2100_door_cls_r');
  141. su.stopSound('sound_baru', 'train.2100_door_opn_r');
  142. su.playSound('sound_baru', 'train.2100_door_opn_r', 1.0, 1.0, false);
  143. }
  144.  
  145. if((doorState == 0 && prevDoorState == 2) || (doorState == 1 && prevDoorState == 3)){
  146. su.stopSound('sound_baru', 'train.2100_door_opn_r');
  147. su.stopSound('sound_baru', 'train.2100_door_cls_r');
  148. su.playSound('sound_baru', 'train.2100_door_cls_r', 1.0, 1.0, false);
  149. }
  150.  
  151. if(speed < 3.0){
  152. if(notch > prevNotch && prevNotch < 0){
  153. if(tickCnt == 0) releaseNotch = notch;
  154. tickCnt = 1;
  155. }
  156. }
  157.  
  158. if(tickCnt != 0 && tickCnt <= releaseTick){
  159. tickCnt++;
  160. }else if(tickCnt == releaseTick + 1){
  161. su.stopSound('sound_baru', 'train.2100_air00');
  162. su.stopSound('sound_baru', 'train.2100_air01');
  163. su.stopSound('sound_baru', 'train.2100_air02');
  164. if(notch >= 0){
  165. if(releaseNotch < -3){
  166. su.playSound('sound_baru', 'train.2100_air02', 1.0, 1.0, false);
  167. }else{
  168. su.playSound('sound_baru', 'train.2100_air00', 1.0, 1.0, false);
  169. }
  170. }else if(notch - releaseNotch > 2){
  171. su.playSound('sound_baru', 'train.2100_air02', 1.0, 1.0, false);
  172. }else{
  173. su.playSound('sound_baru', 'train.2100_air01', 1.0, 1.0, false);
  174. }
  175. tickCnt = 0;
  176. }
  177.  
  178. su.playSound('sound_baru', 'train.cooler', 1.0, 1.0, true);
  179. dataMap.setInt("releaseNotch", releaseNotch, 0);
  180. dataMap.setInt("tickCnt", tickCnt, 0);
  181. dataMap.setInt("prevNotch", notch, 0);
  182. dataMap.setInt("prevDoorState", doorState, 0);
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement