Advertisement
Chaos_Cash

Drone control pocket

Aug 13th, 2024 (edited)
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.37 KB | None | 0 0
  1. function startup()
  2.  
  3. droneComputerId = 2
  4.  
  5. rednet.open("back")
  6.  
  7.  
  8. readingOutput = {}
  9. readingOutput["teleportXPos"] = ""
  10. readingOutput["teleportYPos"] = ""
  11. readingOutput["teleportZPos"] = ""
  12.  
  13. readingOutput["pickUpXPos"] = ""
  14. readingOutput["pickUpYPos"] = ""
  15. readingOutput["pickUpZPos"] = ""
  16.  
  17. blinkIsOn = true
  18. buttonIsThere = false
  19. pickUpButtonIsThere = false
  20.  
  21.  
  22. rechargeStationCoords = {["x"]=-7,["y"]=87,["z"]=-1}
  23. itemStationCoords = {["x"]=-7,["y"]=87,["z"]=0}
  24. end
  25.  
  26.  
  27.  
  28. function main()
  29.  
  30. while true do
  31.  
  32. info1,info2,info3,info4 = os.pullEvent()
  33.  
  34.  
  35. if info1 == "rednet_message" then
  36.  
  37.  
  38. if info3 == "outOfRange" then
  39. print("The destination is out of range")
  40. end
  41.  
  42.  
  43. if type(info3) == "table" then
  44.  
  45.  
  46. if info3["action"] == "sendingLastDronePos" then
  47. lastPosX = info3["x"]
  48. lastPosY = info3["y"]
  49. lastPosZ = info3["z"]
  50. end
  51.  
  52. end
  53.  
  54. end
  55.  
  56.  
  57.  
  58. if curEnv == "home" then
  59.  
  60. if buttonCheck(1,4,11,6) then
  61. TeleportMenu()
  62. end
  63.  
  64. if buttonCheck(13,4,26,6) then
  65. pickUpShipMenu()
  66. end
  67.  
  68. if buttonCheck(15,8,25,10) then
  69. pickUpItem()
  70. end
  71.  
  72. if buttonCheck(1,8,13,10) then
  73. rednet.send(droneComputerId,"pickUpPlayer")
  74. end
  75.  
  76. end
  77.  
  78.  
  79. if curEnv == "TeleportMenu" then
  80.  
  81. betterRead(false,{"0","1","2","3","4","5","6","7","8","9","-"})
  82.  
  83. if info1 == "key" and info2 == 257 then
  84.  
  85. if curReading == "teleportXPos" then
  86. changeReading("teleportYPos",4,5)
  87. elseif curReading == "teleportYPos" then
  88. changeReading("teleportZPos",4,6)
  89. elseif curReading == "teleportZPos" then
  90. stopReading()
  91. end
  92.  
  93. end
  94.  
  95. if lineCheck(4) then
  96. changeReading("teleportXPos",4,4)
  97. end
  98.  
  99. if lineCheck(5) then
  100. changeReading("teleportYPos",4,5)
  101. end
  102.  
  103. if lineCheck(6) then
  104. changeReading("teleportZPos",4,6)
  105. end
  106.  
  107. if tonumber(readingOutput["teleportXPos"]) ~= nil and tonumber(readingOutput["teleportYPos"]) ~= nil and tonumber(readingOutput["teleportZPos"]) ~= nil and (not buttonIsThere) then
  108. button("Start",1,8,9,10)
  109. term.setTextColor(colors.white)
  110. buttonIsThere = true
  111. elseif (not (tonumber(readingOutput["teleportXPos"]) ~= nil and tonumber(readingOutput["teleportYPos"]) ~= nil and tonumber(readingOutput["teleportZPos"]) ~= nil)) and buttonIsThere then
  112. button("Start",1,8,9,10,colors.red)
  113. buttonIsThere = false
  114. term.setTextColor(colors.white)
  115. end
  116.  
  117. if lastPosX ~= nil then
  118. button("Return",11,8,18,10)
  119. term.setTextColor(colors.white)
  120. end
  121.  
  122. if lastPosX ~= nil and buttonCheck(11,8,18,10) then
  123. getLastDronePos()
  124. rednet.send(droneComputerId,{["action"]="goto",["x"]=lastPosX,["y"]=lastPosY,["z"]=lastPosZ})
  125. end
  126.  
  127. if buttonCheck(1,8,9,10) and buttonIsThere then
  128. getLastDronePos()
  129. rednet.send(droneComputerId,{["action"]="goto",["x"]=tonumber(readingOutput["teleportXPos"]),["y"]=tonumber(readingOutput["teleportYPos"]),["z"]=tonumber(readingOutput["teleportZPos"])})
  130. end
  131.  
  132. if buttonCheck(21,18,26,20) then
  133. homeMenu()
  134. cursorBlinkTimer = nil
  135. end
  136.  
  137.  
  138. end
  139.  
  140.  
  141. if curEnv == "pickUpShipMenu" then
  142.  
  143. betterRead(false,{"0","1","2","3","4","5","6","7","8","9","-"})
  144.  
  145. if info1 == "key" and info2 == 257 then
  146.  
  147. if curReading == "pickUpXPos" then
  148. changeReading("pickUpYPos",4,5)
  149. elseif curReading == "pickUpYPos" then
  150. changeReading("pickUpZPos",4,6)
  151. elseif curReading == "pickUpZPos" then
  152. stopReading()
  153. end
  154.  
  155. end
  156.  
  157. if lineCheck(4) then
  158. changeReading("pickUpXPos",4,4)
  159. end
  160.  
  161. if lineCheck(5) then
  162. changeReading("pickUpYPos",4,5)
  163. end
  164.  
  165. if lineCheck(6) then
  166. changeReading("pickUpZPos",4,6)
  167. end
  168.  
  169. if tonumber(readingOutput["pickUpXPos"]) ~= nil and tonumber(readingOutput["pickUpYPos"]) ~= nil and tonumber(readingOutput["pickUpZPos"]) ~= nil and (not pickUpButtonIsThere) then
  170. button("Start",1,8,9,10)
  171. term.setTextColor(colors.white)
  172. pickUpButtonIsThere = true
  173. elseif (not (tonumber(readingOutput["pickUpXPos"]) ~= nil and tonumber(readingOutput["pickUpYPos"]) ~= nil and tonumber(readingOutput["pickUpZPos"]) ~= nil)) and pickUpButtonIsThere then
  174. button("Start",1,8,9,10,colors.red)
  175. pickUpButtonIsThere = false
  176. term.setTextColor(colors.white)
  177. end
  178.  
  179. if buttonCheck(1,8,9,10) and pickUpButtonIsThere then
  180. rednet.send(droneComputerId,{["action"]="pickUpShip",["x"]=tonumber(readingOutput["pickUpXPos"]),["y"]=tonumber(readingOutput["pickUpYPos"]),["z"]=tonumber(readingOutput["pickUpZPos"])})
  181. end
  182.  
  183. if buttonCheck(21,18,26,20) then
  184. homeMenu()
  185. cursorBlinkTimer = nil
  186. end
  187.  
  188.  
  189. end
  190.  
  191. end
  192.  
  193. end
  194.  
  195.  
  196.  
  197. function pickUpItem()
  198.  
  199. rednet.send(droneComputerId,{["action"]="pickUpItem",["x"]=itemStationCoords["x"],["y"]=itemStationCoords["y"],["z"]=itemStationCoords["z"]})
  200.  
  201. end
  202.  
  203.  
  204.  
  205. function pickUpShipMenu()
  206. curEnv = "pickUpShipMenu"
  207. term.clear()
  208.  
  209. headline("Pick up ship")
  210. button("Back",21,18,26,20)
  211.  
  212. changeReading("pickUpXPos",4,4)
  213.  
  214. term.setCursorPos(1,4)
  215. term.setTextColor(colors.green)
  216. term.write("X: ")
  217. term.setTextColor(colors.white)
  218. print(readingOutput["pickUpXPos"])
  219. term.setTextColor(colors.green)
  220. term.write("Y: ")
  221. term.setTextColor(colors.white)
  222. print(readingOutput["pickUpYPos"])
  223. term.setTextColor(colors.green)
  224. term.write("Z: ")
  225. term.setTextColor(colors.white)
  226. print(readingOutput["pickUpZPos"])
  227.  
  228.  
  229. if tonumber(readingOutput["teleportXPos"]) ~= nil and tonumber(readingOutput["teleportYPos"]) ~= nil and tonumber(readingOutput["teleportZPos"]) ~= nil then
  230. button("Start",1,8,9,10)
  231. pickUpButtonIsThere = true
  232. else
  233. button("Start",1,8,9,10,colors.red)
  234. pickUpButtonIsThere = false
  235. end
  236.  
  237. term.setTextColor(colors.white)
  238. end
  239.  
  240.  
  241.  
  242. function pickUpShip(x,y,z)
  243. rednet.send(droneComputerId,{["action"]="pickUpShip",["x"]=x,["y"]=y,["z"]=z})
  244. end
  245.  
  246.  
  247.  
  248. function getLastDronePos()
  249. rednet.send(droneComputerId,"getLastDronePos")
  250. end
  251.  
  252.  
  253.  
  254. function homeMenu()
  255. curEnv = "home"
  256. term.clear()
  257.  
  258. headline("Home")
  259. button("Teleport",1,4,11,6)
  260. button("Pick up ship",13,4,26,6)
  261. button("Take item",15,8,25,10)
  262. button("Take player",1,8,13,10)
  263.  
  264. end
  265.  
  266.  
  267.  
  268. function TeleportMenu()
  269. term.clear()
  270. curEnv = "TeleportMenu"
  271.  
  272. changeReading("teleportXPos",4,4)
  273.  
  274. headline("Teleport")
  275. button("Back",21,18,26,20)
  276.  
  277. term.setCursorPos(1,4)
  278. term.setTextColor(colors.green)
  279. term.write("X: ")
  280. term.setTextColor(colors.white)
  281. print(readingOutput["teleportXPos"])
  282. term.setTextColor(colors.green)
  283. term.write("Y: ")
  284. term.setTextColor(colors.white)
  285. print(readingOutput["teleportYPos"])
  286. term.setTextColor(colors.green)
  287. term.write("Z: ")
  288. term.setTextColor(colors.white)
  289. print(readingOutput["teleportZPos"])
  290.  
  291.  
  292. if tonumber(readingOutput["teleportXPos"]) ~= nil and tonumber(readingOutput["teleportYPos"]) ~= nil and tonumber(readingOutput["teleportZPos"]) ~= nil then
  293. button("Start",1,8,9,10)
  294. buttonIsThere = true
  295. else
  296. button("Start",1,8,9,10,colors.red)
  297. buttonIsThere = false
  298. end
  299.  
  300. if lastPosX ~= nil then
  301. button("Return",11,8,18,10)
  302. else
  303. button("Return",11,8,18,10,colors.red)
  304. end
  305. term.setTextColor(colors.white)
  306.  
  307. end
  308.  
  309.  
  310.  
  311. function betterRead(isBlacklist,filter)
  312.  
  313. if curReading ~= nil then
  314.  
  315.  
  316. if curReadingPosX == nil then
  317. curReadingPosX = readingPosX+string.len(readingOutput[curReading])
  318. end
  319.  
  320.  
  321. if cursorBlinkTimer == nil then
  322. cursorBlinkTimer = os.startTimer(0.5)
  323. end
  324.  
  325.  
  326. if info1 == "char" then
  327.  
  328. isBlacklisted = not isBlacklist
  329. for k,v in pairs(filter) do
  330.  
  331. if info2 == filter[k] then
  332. isBlacklisted = isBlacklist
  333. end
  334.  
  335. end
  336.  
  337.  
  338. if not isBlacklisted then
  339. if readingOutput[curReading] == nil then
  340. readingOutput[curReading] = ""
  341. end
  342.  
  343. readingOutput[curReading] = readingOutput[curReading] .. info2
  344. term.setCursorPos(curReadingPosX,readingPosY)
  345. term.write(info2)
  346. curReadingPosX = curReadingPosX+1
  347.  
  348. if blinkIsOn then
  349. term.write("_")
  350. end
  351.  
  352. end
  353.  
  354. end
  355.  
  356.  
  357. if info1 == "key" and info2 == 259 and curReadingPosX > readingPosX then
  358.  
  359. curReadingPosX = curReadingPosX-1
  360. term.setCursorPos(curReadingPosX+1,readingPosY)
  361. term.write(" ")
  362. term.setCursorPos(curReadingPosX,readingPosY)
  363. if blinkIsOn then
  364. term.write("_")
  365. else
  366. term.write(" ")
  367. end
  368.  
  369. readSave = readingOutput[curReading]
  370. readingOutput[curReading] = ""
  371. for i=1,string.len(readSave)-1 do
  372. readingOutput[curReading] = readingOutput[curReading] .. string.char(string.byte(readSave,i))
  373. end
  374.  
  375. end
  376.  
  377.  
  378. if info1 == "timer" and info2 == cursorBlinkTimer then
  379.  
  380. if blinkIsOn then
  381. term.setCursorPos(curReadingPosX,readingPosY)
  382. term.write("_")
  383. else
  384. term.setCursorPos(curReadingPosX,readingPosY)
  385. term.write(" ")
  386. end
  387.  
  388. cursorBlinkTimer = os.startTimer(0.5)
  389. blinkIsOn = (not blinkIsOn)
  390. end
  391.  
  392.  
  393. end
  394. end
  395.  
  396.  
  397.  
  398. function changeReading(readingName,xPos,yPos)
  399. if type(curReadingPosX) == "number" and type(readingPosY) == "number" then
  400. term.setCursorPos(curReadingPosX,readingPosY)
  401. term.write(" ")
  402. end
  403.  
  404. blinkIsOn = true
  405. curReading = readingName
  406. readingPosX = xPos
  407. readingPosY = yPos
  408. curReadingPosX = nil
  409. cursorBlinkTimer = os.startTimer(0.05)
  410.  
  411. end
  412.  
  413.  
  414.  
  415. function stopReading()
  416.  
  417. term.setCursorPos(curReadingPosX,readingPosY)
  418. term.write(" ")
  419. curReading = nil
  420. cursorBlinkTimer = nil
  421.  
  422. end
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430. -- buttons and all that stuff
  431.  
  432. function headline(headline)
  433. width = term.getSize()
  434. headline_lenght=string.len(" "..headline.." ")
  435. headline_pos=(width/2)-(headline_lenght/2)+1
  436. term.setCursorPos(headline_pos,1)
  437. term.setBackgroundColor(colors.yellow)
  438. term.setTextColor(colors.blue)
  439. term.write(" "..headline.." ")
  440. term.setBackgroundColor(colors.black)
  441. term.setTextColor(colors.white)
  442. end
  443.  
  444.  
  445.  
  446. function button(button_text,button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2,button_color)
  447. term.setTextColor(colors.green)
  448.  
  449. if button_color~=nil then
  450. term.setTextColor(button_color)
  451. end
  452.  
  453. square(button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2,colors.black,"-","|")
  454. term.setCursorPos(math.ceil(button_pos_x1-string.len(button_text)/2+(button_pos_x2-button_pos_x1)/2),button_pos_y1+(button_pos_y2-button_pos_y1)/2)
  455. term.write(button_text)
  456. end
  457.  
  458.  
  459.  
  460. function buttonCheck(b_check_x1,b_check_y1,b_check_x2,b_check_y2)
  461. if info1=="mouse_click" and info3 > b_check_x1-1 and info3 < b_check_x2+1 and info4 > b_check_y1-1 and info4 < b_check_y2+1 then
  462. info1 = nil
  463. return true
  464. else
  465. return false
  466. end
  467. end
  468.  
  469.  
  470.  
  471. function square(x1,y1,x2,y2,back_color_square,symbol_square_x,symbol_square_y,text_color)
  472. x_1=x1
  473. y_1=y1
  474. x_2=x2
  475. y_2=y2
  476. while x_1~=x2+1 do
  477. term.setBackgroundColor(back_color_square)
  478. term.setCursorPos(x_1,y_1)
  479. if text_color~=nil then
  480. term.setTextColor(text_color)
  481. end
  482. term.write(symbol_square_x)
  483. x_1=x_1+1
  484. end
  485.  
  486. while y_1~=y2-1 do
  487. term.setCursorPos(x_1-1,y_1+1)
  488. term.write(symbol_square_y)
  489. y_1=y_1+1
  490. end
  491. x2=x2-1
  492. while x_2~=x1-1 do
  493. term.setCursorPos(x_2,y_2)
  494. term.write(symbol_square_x)
  495. x_2=x_2-1
  496. end
  497.  
  498. while y_2~=y1+1 do
  499. term.setCursorPos(x_2+1,y_2-1)
  500. term.write(symbol_square_y)
  501. y_2=y_2-1
  502. end
  503. term.setBackgroundColor(colors.black)
  504. end
  505.  
  506.  
  507.  
  508. function lineCheck(y)
  509.  
  510. if info1 == "mouse_click" and info4 == y then
  511. return true
  512. else
  513. return false
  514. end
  515.  
  516. end
  517.  
  518. -------------------------------
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526. homeMenu()
  527. startup()
  528. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement