Advertisement
Guest User

ahh

a guest
Mar 24th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. @name Optimized Loco Control
  2. @inputs Active W S Space Throttle_OVR
  3. @outputs MPH KPH V Throttle NegativeThrottle OPS
  4. @persist MaxSpeed Mul [E O Weld]:entity [Diesel_Sound Steamer_Ambient_Sound Steamer_Chuff_Sound Wheel_Sound Brake_Sound]:string EngineMin EngineMax Mode AccelTo AccelQ Throttle Braking Spd
  5. @trigger
  6. @model models/beer/wiremod/watersensor.mdl
  7.  
  8. if(first()|duped()){
  9. MaxSpeed = 5000 #Top Speed in hammer units per second
  10. Mul = 1200 #Force multiplier
  11.  
  12. Mode = 0 #1 for Steamers, 0 for Diesels/Electric/Other
  13.  
  14. #The Engine idle sound that will be used for Diesel/Electric/Other locomotives
  15. Diesel_Sound = "gsgtrainsounds/other/alco_539_idle.wav"
  16.  
  17. #The Ambient and Chuff loop sounds that will be used for Steam locomotives
  18. Steamer_Ambient_Sound = "gsgtrainsounds/steam/engine/b1_idle.wav"
  19. Steamer_Chuff_Sound = "gsgtrainsounds/steam/engine/pannier_chufflooplo.wav"
  20.  
  21. #The wheel and brake sound that will be used on all locomotives
  22. Wheel_Sound = "ambient/machines/train_freight_loop2.wav"
  23. Brake_Sound = "gsgtrainsounds/wheels/brake_2.wav"
  24.  
  25. EngineMin = 80 #Minimum engine pitch. If the locomotive is a steamer, the Ambient sound will be clamped to this value.
  26. EngineMax = 120 #Maximum engine pitch, only used on Diesels/Electrics/Other when you put that hammer down.
  27.  
  28.  
  29. Throttle = 0
  30. AccelTo = 0
  31. E = entity()
  32. O = owner()
  33. runOnChat(1)
  34.  
  35.  
  36. }
  37. interval(20)
  38. if(Active){
  39.  
  40. #Ignition
  41. if(~Active){
  42. Weld = E:isWeldedTo()
  43. E:soundPlay(0,0,Mode ? Steamer_Ambient_Sound : Diesel_Sound)
  44. E:soundPlay(1,0,Wheel_Sound)
  45. if(Mode){
  46. E:soundPlay(2,0,Steamer_Chuff_Sound)
  47. soundPitch(0,EngineMin)
  48. }
  49. }
  50.  
  51.  
  52. #Throttle Controlling
  53.  
  54. if((W|S|Space) & !->Throttle_OVR){
  55. if(AccelQ){AccelQ=0}
  56.  
  57. Throttle += (W - S)*0.125
  58.  
  59. if(Space){
  60. Throttle = 0
  61. Braking = 1
  62. if(Spd > 15){
  63. soundPlay(3,0,Brake_Sound)
  64. }
  65. }
  66. }elseif(->Throttle_OVR){
  67. Throttle = Throttle_OVR
  68. }
  69. if(!->Throttle_OVR & AccelQ){
  70. Throttle += sign(AccelTo - Throttle)/64
  71. if(Throttle==AccelTo){
  72. AccelQ = 0
  73. }
  74. }
  75.  
  76. Throttle = clamp(Throttle,-10,10)
  77. NegativeThrottle = -Throttle
  78.  
  79.  
  80. #Velocity Info Gathering
  81. V = -E:velL():z()
  82. Spd = abs(V)
  83. MPH = toUnit("mph",Spd)
  84. KPH = toUnit("km/h",Spd)
  85.  
  86. #Sound Pitch Adjustment
  87.  
  88. if(!Mode){
  89. soundPitch(0,EngineMin + (EngineMax - EngineMin)*abs(Throttle)/10)
  90. }
  91. soundPitch(1,Spd > 15 ? Spd/12 : 0)
  92. soundPitch(2,Spd > 15 ? Spd/4 : 0)
  93.  
  94. if(Spd<15 & Braking){
  95. Braking = 0
  96. soundStop(3)
  97. }
  98.  
  99. #Force Application
  100. Dir = -E:up()
  101. TargetSpeed = MaxSpeed*Throttle/10
  102. Weld:applyForce(Dir*(TargetSpeed - V)*Mul*2)
  103.  
  104. #Chat Control
  105.  
  106. if(chatClk(O) & !->Throttle_OVR){
  107. Sentence = O:lastSaid():explode(" ")
  108. CMD = Sentence[1,string]
  109. if(CMD == ".throttle"){
  110. AccelQ = 0
  111. Throttle = clamp(Sentence[2,string]:toNumber(),-10,10)
  112. if(Throttle==0){
  113. Braking = 1
  114. E:soundPlay(3,0,Brake_Sound)
  115. }
  116. hideChat(1)
  117. print("Setting Throttle to " + Throttle:toString())
  118. }elseif(CMD == ".accelto"){
  119. AccelQ = 1
  120. AccelTo = clamp(Sentence[2,string]:toNumber(),-10,10)
  121. hideChat(1)
  122. print("Accelerating to " + AccelTo:toString())
  123. }elseif(CMD == ".mul"){
  124. Mul = Sentence[2,string]:toNumber()
  125. hideChat(1)
  126. print("Setting Force Multiplier to " + Sentence[2,string])
  127. }elseif(CMD == ".maxspeed"){
  128. MaxSpeed = Sentence[2,string]:toNumber()
  129. hideChat(1)
  130. print("Setting Maximum Speed to " + Sentence[2,string])
  131. }
  132. }
  133.  
  134. }else{
  135. if(~Active){
  136. Throttle = NegativeThrottle = V = Spd = MPH = KPH = AccelTo = AccelQ = Braking = 0
  137. soundStop(0)
  138. soundStop(1)
  139. soundStop(2)
  140. soundStop(3)
  141.  
  142. }
  143. }
  144.  
  145.  
  146.  
  147. OPS = ops()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement