Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for k,v in pairs(rs.getSides()) do
- if peripheral.getType(v)=='monitor' then
- side = v
- mon = peripheral.wrap(side)
- break
- end
- end
- for k,v in pairs(rs.getSides()) do
- if peripheral.getType(v)=='modem' then
- rednet.open(v)
- break
- end
- end
- monX, monY = mon.getSize()
- launch = false
- update = false
- x = 0
- y = 0
- z = 0
- local function coords()
- mon.setTextScale(1)
- mon.setTextColor(colors.yellow)
- mon.setBackgroundColor(colors.black)
- for i = 1, monX do
- mon.setCursorPos(i,1)
- mon.write(" ")
- end
- mon.setCursorPos(1,1)
- mon.write("X: "..x)
- mon.setCursorPos(monX/2-2,1)
- mon.write("Y: "..y)
- mon.setCursorPos(monX-8,1)
- mon.write("Z: "..z)
- dist = math.floor(math.sqrt( (x-locX)^2 + (y-locY)^2 + (z-locZ)^2 ))
- for i = 1, monX do
- mon.setCursorPos(i,monY/4)
- mon.write(" ")
- end
- for i = 1, monX do
- mon.setCursorPos(i,monY/4+1)
- mon.write(" ")
- end
- mon.setCursorPos((monX/2)-(string.len("Distance: "..dist)/2), monY/4+1) --fix
- mon.write("Distance: "..dist)
- end
- local function display()
- mon.setTextScale(1)
- mon.setTextColor(colors.yellow)
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setCursorPos(1,1)
- mon.write("X: "..x)
- mon.setCursorPos(monX/2-2,1)
- mon.write("Y: "..y)
- mon.setCursorPos(monX-8,1)
- mon.write("Z: "..z)
- --Dist = SQRT( (X2-X1)^2 + (Y2-Y1)^2 + (Z2-Z1)^2 )
- --where point A = (X1, Y1, Z1) , B = (X2, Y2, Z2 )
- dist = math.floor(math.sqrt( (x-locX)^2 + (y-locY)^2 + (z-locZ)^2 ))
- mon.setCursorPos(monX/2, monY/4)
- mon.write(dist)
- mon.setTextColor(colors.black)
- mon.setBackgroundColor(colors.yellow)
- for k = monY/2+1, monY do
- for i = 1, monX/5*2 do
- mon.setCursorPos(i, k)
- mon.write(" ")
- end
- end
- mon.setCursorPos(monX/10, monY/4*3+1)
- mon.write("Bookmarks")
- mon.setBackgroundColor(colors.red)
- for k = monY/2+1, monY do
- for i = monX/5*2+1, monX/5*3 do
- mon.setCursorPos(i, k)
- mon.write(" ")
- end
- end
- mon.setCursorPos(monX/2-2, monY/4*3+1)
- mon.setTextColor(colors.yellow)
- mon.write("Launch")
- mon.setBackgroundColor(colors.yellow)
- for k = monY/2+1, monY do
- for i = monX/5*3+1, monX do
- mon.setCursorPos(i,k)
- mon.write(" ")
- end
- end
- mon.setCursorPos(monX/5*4-7, monY/4*3+1)
- mon.setTextColor(colors.black)
- mon.write(" Set Coordinates")
- end
- if fs.exists("location") then
- file = fs.open("location","r")
- loc = file.readAll()
- file.close()
- loc = textutils.unserialize(loc)
- for key,value in pairs(loc) do
- if tostring(key) == "x" then
- locX = tonumber(value)
- elseif tostring(key) == "y" then
- locY = tonumber(value)
- elseif tostring(key) == "z" then
- locZ = tonumber(value)
- end
- end
- file = fs.open("icbmCom", "r")
- icbm = tonumber(file.readAll())
- file.close()
- else
- mon.clear()
- mon.setCursorPos(x/2 - 16, y/2)
- mon.write("Follow instructions on computer below")
- term.clear()
- term.setCursorPos(1,1)
- write("Enter the Launcher's X coordinate: ")
- locX = read()
- write("Enter the Launcher's Y coordinate: ")
- locY = read()
- write("Enter the Launcher's Z coordinate: ")
- locZ = read()
- location = {x = locX, y = locY, z = locZ}
- location = textutils.serialize(location)
- file = fs.open("location", "w")
- file.write(location)
- file.close()
- term.clear()
- term.setCursorPos(1,1)
- write("Enter the ID the ICBM launcher computer: ")
- icbm = tonumber(read())
- file = fs.open("icbmCom", "w")
- file.write(icbm)
- file.close()
- end
- display()
- while true do
- event, param1, param2, param3, param4, param5 = os.pullEvent()
- print(event)
- if event == "modem_message" and param3 == icbm then
- rednet.send(icbm, "ok1")
- id, x = rednet.receive()
- print("x: "..x)
- rednet.send(icbm, "ok2")
- id, y =rednet.receive()
- print("y: "..y)
- rednet.send(icbm, "ok3")
- id, z = rednet.receive()
- print("Z: "..z)
- if launch == true then
- rednet.send(icbm, "launch")
- launch = false
- elseif update == true then
- print("sending update!")
- rednet.send(icbm, "coords")
- rednet.receive()
- rednet.send(icbm, setX)
- rednet.receive()
- rednet.send(icbm, setY)
- rednet.receive()
- rednet.send(icbm, setZ)
- update = false
- else
- rednet.send(icbm, "dud")
- end
- coords()
- elseif event == "monitor_touch" and param2 > monX/5*3+1 and param3 > monY/2 then
- mon.setBackgroundColor(colors.black)
- mon.clear()
- coords()
- mon.setCursorPos(monX/2- 14, monY/2)
- mon.setTextColor(colors.red)
- mon.write("ENTER COORDINATES INTO COMPUTER")
- term.clear()
- term.setCursorPos(1,1)
- write("Enter X: ")
- setX = read()
- term.clear()
- term.setCursorPos(1,1)
- write("Enter Y: ")
- setY = read()
- term.clear()
- term.setCursorPos(1,1)
- write("Enter Z: ")
- setZ = read()
- term.clear()
- term.setCursorPos(1,1)
- print("Done!")
- os.sleep(1)
- term.clear()
- update = true
- display()
- elseif event == "monitor_touch" and param2 > monX/5*2+1 and param2 < monX/5*3 and param3 > monY/2 then
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setTextColor(colors.yellow)
- mon.setCursorPos(monX/2 -8, 1)
- mon.write("CONFIRM LAUNCH AT")
- leng = string.len("X: "..tostring(x).." Y: "..tostring(y).." Z: "..tostring(z))
- mon.setCursorPos((monX/2)-leng/2+1, 3)
- mon.write("X: "..x.." Y: "..y.." Z: "..z)
- mon.setTextColor(colors.black)
- mon.setBackgroundColor(colors.red)
- for k = monY/2+1, monY do
- for i = 1, monX/5*2 do
- mon.setCursorPos(i, k)
- mon.write(" ")
- end
- end
- mon.setCursorPos(monX/5-3, monY/4*3+1)
- mon.write("Launch")
- mon.setBackgroundColor(colors.green)
- for k = monY/2+1, monY do
- for i = monX/5*3+1, monX do
- mon.setCursorPos(i,k)
- mon.write(" ")
- end
- end
- mon.setCursorPos(monX/5*4-7, monY/4*3+1)
- mon.write("Abort Launch")
- event, param1, param2, param3 = os.pullEvent("monitor_touch")
- if param2 > monX/5*3 and param3 > monY/2 then
- launch = false
- print(launch)
- elseif param2 < monX/5*2 and param3 > monY/2 then
- launch = true
- end
- display()
- elseif event == "monitor_touch" and param2 < monX/5*2 and param3 > monY/2 then
- mon.setCursorPos(1,1)
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setBackgroundColor(colors.green)
- for i = 1,monY,2 do
- mon.setCursorPos(1,i)
- for k = 1,monX do
- mon.write(" ")
- end
- end
- mon.setBackgroundColor(colors.lime)
- for i = 2,monY,2 do
- mon.setCursorPos(1,i)
- for k = 1,monX do
- mon.write(" ")
- end
- end
- for i = 2, monY,2 do
- if fs.exists(tostring(i)) then
- file = fs.open(tostring(i),"r")
- data = file.readAll()
- file.close()
- data = textutils.unserialize(data)
- for key,value in pairs(data) do
- if tostring(key) == "name" then
- mon.setCursorPos(monX/2-string.len(tostring(value))/2, i)
- mon.write(tostring(value))
- end
- end
- else
- mon.setCursorPos(monX/2-5, i)
- mon.write("Set Bookmark")
- end
- end
- mon.setBackgroundColor(colors.red)
- for i = 1,monY do
- mon.setCursorPos(monX-3,i)
- mon.write(" X ")
- end
- mon.setBackgroundColor(colors.green)
- for i = 1, monY,2 do
- if fs.exists(tostring(i)) then
- file = fs.open(tostring(i),"r")
- data = file.readAll()
- file.close()
- data = textutils.unserialize(data)
- for key,value in pairs(data) do
- if tostring(key) == "name" then
- mon.setCursorPos(monX/2-string.len(tostring(value))/2, i)
- mon.write(tostring(value))
- end
- end
- else
- mon.setCursorPos(monX/2-5, i)
- mon.write("Set Bookmark")
- end
- end
- event, param1, param2, param3 = os.pullEvent("monitor_touch")
- if param2 > monX-3 then
- fs.delete(tostring(param3))
- elseif fs.exists(tostring(param3)) then
- file = fs.open(tostring(param3), "r")
- info = file.readAll()
- file.close()
- info = textutils.unserialize(info)
- for key, value in pairs(info) do
- if key == "x" then
- setX = value
- elseif key == "y" then
- setY = value
- elseif key == "z" then
- setZ = value
- end
- update = true
- end
- mon.clear()
- else
- mon.setBackgroundColor(colors.black)
- mon.setTextColor(colors.green)
- mon.clear()
- mon.setCursorPos(monX/2-15, monY/2)
- mon.write("Follow Prompts On The Computer Bellow")
- term.clear()
- term.setCursorPos(1,1)
- write("Set the name for bookmark: ")
- name = read()
- term.clear()
- term.setCursorPos(1,1)
- write("Set the X coordinate: ")
- wpX = read()term.clear()
- term.setCursorPos(1,1)
- write("Set the Y coordinate: ")
- wpY = read()term.clear()
- term.setCursorPos(1,1)
- write("Set the Z coordinate: ")
- wpZ = read()
- term.clear()
- term.setCursorPos(1,1)
- write("Done!")
- table = {name = name, x = wpX, y = wpY, z = wpZ}
- table = textutils.serialize(table)
- for i = 1, monY do
- if fs.exists(tostring(i)) == false then
- file = fs.open(tostring(i), "w")
- file.write(table)
- file.close()
- break
- end
- end
- end
- display()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement