MegiRicky

SPAAPocket

Mar 17th, 2025
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. local modem = peripheral.find("modem") or error("No modem attached", 0)
  2.  
  3. print("Input the controlChannel, default = 2100")
  4. local controlChannel = io.read()
  5. if controlChannel == "" then
  6. controlChannel = 2100
  7. end
  8. controlChannel = tonumber(controlChannel)
  9. modem.open(controlChannel) -- Open a channel to communicate
  10.  
  11. print("Remote control started. Use WASD keys to control movement, e(up) q(down) for suspension, Space for cannon, Shift for autocannon, T for smoke grenades, Tab to switch cannon control mode.")
  12.  
  13. local controls = {
  14. accelerate = false,
  15. decelerate = false,
  16. turnLeft = false,
  17. turnRight = false,
  18. suspensionUp = false,
  19. suspensionDown = false,
  20. fireCannon = false,
  21. fireAutocannon = false,
  22. targetSwitch = false,
  23. fireMissile = {},
  24. launchSmokeGrenade = false,
  25. cannonControlMode = "manual",
  26. cannonUp = false,
  27. cannonDown = false,
  28. cannonLeft = false,
  29. cannonRight = false,
  30. }
  31.  
  32. local keyMap = {
  33. w = "accelerate",
  34. s = "decelerate",
  35. a = "turnLeft",
  36. d = "turnRight",
  37. e = "suspensionUp",
  38. q = "suspensionDown",
  39. space = "fireCannon",
  40. leftCtrl = "fireAutocannon",
  41. r = "targetSwitch",
  42. leftShift = "fireMissile",
  43. t = "launchSmokeGrenade",
  44. tab = "switchMode",
  45. up = "cannonUp",
  46. down = "cannonDown",
  47. left = "cannonLeft",
  48. right = "cannonRight"
  49. }
  50.  
  51. local missileId = 1 -- Initial missile ID to be launched
  52. local missileLaunched = {} -- List to store launched missile IDs
  53.  
  54. -- Function to send the current controls state
  55. local function sendControls()
  56. modem.transmit(controlChannel, controlChannel, controls)
  57. end
  58.  
  59. -- Function to launch the next missile
  60. local function launchMissile()
  61. if type(controls.fireMissile) ~= "table" then
  62. controls.fireMissile = {}
  63. end
  64.  
  65. local currentMissileId = missileId
  66. -- Assign a table to this missile's ID in fireMissile, marking it as launched
  67. controls.fireMissile[currentMissileId] = {launch = true}
  68. missileLaunched[currentMissileId] = true -- Mark this missile as launched
  69. print("Launching missile:", currentMissileId)
  70.  
  71. missileId = missileId + 1 -- Increment missile ID for next launch
  72. end
  73.  
  74. while true do
  75. local event, param1, param2 = os.pullEvent()
  76.  
  77. if event == "key" then
  78. -- Key press event
  79. for k, control in pairs(keyMap) do
  80. if param1 == keys[k] then
  81. if control == "switchMode" then
  82. -- Switch cannon control mode when Tab is pressed
  83. if controls.cannonControlMode == "manual" then
  84. controls.cannonControlMode = "mouseAim"
  85. print("Switched to Mouse Aim mode")
  86. else
  87. controls.cannonControlMode = "manual"
  88. print("Switched to Manual Control mode")
  89. end
  90. elseif control == "fireMissile" then
  91. launchMissile()
  92. else
  93. controls[control] = true
  94. end
  95. sendControls()
  96. print("Key pressed:", k, control)
  97. end
  98. end
  99.  
  100. elseif event == "key_up" then
  101. -- Key release event
  102. for k, control in pairs(keyMap) do
  103. if param1 == keys[k] then
  104. if control ~= "switchMode" then
  105. controls[control] = false
  106. sendControls()
  107. print("Key released:", k, control)
  108. end
  109. end
  110. end
  111. end
  112. end
  113.  
Advertisement
Add Comment
Please, Sign In to add comment