Advertisement
minecraft_storm

tardim_control

Apr 29th, 2024 (edited)
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.51 KB | None | 0 0
  1. local basalt = require("basalt")
  2. local modem = peripheral.find("modem") or error("No modem attached", 0)
  3.  
  4. terminate = false;
  5. connected = false;
  6. address = 0
  7. replyAddress = 23
  8. password = "tardim-1"
  9.  
  10.  
  11. modem.open(replyAddress)
  12. print("boot")
  13.  
  14. function listen()
  15. while not terminate do
  16. local event, par1, par2, par3, par4, par5 = os.pullEvent()
  17. if event == "modem_message" then
  18. local side = par1
  19. local channel = par2
  20. local replyChannel = par3
  21. local message = par4
  22. local distance = par5
  23. messageReceived(side, channel, replyChannel, message, distance)
  24. end
  25. sleep(0.1)
  26. end
  27. end
  28.  
  29. function messageReceived(side, channel, replyChannel, message, distance)
  30. if message[1] == "ok" then
  31. address = tonumber(message[2])
  32. sleep(0.1)
  33. modem.transmit(address, replyAddress, {"pass", password})
  34. end
  35. if message[1] == "correct" then
  36. connected = true
  37. updateConnection("Connected")
  38. end
  39. if message[1] == "status" then
  40. updateStatus(message[2])
  41. updateFuel(message[3])
  42. end
  43. if message[1] == "location_set" then
  44. updateSummonStatus("Location Set")
  45. end
  46. if message[1] == "remat" then
  47. updateSummonStatus("Remat")
  48. end
  49. if message[1] == "demat" then
  50. updateSummonStatus("Demat")
  51. end
  52. if message[1] == "inFlight" then
  53. updateSummonStatus("Tardim is already in flight")
  54. end
  55. if message[1] == "landed" then
  56. updateSummonStatus("Tardim is already lannded")
  57. end
  58. end
  59.  
  60. --> Now we want to create a base frame, we call the variable "main" - by default everything you create is visible. (you don't need to use :show())
  61. local main = basalt.createFrame()
  62.  
  63. local buttonConnect = main:addButton()
  64. buttonConnect:setPosition(1, 1)
  65. buttonConnect:setSize(10, 1)
  66. buttonConnect:setText("Connect")
  67.  
  68. local function connectButtonClick()
  69. modem.transmit(address, replyAddress, {"connect"})
  70. end
  71.  
  72. buttonConnect:onClick(connectButtonClick)
  73.  
  74. -- Connection field
  75. local connectionLabel = main:addLabel()
  76. connectionLabel:setPosition(1, 2)
  77. connectionLabel:setSize(30, 1)
  78. connectionLabel:setText("Connection: Not connected")
  79.  
  80. -- Status field
  81. local statusLabel = main:addLabel()
  82. statusLabel:setPosition(1, 3)
  83. statusLabel:setSize(30, 1)
  84. statusLabel:setText("Status: ")
  85.  
  86. -- Fuel field
  87. local fuelLabel = main:addLabel()
  88. fuelLabel:setPosition(1, 4)
  89. fuelLabel:setSize(30, 1)
  90. fuelLabel:setText("Fuel: N/A")
  91.  
  92. -- Coordinate input fields
  93. local xLabel = main:addLabel()
  94. xLabel:setPosition(1, 6)
  95. xLabel:setSize(5, 1)
  96. xLabel:setText("X:")
  97.  
  98. local xInput = main:addInput()
  99. xInput:setPosition(7, 6)
  100. xInput:setSize(5, 1)
  101. xInput:setInputType("number")
  102. xInput:setDefaultText("0")
  103. xInput:onChange(function(self)
  104. xInputValue = tonumber(self:getValue())
  105. end)
  106.  
  107. local yLabel = main:addLabel()
  108. yLabel:setPosition(1, 7)
  109. yLabel:setSize(5, 1)
  110. yLabel:setText("Y:")
  111.  
  112. local yInput = main:addInput()
  113. yInput:setPosition(7, 7)
  114. yInput:setSize(5, 1)
  115. yInput:setInputType("number")
  116. yInput:setDefaultText("0")
  117. yInput:onChange(function(self)
  118. yInputValue = tonumber(self:getValue())
  119. end)
  120.  
  121. local zLabel = main:addLabel()
  122. zLabel:setPosition(1, 8)
  123. zLabel:setSize(5, 1)
  124. zLabel:setText("Z:")
  125.  
  126. local zInput = main:addInput()
  127. zInput:setPosition(7, 8)
  128. zInput:setSize(5, 1)
  129. zInput:setInputType("number")
  130. zInput:setDefaultText("0")
  131. zInput:onChange(function(self)
  132. zInputValue = tonumber(self:getValue())
  133. end)
  134.  
  135. -- Remat button
  136. local rematButton = main:addButton()
  137. rematButton:setPosition(15, 6)
  138. rematButton:setSize(10, 1)
  139. rematButton:setText("Remat")
  140.  
  141. local function rematButtonClick()
  142. if connected == true then
  143. modem.transmit(address, replyAddress, {"remat"})
  144. end
  145. end
  146.  
  147. rematButton:onClick(rematButtonClick)
  148.  
  149. -- Demat button
  150. local dematButton = main:addButton()
  151. dematButton:setPosition(15, 7)
  152. dematButton:setSize(10, 1)
  153. dematButton:setText("Demat")
  154.  
  155. local function dematButtonClick()
  156. if connected == true then
  157. modem.transmit(address, replyAddress, {"demat"})
  158. end
  159. end
  160.  
  161. dematButton:onClick(dematButtonClick)
  162.  
  163. -- Summon Status field
  164. local summonStatusLabel = main:addLabel()
  165. summonStatusLabel:setPosition(1, 9)
  166. summonStatusLabel:setSize(30, 1)
  167.  
  168. local confirmButton = main:addButton()
  169. confirmButton:setPosition(1, 11)
  170. confirmButton:setSize(10, 1)
  171. confirmButton:setText("Confirm")
  172.  
  173. local function confirmButtonClick()
  174. if connected == true then
  175. if xInputValue and yInputValue and zInputValue then
  176. updateSummonStatus("Location send")
  177. modem.transmit(address, replyAddress, {"location", xInputValue, yInputValue, zInputValue})
  178. else
  179. updateSummonStatus("Please enter valid coordinates.")
  180. end
  181. end
  182. end
  183. confirmButton:onClick(confirmButtonClick)
  184.  
  185. function updateStatus(status)
  186. statusLabel:setText("Status: " .. tostring(status))
  187. end
  188.  
  189. function updateConnection(status)
  190. connectionLabel:setText("Connection: " .. status)
  191. end
  192.  
  193. function updateFuel(fuel)
  194. fuelLabel:setText("Fuel: " .. fuel)
  195. end
  196.  
  197. function updateSummonStatus(status)
  198. summonStatusLabel:setText(status)
  199. end
  200.  
  201. function main_loop()
  202. basalt.autoUpdate()
  203. while true do
  204.  
  205. end
  206. end
  207.  
  208. function ping()
  209. while true do
  210. if connected == true then
  211. modem.transmit(address, replyAddress, {"status"})
  212. end
  213. sleep(2)
  214. end
  215. end
  216.  
  217. parallel.waitForAll(listen, main_loop, ping)
  218.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement