MegiRicky

F-35Pocket

Feb 14th, 2025 (edited)
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.37 KB | None | 0 0
  1. local modem = peripheral.find("modem") or error("No modem attached", 0)
  2.  
  3. print("Input the controlChannel, default = 1420")
  4. local controlChannel = io.read()
  5. if controlChannel == "" then
  6. controlChannel = 1420
  7. end
  8. controlChannel = tonumber(controlChannel)
  9. modem.open(controlChannel) -- Open a channel to communicate
  10.  
  11. local controls = {
  12. pitchDown = false,
  13. pitchUp = false,
  14. rollLeft = false,
  15. rollRight = false,
  16. yawRight = false,
  17. yawLeft = false,
  18. autoPilot = false,
  19. throttle = 0,
  20. fire = false,
  21. cannonControlMode = "manual",
  22. hoverMode = false,
  23. cannonUp = false,
  24. cannonDown = false,
  25. cannonLeft = false,
  26. cannonRight = false,
  27. switchToAIM220 = false,
  28. switchToGBU = false,
  29. switchToThunderbolt = false,
  30. switchToAIM9 = false,
  31. switchToGun = false
  32. }
  33.  
  34. local keyMap = {
  35. w = "pitchDown",
  36. s = "pitchUp",
  37. a = "rollLeft",
  38. d = "rollRight",
  39. e = "yawRight",
  40. q = "yawLeft",
  41. p = "autoPilot",
  42. space = "fire",
  43. capsLock = "hoverModeSwitch",
  44. leftShift = "throttleUp",
  45. leftCtrl = "throttleDown",
  46. tab = "switchMode",
  47. up = "cannonUp",
  48. down = "cannonDown",
  49. left = "cannonLeft",
  50. right = "cannonRight",
  51. one = "switchToAIM220",
  52. two = "switchToGBU",
  53. three = "switchToThunderbolt",
  54. four = "switchToAIM9",
  55. five = "switchToGun"
  56. }
  57.  
  58. local lastInputTime = os.clock() -- Tracks last input time
  59. local timeoutDuration = 9999999 -- 9999999 seconds timeout
  60. local weaponChoosen = "AIM-220"
  61.  
  62. -- Function to send the current controls state
  63. local function sendControls()
  64. modem.transmit(controlChannel, controlChannel, controls)
  65. end
  66.  
  67. -- Function to display control status
  68. local function displayControls()
  69. term.clear()
  70. term.setCursorPos(1, 1)
  71.  
  72. print("== F-35 Remote Control ==")
  73. print("Throttle: " .. tostring(controls.throttle) .. "/15")
  74. print("Roll: " .. (controls.rollLeft and "LEFT" or controls.rollRight and "RIGHT" or "CENTER"))
  75. print("Pitch: " .. (controls.pitchUp and "UP" or controls.pitchDown and "DOWN" or "LEVEL"))
  76. print("Yaw: " .. (controls.yawLeft and "LEFT" or controls.yawRight and "RIGHT" or "CENTER"))
  77. print("Cannon Mode: " .. controls.cannonControlMode)
  78. print("VTOL Mode: " .. (controls.hoverMode and "ON" or "OFF"))
  79. print("AutoPilot: "..(controls.autoPilot and "ON" or "OFF"))
  80. print("Fire: " .. (controls.fire and "YES" or "NO"))
  81. print("chosen weapon: "..weaponChoosen)
  82. print("==========================")
  83. print("W/S=Pitch | A/D=Roll | Q/E=Yaw | Space=Fire")
  84. print("Shift=Throttle+ | Ctrl=Throttle- | Tab=Cannon Mode")
  85. print("Caps = Toggle VTOL")
  86. print("1:AIM220 | 2:GBU | 3:TB | 4:AIM9 | 5:Gun")
  87. end
  88.  
  89. -- Function to handle key input
  90. local function keyEventListener()
  91. while true do
  92. displayControls()
  93. local event, param1, param2 = os.pullEvent()
  94.  
  95. if event == "key" then
  96. lastInputTime = os.clock() -- Update last input time
  97.  
  98. for k, control in pairs(keyMap) do
  99. if param1 == keys[k] then
  100. if control == "switchMode" then
  101. controls.cannonControlMode = (controls.cannonControlMode == "manual") and "mouseAim" or "manual"
  102. elseif control == "hoverModeSwitch" then
  103. controls.hoverMode = not controls.hoverMode
  104. elseif control == "throttleUp" then
  105. controls.throttle = math.min(controls.throttle + 1, 15)
  106. elseif control == "throttleDown" then
  107. controls.throttle = math.max(controls.throttle - 1, 0)
  108. elseif control == "autoPilot" then
  109. controls.autoPilot = not controls.autoPilot
  110. else
  111. controls[control] = true
  112. end
  113. sendControls()
  114. end
  115. end
  116. elseif event == "key_up" then
  117. for k, control in pairs(keyMap) do
  118. if param1 == keys[k] then
  119. if control ~= "switchMode" and control ~= "hoverModeSwitch" and control ~= "autoPilot" then
  120. controls[control] = false
  121. sendControls()
  122. end
  123. end
  124. end
  125. end
  126. if controls.switchToAIM220 then
  127. weaponChoosen = "AIM-220"
  128. elseif controls.switchToGBU then
  129. weaponChoosen = "GBU-42"
  130. elseif controls.switchToThunderbolt then
  131. weaponChoosen = "Thunderbolt"
  132. elseif controls.switchToAIM9 then
  133. weaponChoosen = "AIM-9"
  134. elseif controls.switchToGun then
  135. weaponChoosen = "Gun"
  136. end
  137. end
  138. end
  139.  
  140. -- Function to monitor inactivity and reset throttle
  141. local function inactivityMonitor()
  142. while true do
  143. sleep(1) -- Check every second
  144.  
  145. if os.clock() - lastInputTime > timeoutDuration then
  146. if controls.throttle > 0 then
  147. print("\n[Warning] No input detected for " .. timeoutDuration .. "s. Resetting throttle to 0!")
  148. controls.throttle = 0
  149. sendControls()
  150. end
  151. end
  152. end
  153. end
  154.  
  155. -- Run both event listener and inactivity monitor in parallel
  156. parallel.waitForAny(keyEventListener, inactivityMonitor)
  157.  
Advertisement
Add Comment
Please, Sign In to add comment