MegiRicky

thunderBoltVLSthrottle

Dec 11th, 2024
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. local modem = peripheral.find("modem")
  2. local motor = peripheral.find("electric_motor")
  3.  
  4. print("Input the missile id, eg:1, default: 1")
  5. local missileId = io.read()
  6. if missileId == "" then
  7. missileId = 1
  8. end
  9. missileId = tonumber(missileId)
  10.  
  11. local controlsChannel = 1300
  12.  
  13. local throttleChannel = controlsChannel + missileId
  14. modem.open(throttleChannel)
  15. modem.open(controlsChannel)
  16. print("throttleChannel: "..throttleChannel)
  17.  
  18. redstone.setAnalogOutput("front",0)
  19. redstone.setAnalogOutput("back",0)
  20. redstone.setOutput("top",false)
  21.  
  22. local launched = false
  23. local function throttleControl()
  24. while true do
  25. if throttle then
  26. motor.setSpeed(-throttle)
  27. if throttle > 0 then
  28. print("accelerating")
  29. end
  30. end
  31. sleep(0.2)
  32. end
  33. end
  34.  
  35. local function openLaunchHatch()
  36. while true do
  37. if not(launched) and controls and controls.fireMissile and controls.fireMissile[missileId] and controls.fireMissile[missileId].launch == true then
  38. redstone.setOutput("top",true)
  39. sleep(0.1)
  40. redstone.setOutput("top",false)
  41. launched = true
  42. end
  43. sleep()
  44. end
  45. end
  46.  
  47. local function modemMessage()
  48. while true do
  49. if modem then
  50. local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  51. if channel == controlsChannel then
  52. controls = message
  53. elseif channel == throttleChannel then
  54. throttle = message
  55. end
  56. else
  57. sleep()
  58. end
  59. end
  60. end
  61.  
  62. parallel.waitForAny(
  63. modemMessage,
  64. throttleControl,
  65. openLaunchHatch
  66. )
  67.  
Advertisement
Add Comment
Please, Sign In to add comment