MegiRicky

vecotrVLSthrottle.lua

Nov 16th, 2024 (edited)
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. local modem = peripheral.find("modem")
  2.  
  3. print("Input the missile id, eg:1, default: 1")
  4. local missileId = io.read()
  5. if missileId == "" then
  6. missileId = 1
  7. end
  8. missileId = tonumber(missileId)
  9.  
  10. local controlsChannel = 1300
  11.  
  12. local throttleChannel = controlsChannel + missileId
  13. modem.open(throttleChannel)
  14. modem.open(controlsChannel)
  15. print("throttleChannel: "..throttleChannel)
  16.  
  17. redstone.setAnalogOutput("front",0)
  18. redstone.setAnalogOutput("back",0)
  19. redstone.setOutput("top",false)
  20.  
  21. local launched = false
  22. local function throttleControl()
  23. while true do
  24. if throttle then
  25. redstone.setAnalogOutput("front",tonumber(throttle))
  26. redstone.setAnalogOutput("back",tonumber(throttle))
  27. if throttle > 0 then
  28. print("accelerating")
  29. end
  30. end
  31. sleep()
  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