gril002

OverWatch OS client

May 8th, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 38.43 KB | None | 0 0
  1. local unpack = unpack or table.unpack --#compatibility with 5.1 & 5.2
  2. os.pullEvent = function( sFilter ) --#override os.pullEvent
  3.   local result
  4.   repeat --#pull a raw event until the returned event is not terminate
  5.     result = {os.pullEventRaw( sFilter )}
  6.   until result[ 1 ] ~= "terminate"
  7.   return unpack( result )
  8. end
  9.  
  10.  
  11. -----------------------------------------------------------------------------------------------------
  12. debug = false
  13. xPos = nil
  14. yPos = nil
  15. autoUpdate = true
  16. -----------------------------------------------------------------------------------------------------
  17. function initialize()
  18.     getResolution()
  19.     fs.delete("saves/loginData")
  20.     exists = fs.exists("saves")
  21.     if exists == false then
  22.     print("Downloading files")
  23.     end
  24.     exists = fs.exists("saves/compass/data/loc1")
  25.     if exists == false then
  26.         file = fs.open("saves/compass/data/loc1", "w")
  27.         file.writeLine("Loc. 1")
  28.         file.writeLine(0)
  29.         file.writeLine(0)
  30.         file.close()
  31.         print("Created Loc1")
  32.     end
  33.     exists = fs.exists("saves/compass/data/loc2")
  34.     if exists == false then
  35.         file = fs.open("saves/compass/data/loc2", "w")     
  36.         file.writeLine("Loc. 2")
  37.         file.writeLine(0)
  38.         file.writeLine(0)
  39.         file.close()
  40.         print("Created Loc2")
  41.     end
  42.     exists = fs.exists("saves/compass/images")
  43.     if exists == false then
  44.         pb("W3WtTb7X", "saves/compass/images/East")
  45.         pb("XkCzw5Eu","saves/compass/images/North")
  46.         pb("cf87Bj7B","saves/compass/images/NorthEast")
  47.         pb("h5j04eup","saves/compass/images/NorthWest")
  48.         pb("vPRiFCxa","saves/compass/images/South")
  49.         pb("rPNaEPd6","saves/compass/images/SouthEast")
  50.         pb("tdV2C3Uf","saves/compass/images/SouthWest")
  51.         pb("90SN6r7V","saves/compass/images/West")
  52.         print("Downloaded Compass images")
  53.     end
  54.     exists = fs.exists("saves/door/key")
  55.     if exists == false then
  56.         pb("XJujhEvA", "saves/door/key")
  57.         print("Downloaded key image")
  58.     end
  59.     exists = fs.exists("saves/OS files/id")
  60.     if exists == false then
  61.         setUp = false
  62.         print("Device not set up")
  63.     else file = fs.open("saves/OS files/id", "r" ) -- read ID
  64.         rID = file.readLine()
  65.         file.close()
  66.         rID = tonumber(rID)
  67.     end
  68.     exists = fs.exists("saves/OS files/version")
  69.     if exists == false then
  70.         currentVersion = 0
  71.     else file = fs.open("saves/OS files/version", "r" )
  72.         currentVersion = file.readLine()
  73.         file.close()
  74.         currentVersion = tonumber(currentVersion)
  75.     end
  76.     pb("r1cCb1Nn", "saves/OS files/updater")
  77.     print("Updated updater")
  78.     updater()
  79.     checkSetUp()
  80.     wireless = peripheral.isPresent("back")
  81.     if wireless == false then
  82.         clear()
  83.         text = "The device"
  84.         line = 4
  85.         printCentered()
  86.         text = "must be wireless"
  87.         line = 3
  88.         printCentered()
  89.         text = "Press the Enter key"
  90.         line = 1
  91.         printCentered()
  92.         text = "to delete the program or"
  93.         line = 0
  94.         printCentered()
  95.         text = "wait 5 seconds for the"
  96.         line = -1
  97.         printCentered()
  98.         text = "device to turn off"
  99.         line = -2
  100.         printCentered()
  101.         resetTimer = os.startTimer(5)
  102.         local event, key = os.pullEvent()
  103.         while true do
  104.             local event, key = os.pullEvent()
  105.             if event == "key" then
  106.                 if key == 28 then
  107.                     fs.delete("startup")
  108.                     fs.delete("saves")
  109.                     os.reboot()
  110.                 end
  111.             elseif event == "timer" then
  112.                 if key == "resetTimer" then
  113.                     os.shutdown()
  114.                 end
  115.             end
  116.         end
  117.     end
  118.     rednet.open("back")
  119.     advanced = term.isColor()
  120.     if advanced == false then
  121.         clear()
  122.         text = "The device"
  123.         line = 4
  124.         printCentered()
  125.         text = "must be advanced"
  126.         line = 3
  127.         printCentered()
  128.         text = "Press the Enter key"
  129.         line = 1
  130.         printCentered()
  131.         text = "to delete the program or"
  132.         line = 0
  133.         printCentered()
  134.         text = "wait 5 seconds for the"
  135.         line = -1
  136.         printCentered()
  137.         text = "device to turn off"
  138.         line = -2
  139.         printCentered()
  140.         resetTimer2 = os.startTimer(5)
  141.         local event, key = os.pullEvent()
  142.         while true do
  143.             local event, key = os.pullEvent()
  144.             if event == "key" then
  145.                 if key == 28 then
  146.                     fs.delete("startup")
  147.                     fs.delete("saves")
  148.                     os.reboot()
  149.                 end
  150.             elseif event == "timer" then
  151.                 if key == resetTimer2 then
  152.                     os.shutdown()
  153.                 end
  154.             end
  155.         end
  156.     end
  157.     print("Getting protocols")
  158.     rednet.send(rID, "all", "kj24fg2hz5fhj4xc3gg2c45")
  159.     sID, uData = rednet.receive("n4xf4xbc5f7dx85hgcy<o56")
  160.     sID, SesKeys = rednet.receive("sfh546dhsg65423hkvb34c6")
  161.     sID, doorCtrl = rednet.receive("d567s25f,3j3n5fcd25f3y5")
  162.     sID, TDList = rednet.receive("qw7bv3klf3f34bc472zl32g")
  163.     sID, Mail = rednet.receive("p2k54v1f4h2v321c5hnn314")
  164.     sID, event = rednet.receive("d578tz232353jklc53kl655")
  165.     sID, vote = rednet.receive("cf5h83gxd25g3j5fg3j53c")
  166.     print("Received protocols")
  167. end
  168.  
  169. function updater()
  170.     if autoUpdate == true then
  171.         file = fs.open("saves/OS files/updater", "r" )
  172.         name = file.readLine()
  173.         newestVersion = file.readLine()
  174.         file.close()
  175.         newestVersion = tonumber(newestVersion)
  176.         if newestVersion > currentVersion then
  177.             print("There is a new update available")
  178.             print("Current version:", currentVersion, " Newest version", newestVersion)
  179.             sleep(1)
  180.             fs.delete("startup")
  181.             pb("jnZP4DN6", "startup")
  182.             file = fs.open("saves/OS files/version", "w" )
  183.             file.write(newestVersion)
  184.             file.close()
  185.             os.reboot()
  186.         else
  187.             print("The newest version is already installed")
  188.         end
  189.     end
  190. end
  191.  
  192. function checkSetUp()
  193.     if setUp == false then
  194.         clear()
  195.         line = 3
  196.         text = " Please insert the PoC"
  197.         printCentered()
  198.         line = 2
  199.         text = "into the server disk"
  200.         printCentered()
  201.         line = 1
  202.         text = "drive to connect it to"
  203.         printCentered()
  204.         line = 0
  205.         text = "the server"
  206.         printCentered()
  207.         sleep(5)
  208.         os.shutdown()
  209.     end
  210. end
  211.    
  212. function pb(paste, file)
  213.     response = http.get("http://pastebin.com/raw/"..paste)
  214.     sResponse = response.readAll()
  215.     response.close()
  216.     file = fs.open(file, "w" )
  217.     file.write(sResponse)
  218.     file.close()
  219. end
  220.  
  221. function getTime()
  222.     time = textutils.formatTime(os.time(), true)
  223. end
  224.  
  225. function clear()
  226.     term.clear()
  227.     term.setCursorPos(1,1) 
  228. end
  229.  
  230. function getResolution()
  231.     x,y = term.getSize()
  232. end
  233.  
  234. function centerX()
  235.     lenght = string.len(text)/2
  236.     a = x/2 - lenght
  237. end
  238.    
  239. function centerY()
  240.     b = y/2 - line
  241. end
  242.  
  243. function leftX()
  244.     d = line
  245.     lenght = string.len(text)/2
  246.     c = e - lenght
  247.     term.setCursorPos(c,d)
  248.     write(text)
  249. end
  250.  
  251. function rightX()
  252.     d = line
  253.     lenght = string.len(text)/2
  254.     c = f - lenght
  255.     term.setCursorPos(c,d)
  256.     write(text)
  257. end
  258.  
  259. function printCentered()
  260.     centerX()
  261.     centerY()
  262.     term.setCursorPos(a,b)
  263.     print(text)
  264. end
  265.  
  266. function lockedScreen()
  267.     clear()
  268.     getResolution()
  269.     text = "Please log in"
  270.     line = 2
  271.     printCentered()
  272.     text = "Username:         "
  273.     line = 1
  274.     printCentered()
  275.     text = "Password:         "
  276.     line = 0
  277.     printCentered()
  278.     line = 1
  279.     centerY()
  280.     a = x/2
  281.     term.setCursorPos(a, b)
  282.     username = read()
  283.     line = 0
  284.     centerY()
  285.     a = x/2
  286.     term.setCursorPos(a, b)
  287.     password = read("*")
  288.     checkCred()
  289. end
  290.  
  291. function checkCred()
  292.     rednet.send(rID, username, uData)
  293.     rednet.send(rID, password, uData)
  294.     sID,match = rednet.receive(uData)
  295.     if rID == sID then
  296.         if match == "Match" then
  297.             sID,clearance = rednet.receive(uData)
  298.             initialize() elseif
  299.             match == "No match" then
  300.             line = -1
  301.             text = "No match found"
  302.             printCentered()
  303.             sleep(1)
  304.             lockedScreen() else
  305.         end
  306.     end
  307. end
  308.    
  309. function getSessionKey()
  310.     rednet.send(rID, username, SesKeys)
  311.     id, sessionKey = rednet.receive(SesKeys)
  312. end
  313.        
  314. function commandLine()
  315.     term.setCursorPos(1,y)
  316.     term.clearLine()
  317.     term.setCursorPos(1,y-1)
  318.     term.clearLine()
  319.     write("Command:")
  320.     input = read()
  321.     if input == "exit" then
  322.         if clearance == "1.0" then
  323.             clear()
  324.             run = false
  325.             shell.exit()
  326.             return else
  327.             text = "Insufficient acces"
  328.             line = 1
  329.             printCentered()
  330.             sleep(1)
  331.             pressedButton = nil
  332.             interface()
  333.             return
  334.         end
  335.         elseif input == "debug" then
  336.             if debug == false then
  337.                 debug = true
  338.                 term.clearLine()
  339.                 term.setCursorPos(1,y)
  340.                 term.setTextColor(8)
  341.                 write("Debug mode enabled")
  342.                 term.setTextColor(1)
  343.                 sleep(1) elseif
  344.                 debug == true then
  345.                 debug = false
  346.                 term.clearLine()
  347.                 term.setCursorPos(1,y)
  348.                 term.setTextColor(8)
  349.                 write("Debug mode disabled")
  350.                 term.setTextColor(1)
  351.                 sleep(1)
  352.             end
  353.         elseif input == "cancel" then
  354.             pressedButton = nil
  355.             interface2()
  356.             return
  357.         else
  358.         write("invalid command")
  359.         sleep(1)
  360.         commandLine()
  361.     end
  362.     interface2()
  363. end
  364.  
  365. function interface()
  366.     clear()
  367.     setButtonIDs()
  368.     renderButtons()
  369.     nextButton()
  370.     timeTimer = os.startTimer(0)
  371.     while true do
  372.         local event, par1, X, Y = os.pullEvent()
  373.         if (event == "timer") and (par1 == timeTimer) then
  374.             printTime()
  375.             timeTimer = os.startTimer(0.1) elseif
  376.             (event == "mouse_click")then
  377.             xPos = X
  378.             yPos = Y
  379.             getClickPos()
  380.         end
  381.         if pressedButton == 1 then
  382.             button1() elseif
  383.             pressedButton == 2 then
  384.             button2() elseif
  385.             pressedButton == 3 then
  386.             button3() elseif
  387.             pressedButton == 4 then
  388.             button4() elseif
  389.             pressedButton == 5 then
  390.             button5() elseif
  391.             pressedButton == 6 then
  392.             button6() elseif
  393.             pressedButton == 8 then
  394.             interface2()
  395.         end
  396.         xPos = nil
  397.         yPos = nil
  398.     end
  399. end
  400.  
  401. function interface2()
  402.     clear()
  403.     returnButton()
  404.     button = 1
  405.     buttonID1 = "Command"
  406.     toggleButton()
  407.     button = 2
  408.     buttonID2 = "Help"
  409.     toggleButton()
  410.     setButtonIDs()
  411.     while true do
  412.         local event, par1, X, Y = os.pullEvent()
  413.         if (event == "timer") and (par1 == timeTimer) then
  414.             printTime()
  415.             timeTimer = os.startTimer(0.1) elseif
  416.             (event == "mouse_click")then
  417.             xPos = X
  418.             yPos = Y
  419.             getClickPos()
  420.         end
  421.         if pressedButton == 1 then
  422.             commandLine() elseif
  423.             pressedButton == 2 then
  424.             help() elseif
  425.             pressedButton == 7 then
  426.             interface()
  427.         end
  428.     end
  429.     xPos = nil
  430.     yPos = nil
  431. end
  432.  
  433. function renderButtons()
  434.     button = 1
  435.     state = "on"
  436.     while true do
  437.         if button < 7 then
  438.             toggleButton()
  439.             button = button + 1 else
  440.             break
  441.         end
  442.     end
  443. end
  444.  
  445. function toggleButton()
  446.     if pocket then
  447.         e = 8
  448.         f = 20
  449.         if button == 1 then
  450.             if state == "on" then
  451.                 paintutils.drawFilledBox(3, 2, 12, 6, 8192) elseif
  452.                 state == "off" then
  453.                 paintutils.drawFilledBox(3, 2, 12, 6, 16384)
  454.             end
  455.             text = buttonID1
  456.             line = 4
  457.             leftX()
  458.             elseif button == 2 then
  459.                 if state == "on" then
  460.                     paintutils.drawFilledBox(15, 2, 24, 6, 8192) elseif
  461.                     state == "off" then
  462.                     paintutils.drawFilledBox(15, 2, 24, 6, 16384)
  463.                 end
  464.             text = buttonID2
  465.             line = 4
  466.             rightX()
  467.             elseif button == 3 then
  468.             if state == "on" then
  469.                 paintutils.drawFilledBox(3, 8, 12, 12, 8192) elseif
  470.                 state == "off" then
  471.                 paintutils.drawFilledBox(3, 8, 12, 12, 16384)
  472.             end
  473.             text = buttonID3
  474.             line = 10
  475.             leftX()
  476.             elseif button == 4 then
  477.             if state == "on" then
  478.                 paintutils.drawFilledBox(15, 8, 24, 12, 8192) elseif
  479.                 state == "off" then
  480.                 paintutils.drawFilledBox(15, 8, 24, 12, 16384)
  481.             end
  482.             text = buttonID4
  483.             line = 10
  484.             rightX()
  485.             elseif button == 5 then
  486.             if state == "on" then
  487.                 paintutils.drawFilledBox(3, 14, 12, 18, 8192) elseif
  488.                 state == "off" then
  489.                 paintutils.drawFilledBox(3, 14, 12, 18, 16384)
  490.             end
  491.             text = buttonID5
  492.             line = 16
  493.             leftX()
  494.             elseif button == 6 then
  495.             if state == "on" then
  496.                 paintutils.drawFilledBox(15, 14, 24, 18, 8192) elseif
  497.                 state == "off" then
  498.                 paintutils.drawFilledBox(15, 14, 24, 18, 16384)
  499.             end
  500.             text = buttonID6
  501.             line = 16
  502.             rightX()
  503.         end
  504.         term.setBackgroundColor(32768)
  505.     end
  506. end
  507.  
  508. function returnButton()
  509.     term.setCursorPos(1,y)
  510.     paintutils.drawFilledBox(1, y, 6, y, 8192)
  511.     term.setCursorPos(2,y)
  512.     write("Back")
  513.     term.setBackgroundColor(32768)
  514. end
  515.  
  516. function nextButton()
  517.     term.setCursorPos(20,y)
  518.     paintutils.drawFilledBox(20, y, x, y, 8192)
  519.     term.setCursorPos(22,y)
  520.     write("Next")
  521.     term.setBackgroundColor(32768)
  522. end
  523.  
  524. function getClickPos()
  525.     getResolution()
  526.     term.setCursorPos(1,y)
  527.     if (xPos == nil) or (yPos == nil) then
  528.         event, button, xPos, yPos = os.pullEvent("mouse_click")
  529.     end
  530.     if (xPos > 2) and (xPos < 13) and (yPos > 1) and (yPos < 7) then
  531.         pressedButton = 1 elseif
  532.         (xPos > 14) and (xPos < 25) and (yPos > 1) and (yPos < 7) then
  533.         pressedButton = 2 elseif
  534.         (xPos > 2) and (xPos < 13) and (yPos > 7) and (yPos < 13) then
  535.         pressedButton = 3 elseif
  536.         (xPos > 14) and (xPos < 25) and (yPos > 7) and (yPos < 13) then
  537.         pressedButton = 4 elseif
  538.         (xPos > 2) and (xPos < 13) and (yPos > 13) and (yPos < 19) then
  539.         pressedButton = 5 elseif
  540.         (xPos > 14) and (xPos < 25) and (yPos > 13) and (yPos < 19) then
  541.         pressedButton = 6 elseif
  542.         (xPos > 0) and (xPos < 7) and (yPos == y) then
  543.         pressedButton = 7 elseif
  544.         (xPos > 20) and (xPos < 27) and (yPos == y) then
  545.         pressedButton = 8
  546.     end
  547.     if debug == true then
  548.         term.setCursorPos(1,y)
  549.         term.setTextColor(8)
  550.         write("X:")
  551.         write(xPos)
  552.         write(" Y:")
  553.         write(yPos)
  554.         term.setTextColor(1)
  555.         sleep(1)
  556.         term.clearLine()
  557.     end
  558.     linePos = yPos
  559.     xPos = nil
  560.     yPos = nil
  561. end
  562.  
  563. function setButtonIDs()
  564. buttonID1 = "Mail"
  565. buttonID2 = " To do"
  566. buttonID3 = "Door"
  567. buttonID4 = " Compass"
  568. buttonID5 = " Voting"
  569. buttonID6 = " Events"
  570. end
  571.  
  572. function button1()
  573.     if debug == true then
  574.     term.setCursorPos(1,y)
  575.     term.setTextColor(8)
  576.     write("button 1")
  577.     term.setTextColor(1)
  578.     sleep(1)
  579.     term.clearLine()
  580.     end
  581.     mailFunc()
  582.     pressedButton = nil
  583.     xPos = nil
  584.     yPos = nil
  585. end
  586.  
  587. function button2()
  588.     if debug == true then
  589.     term.setCursorPos(1,y)
  590.     term.setTextColor(8)
  591.     write("buttton 2")
  592.     term.setTextColor(1)
  593.     sleep(1)
  594.     term.clearLine()
  595.     end
  596.     toDo()
  597.     pressedButton = nil
  598.     xPos = nil
  599.     yPos = nil
  600. end
  601.  
  602. function button3()
  603.     if debug == true then
  604.         term.setTextColor(8)
  605.         term.setCursorPos(1,y)
  606.         write("buttton 3")
  607.         term.setTextColor(1)
  608.         sleep(1)
  609.         term.clearLine()
  610.     end
  611.     door()
  612.     pressedButton = nil
  613.     xPos = nil
  614.     yPos = nil
  615. end
  616.  
  617. function button4()
  618.     if debug == true then
  619.     term.setCursorPos(1,y)
  620.     term.setTextColor(8)
  621.     write("buttton 4")
  622.     term.setTextColor(1)
  623.     sleep(1)
  624.     term.clearLine()
  625.     end
  626.     compass()
  627.     pressedButton = nil
  628.     xPos = nil
  629.     yPos = nil
  630. end
  631.  
  632. function button5()
  633.     if debug == true then
  634.     term.setCursorPos(1,y)
  635.     term.setTextColor(8)
  636.     write("buttton 5")
  637.     term.setTextColor(1)
  638.     sleep(1)
  639.     term.clearLine()
  640.     end
  641.     voting()
  642.     pressedButton = nil
  643.     xPos = nil
  644.     yPos = nil
  645. end
  646.  
  647. function button6()
  648.     if debug == true then
  649.     term.setCursorPos(1,y)
  650.     term.setTextColor(8)
  651.     write("buttton 6")
  652.     term.setTextColor(1)
  653.     sleep(1)
  654.     term.clearLine()
  655.     end
  656.     events()
  657.     pressedButton = nil
  658.     xPos = nil
  659.     yPos = nil
  660. end
  661.  
  662. function printTime()
  663.     getTime()
  664.     term.setCursorPos(1,1)
  665.     term.clearLine()
  666.     write(time)
  667. end
  668.  
  669. function door()
  670.     clear()
  671.     paintutils.drawImage(paintutils.loadImage("saves/door/key"),x/2-8,2)
  672.     term.setBackgroundColor(32768)
  673.     line = 2
  674.     text = "You can now open"
  675.     printCentered()
  676.     text = "doors for 3 seconds"
  677.     line = 1
  678.     printCentered()
  679.     text = "Insert the PDA"
  680.     line = -1
  681.     printCentered()
  682.     text = "into a door disk drive"
  683.     line = -2
  684.     printCentered()
  685.     getSessionKey()
  686.     file = fs.open("saves/door/loginData", "w")
  687.     file.writeLine(sessionKey)
  688.     file.close()
  689.     sleep(3)
  690.     exists = fs.exists("saves/door/loginData")
  691.     if exists == true then
  692.         fs.delete("saves/door/loginData")
  693.     end
  694.     pressedButton = nil
  695.     interface()
  696.     return
  697. end
  698.  
  699. function compass()
  700.     file = fs.open("saves/compass/data/loc1","r")
  701.     location1 = file.readLine()
  702.     l1X = file.readLine()
  703.     l1Z = file.readLine()
  704.     file.close()
  705.     file = fs.open("saves/compass/data/loc2","r")
  706.     location2 = file.readLine()
  707.     l2X = file.readLine()
  708.     l2Z = file.readLine()
  709.     file.close()
  710.     clear()
  711.     returnButton()
  712.     text = " Where would"
  713.     line = 6
  714.     printCentered()
  715.     text = " you like to go?"
  716.     line = 5
  717.     printCentered()
  718.     button = 3
  719.     buttonID3 = location1
  720.     toggleButton()
  721.     button = 4
  722.     buttonID4 = location2
  723.     toggleButton()
  724.     button = 5
  725.     buttonID5 = "Custom"
  726.     toggleButton()
  727.     button = 6
  728.     buttonID6 = "Change"
  729.     toggleButton()
  730.     setButtonIDs()
  731.     getLocation()
  732.     while true do
  733.         getClickPos()
  734.         if pressedButton == 3 then
  735.             if l1X == "0.0" then
  736.                 clear()
  737.                 text = " Before first use you"
  738.                 line = 6
  739.                 printCentered()
  740.                 line = 5
  741.                 text = " have to set the location"
  742.                 printCentered()
  743.                 sleep(1)
  744.                 change1()
  745.             end
  746.             returnButton()
  747.             comTimer = os.startTimer(0) --compass timer
  748.             while true do
  749.                 local event, par1, X, Y = os.pullEvent()
  750.                 if (event == "timer") and (par1 == comTimer) then
  751.                     getLocation()
  752.                     gX = l1X - cX -- go to = location 1 X - current X
  753.                     gZ = l1Z - cZ
  754.                     refreshCompass()
  755.                     comTimer = os.startTimer(1) elseif
  756.                     (event == "mouse_click") and (X > 0) and (X < 7) and (Y == y) then
  757.                     pressedButton = nil
  758.                     compass()
  759.                     return
  760.                 end
  761.             end
  762.         elseif pressedButton == 4 then
  763.             if l2X == "0.0" then
  764.                 clear()
  765.                 text = "Before first use you"
  766.                 line = 6
  767.                 printCentered()
  768.                 text = "have to set the location"
  769.                 line = 5
  770.                 printCentered()
  771.                 sleep(1)
  772.                 change2()
  773.             end
  774.             comTimer = os.startTimer(0)
  775.             while true do
  776.                 local event, par1, X, Y = os.pullEvent()
  777.                 if (event == "timer") and (par1 == comTimer) then
  778.                     getLocation()
  779.                     gX = l2X - cX -- go to
  780.                     gZ = l2Z - cZ
  781.                     refreshCompass()
  782.                     comTimer = os.startTimer(1) elseif
  783.                     (event == "mouse_click") and (X > 0) and (X < 7) and (Y == y) then
  784.                     pressedButton = nil
  785.                     compass()
  786.                     return
  787.                 end
  788.             end
  789.         elseif pressedButton == 5 then
  790.             clear()
  791.             text = "Type in the"
  792.             line = 5
  793.             printCentered()
  794.             text = "coordinates"
  795.             line = 4
  796.             printCentered()
  797.             text = "X coord.:         "
  798.             line = 2
  799.             printCentered()
  800.             text = "Z coord.:         "
  801.             line = 1
  802.             printCentered()
  803.             line = 2
  804.             centerY()
  805.             a = x/2
  806.             term.setCursorPos(a, b)
  807.             lcX = read()
  808.             numCheck = tonumber(lcX)
  809.             if numCheck == nil then
  810.                 text = "X can only"
  811.                 line = -3
  812.                 printCentered()
  813.                 text = "be a number"
  814.                 line = -4
  815.                 printCentered()
  816.                 sleep(1)
  817.                 change1()
  818.             end
  819.             line = 1
  820.             centerY()
  821.             a = x/2
  822.             term.setCursorPos(a, b)
  823.             lcZ = read()
  824.             numCheck = tonumber(lcZ)
  825.             if numCheck == nil then
  826.                 text = "Z can only"
  827.                 line = -3
  828.                 printCentered()
  829.                 text = "be a number"
  830.                 line = -4
  831.                 printCentered()
  832.                 sleep(1)
  833.                 change1()
  834.             end
  835.             comTimer = os.startTimer(0)
  836.             while true do
  837.                 local event, par1, X, Y = os.pullEvent()
  838.                 if (event == "timer") and (par1 == comTimer) then
  839.                     getLocation()
  840.                     gX = lcX - cX -- go to
  841.                     gZ = lcZ - cZ
  842.                     refreshCompass()
  843.                     comTimer = os.startTimer(1) elseif
  844.                     (event == "mouse_click") and (X > 0) and (X < 7) and (Y == y) then
  845.                     pressedButton = nil
  846.                     compass()
  847.                     return
  848.                 end
  849.             end
  850.         elseif pressedButton == 6 then
  851.             clear()
  852.             returnButton()
  853.             text = " Which location would"
  854.             line = 6
  855.             printCentered()
  856.             text = " you like to change?"
  857.             line = 5
  858.             printCentered()
  859.             button = 3
  860.             buttonID3 = location1
  861.             toggleButton()
  862.             button = 4
  863.             buttonID4 = location2
  864.             toggleButton()
  865.             toggleButton()
  866.             setButtonIDs()
  867.             getClickPos()
  868.             if pressedButton == 3 then
  869.                 change1() elseif
  870.                 pressedButton == 4 then
  871.                 change2() elseif
  872.                 pressedButton == 7 then
  873.                 pressedButton = nil
  874.                 compass()
  875.                 return
  876.             end
  877.         elseif pressedButton == 7 then
  878.             pressedButton = nil
  879.             interface()
  880.             return
  881.         end
  882.     end
  883. end
  884.  
  885. function change1()
  886.     clear()
  887.     text = "Fill in"
  888.     line = 6
  889.     printCentered()
  890.     text = "the next data"
  891.     line = 5
  892.     printCentered()
  893.     text = "Name:     "
  894.     line = 3
  895.     printCentered()
  896.     text = "X coord.:         "
  897.     line = 2
  898.     printCentered()
  899.     text = "Z coord.:         "
  900.     line = 1
  901.     printCentered()
  902.     line = 3
  903.     centerY()
  904.     a = x/2
  905.     term.setCursorPos(a, b)
  906.     newName = read()
  907.     lenght = string.len(newName)
  908.     if (lenght>7) then
  909.         text = "The name can only"
  910.         line = -3
  911.         printCentered()
  912.         text = "be 7 letters long"
  913.         line = -4
  914.         printCentered()
  915.         sleep(1)
  916.         change1()
  917.     end
  918.     line = 2
  919.     centerY()
  920.     a = x/2
  921.     term.setCursorPos(a, b)
  922.     newX = read()
  923.     numCheck = tonumber(newX)
  924.     if numCheck == nil then
  925.         text = "X can only"
  926.         line = -3
  927.         printCentered()
  928.         text = "be a number"
  929.         line = -4
  930.         printCentered()
  931.         sleep(1)
  932.         change1()
  933.     end
  934.     line = 1
  935.     centerY()
  936.     a = x/2
  937.     term.setCursorPos(a, b)
  938.     newZ = read()
  939.     numCheck = tonumber(newZ)
  940.     if numCheck == nil then
  941.         text = "Z can only"
  942.         line = -3
  943.         printCentered()
  944.         text = "be a number"
  945.         line = -4
  946.         printCentered()
  947.         sleep(1)
  948.         change1()
  949.     end
  950.     file = fs.open("saves/compass/data/loc1", "w")
  951.     file.writeLine(newName)
  952.     file.writeLine(newX)
  953.     file.writeLine(newZ)
  954.     file.close()
  955.     compass()
  956. end
  957.  
  958. function change2()
  959.     clear()
  960.     text = "Fill in"
  961.     line = 6
  962.     printCentered()
  963.     text = "the next data"
  964.     line = 5
  965.     printCentered()
  966.     text = "Name:     "
  967.     line = 3
  968.     printCentered()
  969.     text = "X coord.:         "
  970.     line = 2
  971.     printCentered()
  972.     text = "Z coord.:         "
  973.     line = 1
  974.     printCentered()
  975.     line = 3
  976.     centerY()
  977.     a = x/2
  978.     term.setCursorPos(a, b)
  979.     newName = read()
  980.     lenght = string.len(newName)
  981.     if (lenght>7) then
  982.         text = "The name can only"
  983.         line = -3
  984.         printCentered()
  985.         text = "be 7 letters long"
  986.         line = -4
  987.         printCentered()
  988.         sleep(1)
  989.         change1()
  990.     end
  991.     line = 2
  992.     centerY()
  993.     a = x/2
  994.     term.setCursorPos(a, b)
  995.     newX = read()
  996.     numCheck = tonumber(newX)
  997.     if numCheck == nil then
  998.         text = "X can only"
  999.         line = -3
  1000.         printCentered()
  1001.         text = "be a number"
  1002.         line = -4
  1003.         printCentered()
  1004.         sleep(1)
  1005.         change1()
  1006.     end
  1007.     line = 1
  1008.     centerY()
  1009.     a = x/2
  1010.     term.setCursorPos(a, b)
  1011.     newZ = read()
  1012.     if numCheck == nil then
  1013.         text = "Z can only"
  1014.         line = -3
  1015.         printCentered()
  1016.         text = "be a number"
  1017.         line = -4
  1018.         printCentered()
  1019.         sleep(1)
  1020.         change1()
  1021.     end
  1022.     file = fs.open("saves/compass/data/loc2", "w")
  1023.     file.writeLine(newName)
  1024.     file.writeLine(newX)
  1025.     file.writeLine(newZ)
  1026.     file.close()
  1027.     compass()
  1028. end
  1029.  
  1030. function getLocation()
  1031. cX, cY, cZ = gps.locate() --current
  1032.     if  cX == nil then
  1033.         print("Failed to get location!")
  1034.         sleep(2)
  1035.         pressedButton = nil
  1036.         return
  1037.         else
  1038.         cX = math.round(cX)
  1039.         cY = math.round(cY)
  1040.         cZ = math.round(cZ)
  1041.     end
  1042. end
  1043.  
  1044. function refreshCompass()
  1045.     getDirections()
  1046.     number = gX
  1047.     getAbsolute()
  1048.     goX = Anumber
  1049.     number = gZ
  1050.     getAbsolute()
  1051.     goZ = Anumber
  1052.     clear()
  1053.     drawCompass()
  1054.     line = -7
  1055.     centerY()
  1056.     term.setCursorPos(1, b)
  1057.     if debug == true then
  1058.         term.setTextColor(8)
  1059.         print(cX, cY, cZ, gX, gZ)
  1060.         term.setTextColor(1)
  1061.     end
  1062.     if (goZ == 0) and (dZ == nil) then
  1063.         clear()
  1064.         text = "You have arrived"
  1065.         line = 1
  1066.         printCentered()
  1067.         text = "to your destination"
  1068.         line = 0
  1069.         printCentered() elseif
  1070.         dX == nil then
  1071.         print("Go", goZ, "blocks", dZ) elseif
  1072.         dZ == nil then
  1073.         print("Go", goX, "blocks", dX) elseif
  1074.         (goZ == 0) and (dZ == nil) then
  1075.         text = "You have arrived"
  1076.         line = 1
  1077.         printCentered()
  1078.         text = "to your destination"
  1079.         line = 0
  1080.         printCentered() else
  1081.         print("Go", goZ, "blocks", dZ, "and", goX, "blocks", dX)
  1082.     end
  1083.     returnButton()
  1084. end
  1085.  
  1086. function getDirections()
  1087.     if gX > 0 then
  1088.         dX = "East" else -- direction
  1089.         dX = "West"
  1090.     end
  1091.     if gX == 0 then
  1092.         dX = nil
  1093.     end
  1094.     if gZ > 0 then
  1095.         dZ = "South" else
  1096.         dZ = "North"
  1097.     end
  1098.     if gZ == 0 then
  1099.         dZ = nil
  1100.     end
  1101. end
  1102. function getAbsolute()
  1103.     if number < 0 then
  1104.         Anumber = -1*number else
  1105.         Anumber = number
  1106.     end
  1107. end
  1108.  
  1109. function drawCompass()
  1110.     if  (dZ == "North") and (dX == nil) then
  1111.         image = paintutils.loadImage("Saves/compass/images/North")
  1112.         a = x/2 - 8
  1113.         paintutils.drawImage(image, a,2) elseif
  1114.         (dZ == "South") and (dX == nil) then
  1115.         image = paintutils.loadImage("Saves/compass/images/South")
  1116.         a = x/2 - 8
  1117.         paintutils.drawImage(image, a,2) elseif
  1118.         (dZ == nil) and (dX == "West") then
  1119.         image = paintutils.loadImage("Saves/compass/images/West")
  1120.         a = x/2 - 8
  1121.         paintutils.drawImage(image, a,2) elseif
  1122.         (dZ == nil) and (dX == "East") then
  1123.         image = paintutils.loadImage("Saves/compass/images/East")
  1124.         a = x/2 - 8
  1125.         paintutils.drawImage(image, a,2) elseif
  1126.         (dZ == "North") and (dX == "West") then
  1127.         image = paintutils.loadImage("Saves/compass/images/NorthWest")
  1128.         a = x/2 - 8
  1129.         paintutils.drawImage(image, a,2) elseif
  1130.         (dZ == "North") and (dX == "East") then
  1131.         image = paintutils.loadImage("Saves/compass/images/NorthEast")
  1132.         a = x/2 - 8
  1133.         paintutils.drawImage(image, a,2) elseif
  1134.         (dZ == "South") and (dX == "West")then
  1135.         image = paintutils.loadImage("Saves/compass/images/SouthWest")
  1136.         a = x/2 - 8
  1137.         paintutils.drawImage(image, a,2) elseif
  1138.         (dZ == "South") and (dX == "East")then
  1139.         image = paintutils.loadImage("Saves/compass/images/SouthEast")
  1140.         a = x/2 - 8
  1141.         paintutils.drawImage(image, a,2)
  1142.         term.setBackgroundColor(32768)
  1143.     end
  1144.     term.setBackgroundColor(32768)
  1145. end
  1146.  
  1147. function math.round(n)
  1148.         for i = 1, #tostring(n) do
  1149.                 if string.sub(tostring(n), i, i) == "." then
  1150.                         return tonumber(string.sub(tostring(n), i+1, i+1)) >= 5 and math.ceil(n) or math.floor(n)
  1151.                 end
  1152.         end
  1153.         return n
  1154. end
  1155.  
  1156. function mailFunc()
  1157.     clear()
  1158.     print("Inbox")
  1159.     print("New")
  1160.     num = 0
  1161.     rednet.send(rID, "sendMail", Mail)
  1162.     rednet.send(rID, username, Mail)
  1163.     rednet.send(rID, num, Mail)
  1164.     mail = {[1] = {}, [2] = {}, [3] = {}, [4] = {}, [5] = {}, [6] = {}, [7] = {}, [8] = {}}
  1165.     PosY = 3
  1166.     for i = 1,8 do
  1167.         sID, exists = rednet.receive(Mail)
  1168.         if exists == "exists" then
  1169.             sID, mail[i][1] = rednet.receive(Mail) --sender
  1170.             sID, mail[i][2] = rednet.receive(Mail) --day
  1171.             sID, mail[i][3] = rednet.receive(Mail) --time
  1172.             sID, mail[i][4] = rednet.receive(Mail) --title
  1173.             sID, mail[i][5] = rednet.receive(Mail) --message
  1174.             write( "From: "..mail[i][1])
  1175.             daySent = math.round(mail[i][2])
  1176.             daySent = tostring(daySent)
  1177.             currentDay = math.round(os.day())
  1178.             currentDay = tostring(currentDay)
  1179.             if daySent == currentDay then
  1180.                 term.setCursorPos(x-#mail[i][3]+1, PosY)
  1181.                 write(mail[i][3])
  1182.             elseif daySent ~= currentDay then
  1183.                 term.setCursorPos(x-#daySent-3, PosY)
  1184.                 write("Day "..daySent)
  1185.             end
  1186.             print( "Title:", mail[i][4])
  1187.         end
  1188.         PosY = PosY + 2
  1189.     end
  1190.     returnButton()
  1191.     nextButton()
  1192.     openMail = nil
  1193.     while true do
  1194.         getClickPos()
  1195.         returnButton()
  1196.         nextButton()
  1197.         openMail = nil
  1198.         if linePos == 2 then
  1199.             sendMail()
  1200.         elseif (linePos == 3) or (linePos == 4) then
  1201.             openMail = 1
  1202.         elseif (linePos == 5) or (linePos == 6) then
  1203.             openMail = 2
  1204.         elseif (linePos == 7) or (linePos == 8) then
  1205.             openMail = 3
  1206.         elseif (linePos == 9) or (linePos == 10) then
  1207.             openMail = 4
  1208.         elseif (linePos == 11) or (linePos == 12) then
  1209.             openMail = 5
  1210.         elseif (linePos == 13) or (linePos == 14) then
  1211.             openMail = 6
  1212.         elseif (linePos == 15) or (linePos == 16) then
  1213.             openMail = 7
  1214.         elseif (linePos == 17) or (linePos == 18) then
  1215.             openMail = 8
  1216.         elseif pressedButton == 7 then
  1217.             pressedButton = nil
  1218.             interface()
  1219.             return
  1220.         elseif pressedButton == 8 then
  1221.             num = 9
  1222.             mailFunc()
  1223.         else openMail = nil
  1224.         end
  1225.         sleep(0.1)
  1226.         OpenMail()
  1227.     end
  1228. end
  1229.  
  1230. function OpenMail()
  1231.     if openMail ~= nil then
  1232.         if mail[openMail][1] ~= nil then
  1233.             clear()
  1234.             daySent = math.round(mail[openMail][2])
  1235.             daySent = tostring(daySent)
  1236.             print("From:", mail[openMail][1])
  1237.             print("Sent on day", daySent, "at", mail[openMail][3])
  1238.             print("Title: ", mail[openMail][4])
  1239.             print(mail[openMail][5])
  1240.             returnButton()
  1241.             while true do
  1242.                 getClickPos()
  1243.                 if pressedButton == 7 then
  1244.                     pressedButton = nil
  1245.                     linePos = nil
  1246.                     openMail = nil
  1247.                     mailFunc()
  1248.                     return
  1249.                 end
  1250.             end
  1251.         end
  1252.     end
  1253. end
  1254.  
  1255. function sendMail()
  1256.     clear()
  1257.     write("receiver: ")
  1258.     receiver = read()
  1259.     write("Title: ")
  1260.     name = read()
  1261.     write("message: ")
  1262.     message = read()
  1263.     sender = username
  1264.     rednet.send(rID, "createMail", Mail)
  1265.     rednet.send(rID, username, Mail)
  1266.     rednet.send(rID, sender, Mail)
  1267.     rednet.send(rID, receiver, Mail)
  1268.     rednet.send(rID, os.day(), Mail)
  1269.     getTime()
  1270.     rednet.send(rID, time, Mail)
  1271.     rednet.send(rID, name, Mail)
  1272.     rednet.send(rID, message, Mail)
  1273.     sID, mailMatch = rednet.receive(Mail)
  1274.     clear()
  1275.     if mailMatch == "sent" then
  1276.         printCentered()
  1277.         text = "Mail sent"
  1278.         line = 0
  1279.         printCentered()
  1280.     elseif mailMatch == "noMatch" then
  1281.         text = "There is no such user "
  1282.         line = 0
  1283.         printCentered()
  1284.     end
  1285.     sleep(1)
  1286.     mailFunc()
  1287.     return
  1288. end
  1289.  
  1290. function toDo()
  1291.     clear()
  1292.     getList()
  1293.     printList()
  1294.     returnButton()
  1295.     getClickPos()
  1296.     while true do
  1297.         returnButton()
  1298.         if linePos == 1 then
  1299.             listLine = 1
  1300.             elseif linePos == 2 then
  1301.             listLine = 2
  1302.             elseif linePos == 3 then
  1303.             listLine = 3
  1304.             elseif linePos == 4 then
  1305.             listLine = 4
  1306.             elseif linePos == 5 then
  1307.             listLine = 5
  1308.             elseif linePos == 6 then
  1309.             listLine = 6
  1310.             elseif linePos == 7 then
  1311.             listLine = 7
  1312.             elseif linePos == 8 then
  1313.             listLine = 8
  1314.             elseif linePos == 9 then
  1315.             listLine = 9
  1316.             elseif linePos == 10 then
  1317.             listLine = 10
  1318.             elseif pressedButton == 7 then
  1319.             listLine = nil
  1320.             pressedButton = nil
  1321.             interface()
  1322.             return
  1323.             else toDo()
  1324.         end
  1325.         printList()
  1326.         returnButton()
  1327.         button = 5
  1328.         buttonID5 = "Edit"
  1329.         toggleButton()
  1330.         button = 6
  1331.         buttonID6 = "Status"
  1332.         toggleButton()
  1333.         getClickPos()
  1334.         if pressedButton == 5 then
  1335.             editNum()
  1336.         elseif pressedButton == 6 then
  1337.             button = 5
  1338.             buttonID5 = "Complete"
  1339.             toggleButton()
  1340.             button = 6
  1341.             buttonID6 = "Normal"
  1342.             toggleButton()
  1343.             returnButton()
  1344.             getClickPos()
  1345.             if pressedButton == 5 then
  1346.                 status = "complete"
  1347.                 changeStatus()
  1348.             elseif pressedButton == 6 then
  1349.                 status = "normal"
  1350.                 changeStatus()
  1351.             elseif pressedButton == 7 then
  1352.             pressedButton = nil
  1353.             interface()
  1354.             return
  1355.             end
  1356.         elseif pressedButton == 7 then
  1357.             pressedButton = nil
  1358.             interface()
  1359.             return
  1360.         end
  1361.     end
  1362.     pressedButton = nil
  1363.     interface()
  1364.     return
  1365. end
  1366.  
  1367.  
  1368. function getList()
  1369.     rednet.send(rID, username, TDList)
  1370.     rednet.send(rID, "send", TDList)
  1371.     sID,Num1 = rednet.receive(TDList)
  1372.     sID,status1 = rednet.receive(TDList)
  1373.     sID,Num2 = rednet.receive(TDList)
  1374.     sID,status2 = rednet.receive(TDList)
  1375.     sID,Num3 = rednet.receive(TDList)
  1376.     sID,status3 = rednet.receive(TDList)
  1377.     sID,Num4 = rednet.receive(TDList)
  1378.     sID,status4 = rednet.receive(TDList)
  1379.     sID,Num5 = rednet.receive(TDList)
  1380.     sID,status5 = rednet.receive(TDList)
  1381.     sID,Num6 = rednet.receive(TDList)
  1382.     sID,status6 = rednet.receive(TDList)
  1383.     sID,Num7 = rednet.receive(TDList)
  1384.     sID,status7 = rednet.receive(TDList)
  1385.     sID,Num8 = rednet.receive(TDList)
  1386.     sID,status8 = rednet.receive(TDList)
  1387.     sID,Num9 = rednet.receive(TDList)
  1388.     sID,status9 = rednet.receive(TDList)
  1389.     sID,Num10 = rednet.receive(TDList)
  1390.     sID,status10 = rednet.receive(TDList)
  1391. end
  1392.  
  1393. function printList()
  1394.     clear()
  1395.     if listLine == 1 then
  1396.         paintutils.drawFilledBox(1,1,x,1,256)
  1397.         term.setCursorPos(1,1)
  1398.     end
  1399.     if status1 == "complete" then
  1400.         term.setTextColor(colors.lime)
  1401.         print("01. " ..Num1)
  1402.         term.setTextColor(colors.white) elseif
  1403.         status1 == "cancel" then
  1404.         term.setTextColor(colors.red)
  1405.         print("01. " ..Num1)
  1406.         term.setTextColor(colors.white) else
  1407.         term.setTextColor(colors.white)
  1408.         print("01. " ..Num1)
  1409.     end
  1410.     term.setBackgroundColor(32768)
  1411.     if listLine == 2 then
  1412.         paintutils.drawFilledBox(1,2,x,2,256)
  1413.         term.setCursorPos(1,2)
  1414.     end
  1415.     if status2 == "complete" then
  1416.         term.setTextColor(colors.lime)
  1417.         print("02. " ..Num2)
  1418.         term.setTextColor(colors.white) elseif
  1419.         status2 == "cancel" then
  1420.         term.setTextColor(colors.red)
  1421.         print("02. " ..Num2)
  1422.         term.setTextColor(colors.white) else
  1423.         term.setTextColor(colors.white)
  1424.         print("02. " ..Num2)
  1425.     end
  1426.     term.setBackgroundColor(32768)
  1427.     if listLine == 3 then
  1428.         paintutils.drawFilledBox(1,3,x,3,256)
  1429.         term.setCursorPos(1,3)
  1430.     end
  1431.     if status3 == "complete" then
  1432.         term.setTextColor(colors.lime)
  1433.         print("03. " ..Num3)
  1434.         term.setTextColor(colors.white) elseif
  1435.         status3 == "cancel" then
  1436.         term.setTextColor(colors.red)
  1437.         print("03. " ..Num3)
  1438.         term.setTextColor(colors.white) else
  1439.         term.setTextColor(colors.white)
  1440.         print("03. " ..Num3)
  1441.     end
  1442.     term.setBackgroundColor(32768)
  1443.     if listLine == 4 then
  1444.         paintutils.drawFilledBox(1,4,x,4,256)
  1445.         term.setCursorPos(1,4)
  1446.     end
  1447.     if status4 == "complete" then
  1448.         term.setTextColor(colors.lime)
  1449.         print("04. " ..Num4)
  1450.         term.setTextColor(colors.white) elseif
  1451.         status4 == "cancel" then
  1452.         term.setTextColor(colors.red)
  1453.         print("04. " ..Num4)
  1454.         term.setTextColor(colors.white) else
  1455.         term.setTextColor(colors.white)
  1456.         print("04. " ..Num4)
  1457.     end
  1458.     term.setBackgroundColor(32768)
  1459.     if listLine == 5 then
  1460.         paintutils.drawFilledBox(1,5,x,5,256)
  1461.         term.setCursorPos(1,5)
  1462.     end
  1463.     if status5 == "complete" then
  1464.         term.setTextColor(colors.lime)
  1465.         print("05. " ..Num5)
  1466.         term.setTextColor(colors.white) elseif
  1467.         status5 == "cancel" then
  1468.         term.setTextColor(colors.red)
  1469.         print("05. " ..Num5)
  1470.         term.setTextColor(colors.white) else
  1471.         term.setTextColor(colors.white)
  1472.         print("05. " ..Num5)
  1473.     end
  1474.     term.setBackgroundColor(32768)
  1475.     if listLine == 6 then
  1476.         paintutils.drawFilledBox(1,6,x,6,256)
  1477.         term.setCursorPos(1,6)
  1478.     end
  1479.     if status6 == "complete" then
  1480.         term.setTextColor(colors.lime)
  1481.         print("06. " ..Num6)
  1482.         term.setTextColor(colors.white) elseif
  1483.         status6 == "cancel" then
  1484.         term.setTextColor(colors.red)
  1485.         print("06. " ..Num6)
  1486.         term.setTextColor(colors.white) else
  1487.         term.setTextColor(colors.white)
  1488.         print("06. " ..Num6)
  1489.     end
  1490.     term.setBackgroundColor(32768)
  1491.     if listLine == 7 then
  1492.         paintutils.drawFilledBox(1,7,x,7,256)
  1493.         term.setCursorPos(1,7)
  1494.     end
  1495.     if status7 == "complete" then
  1496.         term.setTextColor(colors.lime)
  1497.         print("07 " ..Num7)
  1498.         term.setTextColor(colors.white) elseif
  1499.         status7 == "cancel" then
  1500.         term.setTextColor(colors.red)
  1501.         print("07. " ..Num7)
  1502.         term.setTextColor(colors.white) else
  1503.         term.setTextColor(colors.white)
  1504.         print("07. " ..Num7)
  1505.     end
  1506.     term.setBackgroundColor(32768)
  1507.     if listLine == 8 then
  1508.         paintutils.drawFilledBox(1,8,x,8,256)
  1509.         term.setCursorPos(1,8)
  1510.     end
  1511.     if status8 == "complete" then
  1512.         term.setTextColor(colors.lime)
  1513.         print("08. " ..Num8)
  1514.         term.setTextColor(colors.white) elseif
  1515.         status8 == "cancel" then
  1516.         term.setTextColor(colors.red)
  1517.         print("08. " ..Num8)
  1518.         term.setTextColor(colors.white) else
  1519.         term.setTextColor(colors.white)
  1520.         print("08. " ..Num8)
  1521.     end
  1522.     term.setBackgroundColor(32768)
  1523.     if listLine == 9 then
  1524.         paintutils.drawFilledBox(1,9,x,9,256)
  1525.         term.setCursorPos(1,9)
  1526.     end
  1527.     if status9 == "complete" then
  1528.         term.setTextColor(colors.lime)
  1529.         print("09. " ..Num9)
  1530.         term.setTextColor(colors.white) elseif
  1531.         status9 == "cancel" then
  1532.         term.setTextColor(colors.red)
  1533.         print("09. " ..Num9)
  1534.         term.setTextColor(colors.white) else
  1535.         term.setTextColor(colors.white)
  1536.         print("09. " ..Num9)
  1537.     end
  1538.     term.setBackgroundColor(32768)
  1539.     if listLine == 10 then
  1540.         paintutils.drawFilledBox(1,10,x,10,256)
  1541.         term.setCursorPos(1,10)
  1542.     end
  1543.     if status10 == "complete" then
  1544.         term.setTextColor(colors.lime)
  1545.         print("10. " ..Num10)
  1546.         term.setTextColor(colors.white) elseif
  1547.         status10 == "cancel" then
  1548.         term.setTextColor(colors.red)
  1549.         print("10. " ..Num10)
  1550.         term.setTextColor(colors.white) else
  1551.         term.setTextColor(colors.white)
  1552.         print("10. " ..Num10)
  1553.     end
  1554.     term.setBackgroundColor(32768)
  1555.     lineChange = listLine
  1556.     listLine = 0
  1557. end
  1558.  
  1559. function changeNum()
  1560.     rednet.send(rID, username, TDList)
  1561.     rednet.send(rID, numChange, TDList)
  1562.     rednet.send(rID, newNum, TDList)
  1563.     rednet.send(rID, status, TDList)
  1564. end
  1565.  
  1566. function editNum()
  1567.     term.setCursorPos(1,14)
  1568.     term.clearLine()
  1569.     term.setCursorPos(1,15)
  1570.     term.clearLine()
  1571.     term.setCursorPos(1,16)
  1572.     term.clearLine()
  1573.     term.setCursorPos(1,17)
  1574.     term.clearLine()
  1575.     term.setCursorPos(1,18)
  1576.     term.clearLine()
  1577.     term.setCursorPos(1,16)
  1578.     status = "normal"
  1579.     numChange = "change"..lineChange
  1580.     write("Edit: ")
  1581.     newNum = read()
  1582.     lenght = string.len(newNum)
  1583.     if lenght>23 then
  1584.         term.clearLine()
  1585.         write("Max lenght is 23")
  1586.         sleep(1)
  1587.         editNum()
  1588.     end
  1589.     changeNum()
  1590. end
  1591.  
  1592. function changeStatus()
  1593.     numChange = "change"..lineChange
  1594.     if lineChange == 1 then
  1595.         newNum = Num1
  1596.         elseif lineChange == 2 then
  1597.         newNum = Num2
  1598.         elseif lineChange == 3 then
  1599.         newNum = Num3
  1600.         elseif lineChange == 4 then
  1601.         newNum = Num4
  1602.         elseif lineChange == 5 then
  1603.         newNum = Num5
  1604.         elseif lineChange == 6 then
  1605.         newNum = Num6
  1606.         elseif lineChange == 7 then
  1607.         newNum = Num7
  1608.         elseif lineChange == 8 then
  1609.         newNum = Num8
  1610.         elseif lineChange == 9 then
  1611.         newNum = Num9
  1612.         elseif lineChange == 10 then
  1613.         newNum = Num10
  1614.     end
  1615.     changeNum()
  1616. end
  1617.  
  1618. function voting()
  1619.     clear()
  1620.     text = "The voting app is still WIP"
  1621.     line = 0
  1622.     printCentered()
  1623.     sleep(2)
  1624.     pressedButton = nil
  1625.     interface()
  1626.     return
  1627. end
  1628.  
  1629. function events()
  1630.     clear()
  1631.     text = "The events app is still WIP"
  1632.     line = 0
  1633.     printCentered()
  1634.     sleep(2)
  1635.     pressedButton = nil
  1636.     interface()
  1637. end
  1638.  
  1639. function help()
  1640.     clear()
  1641.     print("Please click on a topic you want help with")
  1642.     print("1. General")
  1643.     print("2. Mail")
  1644.     print("3. To do")
  1645.     print("4. Door")
  1646.     print("5. Compass")
  1647.     print("6. Voting")
  1648.     print("7. Events")
  1649.     print("8. Command")
  1650.     returnButton()
  1651.     while true do
  1652.         getClickPos()
  1653.         returnButton()
  1654.         if linePos == 3 then
  1655.             helpWith = 1
  1656.             elseif linePos == 4 then
  1657.             helpWith = 2
  1658.             elseif linePos == 5 then
  1659.             helpWith = 3
  1660.             elseif linePos == 6 then
  1661.             helpWith = 4
  1662.             elseif linePos == 7 then
  1663.             helpWith = 5
  1664.             elseif linePos == 8 then
  1665.             helpWith = 6
  1666.             elseif linePos == 9 then
  1667.             helpWith = 7
  1668.             elseif linePos == 10 then
  1669.             helpWith = 8
  1670.             elseif pressedButton == 7 then
  1671.             pressedButton = nil
  1672.             interface2()
  1673.             return
  1674.         end
  1675.         if helpWith == 1 then
  1676.             helpGeneral()
  1677.         elseif helpWith == 2 then
  1678.         end
  1679.     end
  1680.     pressedButton = nil
  1681.     interface2()
  1682. end
  1683.  
  1684. function helpGeneral()
  1685.     clear()
  1686.     print("1. Interface")
  1687.     print("2. Requirements")
  1688.     print("3. Credits")
  1689.     returnButton()
  1690.     while true do
  1691.         getClickPos()
  1692.         returnButton()
  1693.         if linePos == 1 then
  1694.             clear()
  1695.             print("The OverWatch OS uses a Graphical user interface or GUI, which means you can click on it. Sometimes big green buttons are used to click on, but sometimes buttuns wil be whole lines usualy marked with 1., 2., 3. etc.")
  1696.             returnButton()
  1697.             while true do
  1698.                 getClickPos()
  1699.                 if pressedButton == 7 then
  1700.                     helpGeneral()
  1701.                 end
  1702.             end
  1703.         elseif linePos == 2 then
  1704.             clear()
  1705.             print("To use the OverWatch OS you need an advanced Pocket computer. This is required becouse it has to display colors and be able to get mouse input. The pocket Computer must also be wireless since it has to contact the server where all the data is actualy storred")
  1706.             returnButton()
  1707.             while true do
  1708.                 getClickPos()
  1709.                 if pressedButton == 7 then
  1710.                     helpGeneral()
  1711.                 end
  1712.             end
  1713.         elseif pressedButton == 7 then
  1714.             pressedButton = nil
  1715.             help()
  1716.             return
  1717.         end
  1718.     end
  1719. end
  1720.  
  1721. -------------------------------------------------
  1722. run = true
  1723. if pocket then
  1724.     initialize()
  1725.     lockedScreen()
  1726.     while run == true do
  1727.         interface()
  1728.     end
  1729.     else
  1730.     print("No hackers allowed lol")
  1731.     sleep(1)
  1732.     os.shutdown()
  1733. end
Add Comment
Please, Sign In to add comment