MegiRicky

EMBTPocket

Mar 8th, 2025 (edited)
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.33 KB | None | 0 0
  1. local modem = peripheral.find("modem") or error("No modem attached", 0)
  2.  
  3. local registeredChannels = {}
  4.  
  5. print("Input the EMBTEMBTControlChannel, default = 2000")
  6. local EMBTControlChannel = io.read()
  7. if EMBTControlChannel == "" then
  8. EMBTControlChannel = 2000
  9. end
  10. EMBTControlChannel = tonumber(EMBTControlChannel)
  11. SHARDControlChannel = EMBTControlChannel + 10
  12. droneControlChannel = EMBTControlChannel + 20
  13. modem.open(EMBTControlChannel) -- Open a channel to communicate
  14. modem.open(droneControlChannel)
  15.  
  16. local systems = {
  17. { name = "Main Turret", EMBTControlsPage = "Main Turret EMBTControls" },
  18. { name = "SHARD", EMBTControlsPage = "S.H.A.R.D. EMBTControls" },
  19. { name = "Drone", EMBTControlsPage = "Scout Drone control"}
  20. }
  21.  
  22. local currentPage = "home"
  23. local currentSelection = 1 -- Initially on the first system (Main Turret)
  24.  
  25. local EMBTControls = {
  26. accelerate = false,
  27. decelerate = false,
  28. turnLeft = false,
  29. turnRight = false,
  30. suspensionUp = false,
  31. suspensionDown = false,
  32. fireCannon = false,
  33. fireAutocannon = false,
  34. targetSwitch = false,
  35. fireMissile = {},
  36. launchSmokeGrenade = false,
  37. cannonControlMode = "manual",
  38. cannonUp = false,
  39. cannonDown = false,
  40. cannonLeft = false,
  41. cannonRight = false,
  42. shellMode = "APHE_Delayed"
  43. }
  44.  
  45. local EMBTKeyMap = {
  46. w = "accelerate",
  47. s = "decelerate",
  48. a = "turnLeft",
  49. d = "turnRight",
  50. e = "suspensionUp",
  51. q = "suspensionDown",
  52. space = "fireCannon",
  53. r = "targetSwitch",
  54. f = "fireAutocannon",
  55. leftCtrl = "fireCOAX",
  56. leftShift = "fireMissile",
  57. t = "launchSmokeGrenade",
  58. tab = "switchMode",
  59. up = "cannonUp",
  60. down = "cannonDown",
  61. left = "cannonLeft",
  62. right = "cannonRight",
  63. one = "shellSwitch_APHE_Delayed",
  64. two = "shellSwitch_APHE_Proximity"
  65. }
  66.  
  67.  
  68. local SHARDControls = {
  69. accelerate = false,
  70. decelerate = false,
  71. turnLeft = false,
  72. turnRight = false,
  73. suspensionUp = false,
  74. suspensionDown = false,
  75. fireCannon = false,
  76. fireAutocannon = false,
  77. fireCOAX = false,
  78. targetSwitch = false,
  79. fireMissile = {},
  80. launchSmokeGrenade = false,
  81. cannonControlMode = "manual",
  82. cannonUp = false,
  83. cannonDown = false,
  84. cannonLeft = false,
  85. cannonRight = false,
  86. }
  87.  
  88. local SHARDKeyMap = {
  89. w = "accelerate",
  90. s = "decelerate",
  91. a = "turnLeft",
  92. d = "turnRight",
  93. e = "suspensionUp",
  94. q = "suspensionDown",
  95. space = "fireCannon",
  96. leftCtrl = "fireAutocannon",
  97. r = "targetSwitch",
  98. leftShift = "fireMissile",
  99. t = "launchSmokeGrenade",
  100. tab = "switchMode",
  101. up = "cannonUp",
  102. down = "cannonDown",
  103. left = "cannonLeft",
  104. right = "cannonRight"
  105. }
  106.  
  107. local SPAAControls = {
  108. accelerate = false,
  109. decelerate = false,
  110. turnLeft = false,
  111. turnRight = false,
  112. suspensionUp = false,
  113. suspensionDown = false,
  114. fireCannon = false,
  115. fireAutocannon = false,
  116. targetSwitch = false,
  117. fireMissile = {},
  118. launchSmokeGrenade = false,
  119. cannonControlMode = "manual",
  120. cannonUp = false,
  121. cannonDown = false,
  122. cannonLeft = false,
  123. cannonRight = false,
  124. }
  125.  
  126. local SPAAKeyMap = {
  127. w = "accelerate",
  128. s = "decelerate",
  129. a = "turnLeft",
  130. d = "turnRight",
  131. e = "suspensionUp",
  132. q = "suspensionDown",
  133. space = "fireCannon",
  134. r = "targetSwitch",
  135. f = "fireAutocannon",
  136. leftCtrl = "fireCOAX",
  137. leftShift = "fireMissile",
  138. t = "launchSmokeGrenade",
  139. tab = "switchMode",
  140. up = "cannonUp",
  141. down = "cannonDown",
  142. left = "cannonLeft",
  143. right = "cannonRight"
  144. }
  145.  
  146. local missileId = 1 -- Initial missile ID to be launched
  147. local missileLaunched = {} -- List to store launched missile IDs
  148.  
  149. -- Function to draw the home page
  150. local function drawHomePage()
  151. term.clear()
  152. term.setCursorPos(1, 1)
  153. print("Select Weapon System:")
  154.  
  155. for i, system in ipairs(systems) do
  156. if i == currentSelection then
  157. -- Highlight the selected item in blue
  158. term.clearLine()
  159. term.setCursorPos(1, i + 1)
  160. term.setBackgroundColor(colors.blue)
  161. else
  162. term.setBackgroundColor(colors.black)
  163. end
  164. print(system.name)
  165. term.setBackgroundColor(colors.black)
  166. end
  167. end
  168.  
  169. local function launchMissile()
  170. if type(EMBTControls.fireMissile) ~= "table" then
  171. EMBTControls.fireMissile = {}
  172. end
  173.  
  174. local currentMissileId = missileId
  175. -- Assign a table to this missile's ID in fireMissile, marking it as launched
  176. EMBTControls.fireMissile[currentMissileId] = {launch = true}
  177. missileLaunched[currentMissileId] = true -- Mark this missile as launched
  178. print("Launching missile:", currentMissileId)
  179.  
  180. missileId = missileId + 1 -- Increment missile ID for next launch
  181. end
  182.  
  183. local function turretControl(event, param1)
  184. if event == "key" then
  185. for k, control in pairs(EMBTKeyMap) do
  186. if param1 == keys[k] then
  187.  
  188. if control == "shellSwitch_APHE_Delayed" then
  189. -- User pressed '1'
  190. EMBTControls.shellMode = "APHE_Delayed"
  191. print("Switched shell to APHE_Delayed")
  192.  
  193. elseif control == "shellSwitch_APHE_Proximity" then
  194. -- User pressed '2'
  195. EMBTControls.shellMode = "APHE_Proximity"
  196. print("Switched shell to APHE_Proximity")
  197.  
  198. elseif control == "switchMode" then
  199. -- (existing tab logic)
  200. if EMBTControls.cannonControlMode == "manual" then
  201. EMBTControls.cannonControlMode = "mouseAim"
  202. print("Switched to Mouse Aim mode")
  203. else
  204. EMBTControls.cannonControlMode = "manual"
  205. print("Switched to Manual Control mode")
  206. end
  207.  
  208. elseif control == "fireMissile" then
  209. -- (existing logic)
  210. launchMissile()
  211.  
  212. else
  213. -- (existing logic)
  214. EMBTControls[control] = true
  215. end
  216.  
  217. -- Transmit updated controls state after handling key press
  218. modem.transmit(EMBTControlChannel, EMBTControlChannel, EMBTControls)
  219. print("Key pressed:", k, control)
  220. end
  221. end
  222.  
  223. elseif event == "key_up" then
  224. for k, control in pairs(EMBTKeyMap) do
  225. if param1 == keys[k] then
  226. -- (existing release logic)
  227. if control ~= "switchMode"
  228. and control ~= "shellSwitch_APHE_Delayed"
  229. and control ~= "shellSwitch_APHE_Proximity" then
  230.  
  231. EMBTControls[control] = false
  232. modem.transmit(EMBTControlChannel, EMBTControlChannel, EMBTControls)
  233. print("Key released:", k, control)
  234. end
  235. end
  236. end
  237. end
  238. end
  239.  
  240. local function SHARDControl(event,param1)
  241. if event == "key" then
  242. -- Key press event
  243. for k, control in pairs(SHARDKeyMap) do
  244. if param1 == keys[k] then
  245. if control == "switchMode" then
  246. -- Switch cannon control mode when Tab is pressed
  247. if SHARDControls.cannonControlMode == "manual" then
  248. SHARDControls.cannonControlMode = "mouseAim"
  249. print("Switched to Mouse Aim mode")
  250. else
  251. SHARDControls.cannonControlMode = "manual"
  252. print("Switched to Manual Control mode")
  253. end
  254. else
  255. SHARDControls[control] = true
  256. end
  257. modem.transmit(SHARDControlChannel, SHARDControlChannel, SHARDControls)
  258. print("Key pressed:", k, control)
  259. end
  260. end
  261.  
  262. elseif event == "key_up" then
  263. -- Key release event
  264. for k, control in pairs(SHARDKeyMap) do
  265. if param1 == keys[k] then
  266. if control ~= "switchMode" then
  267. SHARDControls[control] = false
  268. modem.transmit(SHARDControlChannel, SHARDControlChannel, SHARDControls)
  269. print("Key released:", k, control)
  270. end
  271. end
  272. end
  273. end
  274. end
  275.  
  276. local droneControls = {
  277. forward = false,
  278. backward = false,
  279. strafeLeft = false,
  280. strafeRight = false,
  281. turnLeft = false,
  282. turnRight = false,
  283. goUp = false,
  284. goDown = false,
  285. designate = false
  286. }
  287.  
  288. local droneKeyMap = {
  289. w = "forward",
  290. s = "backward",
  291. q = "strafeLeft",
  292. e = "strafeRight",
  293. a = "turnLeft",
  294. d = "turnRight",
  295. leftShift = "goUp",
  296. leftCtrl = "goDown",
  297. space = "designate",
  298. }
  299.  
  300. local function droneControl(event, param1)
  301. if event == "key" then
  302. for k, control in pairs(droneKeyMap) do
  303. if param1 == keys[k] then
  304. -- Transmit updated controls state after handling key press
  305. droneControls[control] = true
  306. modem.transmit(droneControlChannel, droneControlChannel, droneControls)
  307. print("Key pressed:", k, control)
  308. end
  309. end
  310.  
  311. elseif event == "key_up" then
  312. for k, control in pairs(droneKeyMap) do
  313. if param1 == keys[k] then
  314. -- (existing release logic)
  315. if control ~= "switchMode"
  316. and control ~= "shellSwitch_APHE_Delayed"
  317. and control ~= "shellSwitch_APHE_Proximity" then
  318.  
  319. droneControls[control] = false
  320. modem.transmit(droneControlChannel, droneControlChannel, droneControls)
  321. print("Key released:", k, control)
  322. end
  323. end
  324. end
  325. end
  326. end
  327.  
  328. -- Function to draw the EMBTControls page
  329. local function drawEMBTControlsPage(event,key)
  330. term.setCursorPos(1, 1)
  331. print(systems[currentSelection].EMBTControlsPage)
  332. print("Press Backspace to return")
  333.  
  334. if event == "key" then
  335. if key == keys.backspace then
  336. currentPage = "home"
  337. drawHomePage()
  338. end
  339. end
  340.  
  341. if systems[currentSelection].name == "Main Turret" then
  342. -- Mouse Aim Mode Indicator with color
  343. if EMBTControls.cannonControlMode == "mouseAim" then
  344. term.setCursorPos(1, 3)
  345. term.setBackgroundColor(colors.green) -- Green for ON
  346. term.clearLine() -- Clear line to ensure the color is applied only for the current line
  347. print("Mouse Aim Mode: ON")
  348. term.setBackgroundColor(colors.black)
  349. else
  350. term.setCursorPos(1, 3)
  351. term.setBackgroundColor(colors.red) -- Red for OFF
  352. term.clearLine() -- Clear line to ensure the color is applied only for the current line
  353. print("Mouse Aim Mode: OFF")
  354. term.setBackgroundColor(colors.black)
  355. end
  356. term.setCursorPos(1,4)
  357. term.clearLine()
  358. print("Shell: "..EMBTControls.shellMode)
  359. turretControl(event,key)
  360. elseif systems[currentSelection].name == "SHARD" then
  361. -- SHARD system EMBTControls here
  362. if SHARDControls.cannonControlMode == "mouseAim" then
  363. term.setCursorPos(1, 3)
  364. term.setBackgroundColor(colors.green) -- Green for ON
  365. term.clearLine() -- Clear line to ensure the color is applied only for the current line
  366. print("Auto lock Mode: ON")
  367. term.setBackgroundColor(colors.black)
  368. else
  369. term.setCursorPos(1, 3)
  370. term.setBackgroundColor(colors.red) -- Red for OFF
  371. term.clearLine() -- Clear line to ensure the color is applied only for the current line
  372. print("Auto lock Mode: OFF")
  373. term.setBackgroundColor(colors.black)
  374. end
  375. SHARDControl(event,key)
  376. elseif systems[currentSelection].name =="Drone" then
  377. droneControl(event,key)
  378. end
  379. end
  380.  
  381. -- Function to navigate through systems
  382. local function navigateSystems(key)
  383. if key == keys.up then
  384. currentSelection = currentSelection - 1
  385. if currentSelection < 1 then
  386. currentSelection = #systems
  387. end
  388. elseif key == keys.down then
  389. currentSelection = currentSelection + 1
  390. if currentSelection > #systems then
  391. currentSelection = 1
  392. end
  393. end
  394. end
  395.  
  396. local function handleHomePageKey(event, key)
  397. if event == "key" then
  398. if key == keys.enter then
  399. currentPage = systems[currentSelection].EMBTControlsPage
  400. drawEMBTControlsPage()
  401. elseif key == keys.up or key == keys.down then
  402. navigateSystems(key)
  403. drawHomePage()
  404. end
  405. end
  406. end
  407.  
  408. while true do
  409. if currentPage == "home" then
  410. drawHomePage()
  411. local event, key = os.pullEvent()
  412. if event == "key" and key then
  413. handleHomePageKey(event, key)
  414. end
  415. elseif currentPage == systems[currentSelection].EMBTControlsPage then
  416. local event, key = os.pullEvent()
  417. drawEMBTControlsPage(event, key)
  418. end
  419. end
Advertisement
Add Comment
Please, Sign In to add comment