Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function startup()
- droneComputerId = 2
- rednet.open("back")
- readingOutput = {}
- readingOutput["teleportXPos"] = ""
- readingOutput["teleportYPos"] = ""
- readingOutput["teleportZPos"] = ""
- readingOutput["pickUpXPos"] = ""
- readingOutput["pickUpYPos"] = ""
- readingOutput["pickUpZPos"] = ""
- blinkIsOn = true
- buttonIsThere = false
- pickUpButtonIsThere = false
- rechargeStationCoords = {["x"]=-7,["y"]=87,["z"]=-1}
- itemStationCoords = {["x"]=-7,["y"]=87,["z"]=0}
- end
- function main()
- while true do
- info1,info2,info3,info4 = os.pullEvent()
- if info1 == "rednet_message" then
- if info3 == "outOfRange" then
- print("The destination is out of range")
- end
- if type(info3) == "table" then
- if info3["action"] == "sendingLastDronePos" then
- lastPosX = info3["x"]
- lastPosY = info3["y"]
- lastPosZ = info3["z"]
- end
- end
- end
- if curEnv == "home" then
- if buttonCheck(1,4,11,6) then
- TeleportMenu()
- end
- if buttonCheck(13,4,26,6) then
- pickUpShipMenu()
- end
- if buttonCheck(15,8,25,10) then
- pickUpItem()
- end
- if buttonCheck(1,8,13,10) then
- rednet.send(droneComputerId,"pickUpPlayer")
- end
- end
- if curEnv == "TeleportMenu" then
- betterRead(false,{"0","1","2","3","4","5","6","7","8","9","-"})
- if info1 == "key" and info2 == 257 then
- if curReading == "teleportXPos" then
- changeReading("teleportYPos",4,5)
- elseif curReading == "teleportYPos" then
- changeReading("teleportZPos",4,6)
- elseif curReading == "teleportZPos" then
- stopReading()
- end
- end
- if lineCheck(4) then
- changeReading("teleportXPos",4,4)
- end
- if lineCheck(5) then
- changeReading("teleportYPos",4,5)
- end
- if lineCheck(6) then
- changeReading("teleportZPos",4,6)
- end
- if tonumber(readingOutput["teleportXPos"]) ~= nil and tonumber(readingOutput["teleportYPos"]) ~= nil and tonumber(readingOutput["teleportZPos"]) ~= nil and (not buttonIsThere) then
- button("Start",1,8,9,10)
- term.setTextColor(colors.white)
- buttonIsThere = true
- elseif (not (tonumber(readingOutput["teleportXPos"]) ~= nil and tonumber(readingOutput["teleportYPos"]) ~= nil and tonumber(readingOutput["teleportZPos"]) ~= nil)) and buttonIsThere then
- button("Start",1,8,9,10,colors.red)
- buttonIsThere = false
- term.setTextColor(colors.white)
- end
- if lastPosX ~= nil then
- button("Return",11,8,18,10)
- term.setTextColor(colors.white)
- end
- if lastPosX ~= nil and buttonCheck(11,8,18,10) then
- getLastDronePos()
- rednet.send(droneComputerId,{["action"]="goto",["x"]=lastPosX,["y"]=lastPosY,["z"]=lastPosZ})
- end
- if buttonCheck(1,8,9,10) and buttonIsThere then
- getLastDronePos()
- rednet.send(droneComputerId,{["action"]="goto",["x"]=tonumber(readingOutput["teleportXPos"]),["y"]=tonumber(readingOutput["teleportYPos"]),["z"]=tonumber(readingOutput["teleportZPos"])})
- end
- if buttonCheck(21,18,26,20) then
- homeMenu()
- cursorBlinkTimer = nil
- end
- end
- if curEnv == "pickUpShipMenu" then
- betterRead(false,{"0","1","2","3","4","5","6","7","8","9","-"})
- if info1 == "key" and info2 == 257 then
- if curReading == "pickUpXPos" then
- changeReading("pickUpYPos",4,5)
- elseif curReading == "pickUpYPos" then
- changeReading("pickUpZPos",4,6)
- elseif curReading == "pickUpZPos" then
- stopReading()
- end
- end
- if lineCheck(4) then
- changeReading("pickUpXPos",4,4)
- end
- if lineCheck(5) then
- changeReading("pickUpYPos",4,5)
- end
- if lineCheck(6) then
- changeReading("pickUpZPos",4,6)
- end
- if tonumber(readingOutput["pickUpXPos"]) ~= nil and tonumber(readingOutput["pickUpYPos"]) ~= nil and tonumber(readingOutput["pickUpZPos"]) ~= nil and (not pickUpButtonIsThere) then
- button("Start",1,8,9,10)
- term.setTextColor(colors.white)
- pickUpButtonIsThere = true
- elseif (not (tonumber(readingOutput["pickUpXPos"]) ~= nil and tonumber(readingOutput["pickUpYPos"]) ~= nil and tonumber(readingOutput["pickUpZPos"]) ~= nil)) and pickUpButtonIsThere then
- button("Start",1,8,9,10,colors.red)
- pickUpButtonIsThere = false
- term.setTextColor(colors.white)
- end
- if buttonCheck(1,8,9,10) and pickUpButtonIsThere then
- rednet.send(droneComputerId,{["action"]="pickUpShip",["x"]=tonumber(readingOutput["pickUpXPos"]),["y"]=tonumber(readingOutput["pickUpYPos"]),["z"]=tonumber(readingOutput["pickUpZPos"])})
- end
- if buttonCheck(21,18,26,20) then
- homeMenu()
- cursorBlinkTimer = nil
- end
- end
- end
- end
- function pickUpItem()
- rednet.send(droneComputerId,{["action"]="pickUpItem",["x"]=itemStationCoords["x"],["y"]=itemStationCoords["y"],["z"]=itemStationCoords["z"]})
- end
- function pickUpShipMenu()
- curEnv = "pickUpShipMenu"
- term.clear()
- headline("Pick up ship")
- button("Back",21,18,26,20)
- changeReading("pickUpXPos",4,4)
- term.setCursorPos(1,4)
- term.setTextColor(colors.green)
- term.write("X: ")
- term.setTextColor(colors.white)
- print(readingOutput["pickUpXPos"])
- term.setTextColor(colors.green)
- term.write("Y: ")
- term.setTextColor(colors.white)
- print(readingOutput["pickUpYPos"])
- term.setTextColor(colors.green)
- term.write("Z: ")
- term.setTextColor(colors.white)
- print(readingOutput["pickUpZPos"])
- if tonumber(readingOutput["teleportXPos"]) ~= nil and tonumber(readingOutput["teleportYPos"]) ~= nil and tonumber(readingOutput["teleportZPos"]) ~= nil then
- button("Start",1,8,9,10)
- pickUpButtonIsThere = true
- else
- button("Start",1,8,9,10,colors.red)
- pickUpButtonIsThere = false
- end
- term.setTextColor(colors.white)
- end
- function pickUpShip(x,y,z)
- rednet.send(droneComputerId,{["action"]="pickUpShip",["x"]=x,["y"]=y,["z"]=z})
- end
- function getLastDronePos()
- rednet.send(droneComputerId,"getLastDronePos")
- end
- function homeMenu()
- curEnv = "home"
- term.clear()
- headline("Home")
- button("Teleport",1,4,11,6)
- button("Pick up ship",13,4,26,6)
- button("Take item",15,8,25,10)
- button("Take player",1,8,13,10)
- end
- function TeleportMenu()
- term.clear()
- curEnv = "TeleportMenu"
- changeReading("teleportXPos",4,4)
- headline("Teleport")
- button("Back",21,18,26,20)
- term.setCursorPos(1,4)
- term.setTextColor(colors.green)
- term.write("X: ")
- term.setTextColor(colors.white)
- print(readingOutput["teleportXPos"])
- term.setTextColor(colors.green)
- term.write("Y: ")
- term.setTextColor(colors.white)
- print(readingOutput["teleportYPos"])
- term.setTextColor(colors.green)
- term.write("Z: ")
- term.setTextColor(colors.white)
- print(readingOutput["teleportZPos"])
- if tonumber(readingOutput["teleportXPos"]) ~= nil and tonumber(readingOutput["teleportYPos"]) ~= nil and tonumber(readingOutput["teleportZPos"]) ~= nil then
- button("Start",1,8,9,10)
- buttonIsThere = true
- else
- button("Start",1,8,9,10,colors.red)
- buttonIsThere = false
- end
- if lastPosX ~= nil then
- button("Return",11,8,18,10)
- else
- button("Return",11,8,18,10,colors.red)
- end
- term.setTextColor(colors.white)
- end
- function betterRead(isBlacklist,filter)
- if curReading ~= nil then
- if curReadingPosX == nil then
- curReadingPosX = readingPosX+string.len(readingOutput[curReading])
- end
- if cursorBlinkTimer == nil then
- cursorBlinkTimer = os.startTimer(0.5)
- end
- if info1 == "char" then
- isBlacklisted = not isBlacklist
- for k,v in pairs(filter) do
- if info2 == filter[k] then
- isBlacklisted = isBlacklist
- end
- end
- if not isBlacklisted then
- if readingOutput[curReading] == nil then
- readingOutput[curReading] = ""
- end
- readingOutput[curReading] = readingOutput[curReading] .. info2
- term.setCursorPos(curReadingPosX,readingPosY)
- term.write(info2)
- curReadingPosX = curReadingPosX+1
- if blinkIsOn then
- term.write("_")
- end
- end
- end
- if info1 == "key" and info2 == 259 and curReadingPosX > readingPosX then
- curReadingPosX = curReadingPosX-1
- term.setCursorPos(curReadingPosX+1,readingPosY)
- term.write(" ")
- term.setCursorPos(curReadingPosX,readingPosY)
- if blinkIsOn then
- term.write("_")
- else
- term.write(" ")
- end
- readSave = readingOutput[curReading]
- readingOutput[curReading] = ""
- for i=1,string.len(readSave)-1 do
- readingOutput[curReading] = readingOutput[curReading] .. string.char(string.byte(readSave,i))
- end
- end
- if info1 == "timer" and info2 == cursorBlinkTimer then
- if blinkIsOn then
- term.setCursorPos(curReadingPosX,readingPosY)
- term.write("_")
- else
- term.setCursorPos(curReadingPosX,readingPosY)
- term.write(" ")
- end
- cursorBlinkTimer = os.startTimer(0.5)
- blinkIsOn = (not blinkIsOn)
- end
- end
- end
- function changeReading(readingName,xPos,yPos)
- if type(curReadingPosX) == "number" and type(readingPosY) == "number" then
- term.setCursorPos(curReadingPosX,readingPosY)
- term.write(" ")
- end
- blinkIsOn = true
- curReading = readingName
- readingPosX = xPos
- readingPosY = yPos
- curReadingPosX = nil
- cursorBlinkTimer = os.startTimer(0.05)
- end
- function stopReading()
- term.setCursorPos(curReadingPosX,readingPosY)
- term.write(" ")
- curReading = nil
- cursorBlinkTimer = nil
- end
- -- buttons and all that stuff
- function headline(headline)
- width = term.getSize()
- headline_lenght=string.len(" "..headline.." ")
- headline_pos=(width/2)-(headline_lenght/2)+1
- term.setCursorPos(headline_pos,1)
- term.setBackgroundColor(colors.yellow)
- term.setTextColor(colors.blue)
- term.write(" "..headline.." ")
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- end
- function button(button_text,button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2,button_color)
- term.setTextColor(colors.green)
- if button_color~=nil then
- term.setTextColor(button_color)
- end
- square(button_pos_x1,button_pos_y1,button_pos_x2,button_pos_y2,colors.black,"-","|")
- 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)
- term.write(button_text)
- end
- function buttonCheck(b_check_x1,b_check_y1,b_check_x2,b_check_y2)
- 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
- info1 = nil
- return true
- else
- return false
- end
- end
- function square(x1,y1,x2,y2,back_color_square,symbol_square_x,symbol_square_y,text_color)
- x_1=x1
- y_1=y1
- x_2=x2
- y_2=y2
- while x_1~=x2+1 do
- term.setBackgroundColor(back_color_square)
- term.setCursorPos(x_1,y_1)
- if text_color~=nil then
- term.setTextColor(text_color)
- end
- term.write(symbol_square_x)
- x_1=x_1+1
- end
- while y_1~=y2-1 do
- term.setCursorPos(x_1-1,y_1+1)
- term.write(symbol_square_y)
- y_1=y_1+1
- end
- x2=x2-1
- while x_2~=x1-1 do
- term.setCursorPos(x_2,y_2)
- term.write(symbol_square_x)
- x_2=x_2-1
- end
- while y_2~=y1+1 do
- term.setCursorPos(x_2+1,y_2-1)
- term.write(symbol_square_y)
- y_2=y_2-1
- end
- term.setBackgroundColor(colors.black)
- end
- function lineCheck(y)
- if info1 == "mouse_click" and info4 == y then
- return true
- else
- return false
- end
- end
- -------------------------------
- homeMenu()
- startup()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement