Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local unpack = unpack or table.unpack --#compatibility with 5.1 & 5.2
- os.pullEvent = function( sFilter ) --#override os.pullEvent
- local result
- repeat --#pull a raw event until the returned event is not terminate
- result = {os.pullEventRaw( sFilter )}
- until result[ 1 ] ~= "terminate"
- return unpack( result )
- end
- -----------------------------------------------------------------------------------------------------
- debug = false
- xPos = nil
- yPos = nil
- autoUpdate = true
- -----------------------------------------------------------------------------------------------------
- function initialize()
- getResolution()
- fs.delete("saves/loginData")
- exists = fs.exists("saves")
- if exists == false then
- print("Downloading files")
- end
- exists = fs.exists("saves/compass/data/loc1")
- if exists == false then
- file = fs.open("saves/compass/data/loc1", "w")
- file.writeLine("Loc. 1")
- file.writeLine(0)
- file.writeLine(0)
- file.close()
- print("Created Loc1")
- end
- exists = fs.exists("saves/compass/data/loc2")
- if exists == false then
- file = fs.open("saves/compass/data/loc2", "w")
- file.writeLine("Loc. 2")
- file.writeLine(0)
- file.writeLine(0)
- file.close()
- print("Created Loc2")
- end
- exists = fs.exists("saves/compass/images")
- if exists == false then
- pb("W3WtTb7X", "saves/compass/images/East")
- pb("XkCzw5Eu","saves/compass/images/North")
- pb("cf87Bj7B","saves/compass/images/NorthEast")
- pb("h5j04eup","saves/compass/images/NorthWest")
- pb("vPRiFCxa","saves/compass/images/South")
- pb("rPNaEPd6","saves/compass/images/SouthEast")
- pb("tdV2C3Uf","saves/compass/images/SouthWest")
- pb("90SN6r7V","saves/compass/images/West")
- print("Downloaded Compass images")
- end
- exists = fs.exists("saves/door/key")
- if exists == false then
- pb("XJujhEvA", "saves/door/key")
- print("Downloaded key image")
- end
- exists = fs.exists("saves/OS files/id")
- if exists == false then
- setUp = false
- print("Device not set up")
- else file = fs.open("saves/OS files/id", "r" ) -- read ID
- rID = file.readLine()
- file.close()
- rID = tonumber(rID)
- end
- exists = fs.exists("saves/OS files/version")
- if exists == false then
- currentVersion = 0
- else file = fs.open("saves/OS files/version", "r" )
- currentVersion = file.readLine()
- file.close()
- currentVersion = tonumber(currentVersion)
- end
- pb("r1cCb1Nn", "saves/OS files/updater")
- print("Updated updater")
- updater()
- checkSetUp()
- wireless = peripheral.isPresent("back")
- if wireless == false then
- clear()
- text = "The device"
- line = 4
- printCentered()
- text = "must be wireless"
- line = 3
- printCentered()
- text = "Press the Enter key"
- line = 1
- printCentered()
- text = "to delete the program or"
- line = 0
- printCentered()
- text = "wait 5 seconds for the"
- line = -1
- printCentered()
- text = "device to turn off"
- line = -2
- printCentered()
- resetTimer = os.startTimer(5)
- local event, key = os.pullEvent()
- while true do
- local event, key = os.pullEvent()
- if event == "key" then
- if key == 28 then
- fs.delete("startup")
- fs.delete("saves")
- os.reboot()
- end
- elseif event == "timer" then
- if key == "resetTimer" then
- os.shutdown()
- end
- end
- end
- end
- rednet.open("back")
- advanced = term.isColor()
- if advanced == false then
- clear()
- text = "The device"
- line = 4
- printCentered()
- text = "must be advanced"
- line = 3
- printCentered()
- text = "Press the Enter key"
- line = 1
- printCentered()
- text = "to delete the program or"
- line = 0
- printCentered()
- text = "wait 5 seconds for the"
- line = -1
- printCentered()
- text = "device to turn off"
- line = -2
- printCentered()
- resetTimer2 = os.startTimer(5)
- local event, key = os.pullEvent()
- while true do
- local event, key = os.pullEvent()
- if event == "key" then
- if key == 28 then
- fs.delete("startup")
- fs.delete("saves")
- os.reboot()
- end
- elseif event == "timer" then
- if key == resetTimer2 then
- os.shutdown()
- end
- end
- end
- end
- print("Getting protocols")
- rednet.send(rID, "all", "kj24fg2hz5fhj4xc3gg2c45")
- sID, uData = rednet.receive("n4xf4xbc5f7dx85hgcy<o56")
- sID, SesKeys = rednet.receive("sfh546dhsg65423hkvb34c6")
- sID, doorCtrl = rednet.receive("d567s25f,3j3n5fcd25f3y5")
- sID, TDList = rednet.receive("qw7bv3klf3f34bc472zl32g")
- sID, Mail = rednet.receive("p2k54v1f4h2v321c5hnn314")
- sID, event = rednet.receive("d578tz232353jklc53kl655")
- sID, vote = rednet.receive("cf5h83gxd25g3j5fg3j53c")
- print("Received protocols")
- end
- function updater()
- if autoUpdate == true then
- file = fs.open("saves/OS files/updater", "r" )
- name = file.readLine()
- newestVersion = file.readLine()
- file.close()
- newestVersion = tonumber(newestVersion)
- if newestVersion > currentVersion then
- print("There is a new update available")
- print("Current version:", currentVersion, " Newest version", newestVersion)
- sleep(1)
- fs.delete("startup")
- pb("jnZP4DN6", "startup")
- file = fs.open("saves/OS files/version", "w" )
- file.write(newestVersion)
- file.close()
- os.reboot()
- else
- print("The newest version is already installed")
- end
- end
- end
- function checkSetUp()
- if setUp == false then
- clear()
- line = 3
- text = " Please insert the PoC"
- printCentered()
- line = 2
- text = "into the server disk"
- printCentered()
- line = 1
- text = "drive to connect it to"
- printCentered()
- line = 0
- text = "the server"
- printCentered()
- sleep(5)
- os.shutdown()
- end
- end
- function pb(paste, file)
- response = http.get("http://pastebin.com/raw/"..paste)
- sResponse = response.readAll()
- response.close()
- file = fs.open(file, "w" )
- file.write(sResponse)
- file.close()
- end
- function getTime()
- time = textutils.formatTime(os.time(), true)
- end
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- function getResolution()
- x,y = term.getSize()
- end
- function centerX()
- lenght = string.len(text)/2
- a = x/2 - lenght
- end
- function centerY()
- b = y/2 - line
- end
- function leftX()
- d = line
- lenght = string.len(text)/2
- c = e - lenght
- term.setCursorPos(c,d)
- write(text)
- end
- function rightX()
- d = line
- lenght = string.len(text)/2
- c = f - lenght
- term.setCursorPos(c,d)
- write(text)
- end
- function printCentered()
- centerX()
- centerY()
- term.setCursorPos(a,b)
- print(text)
- end
- function lockedScreen()
- clear()
- getResolution()
- text = "Please log in"
- line = 2
- printCentered()
- text = "Username: "
- line = 1
- printCentered()
- text = "Password: "
- line = 0
- printCentered()
- line = 1
- centerY()
- a = x/2
- term.setCursorPos(a, b)
- username = read()
- line = 0
- centerY()
- a = x/2
- term.setCursorPos(a, b)
- password = read("*")
- checkCred()
- end
- function checkCred()
- rednet.send(rID, username, uData)
- rednet.send(rID, password, uData)
- sID,match = rednet.receive(uData)
- if rID == sID then
- if match == "Match" then
- sID,clearance = rednet.receive(uData)
- initialize() elseif
- match == "No match" then
- line = -1
- text = "No match found"
- printCentered()
- sleep(1)
- lockedScreen() else
- end
- end
- end
- function getSessionKey()
- rednet.send(rID, username, SesKeys)
- id, sessionKey = rednet.receive(SesKeys)
- end
- function commandLine()
- term.setCursorPos(1,y)
- term.clearLine()
- term.setCursorPos(1,y-1)
- term.clearLine()
- write("Command:")
- input = read()
- if input == "exit" then
- if clearance == "1.0" then
- clear()
- run = false
- shell.exit()
- return else
- text = "Insufficient acces"
- line = 1
- printCentered()
- sleep(1)
- pressedButton = nil
- interface()
- return
- end
- elseif input == "debug" then
- if debug == false then
- debug = true
- term.clearLine()
- term.setCursorPos(1,y)
- term.setTextColor(8)
- write("Debug mode enabled")
- term.setTextColor(1)
- sleep(1) elseif
- debug == true then
- debug = false
- term.clearLine()
- term.setCursorPos(1,y)
- term.setTextColor(8)
- write("Debug mode disabled")
- term.setTextColor(1)
- sleep(1)
- end
- elseif input == "cancel" then
- pressedButton = nil
- interface2()
- return
- else
- write("invalid command")
- sleep(1)
- commandLine()
- end
- interface2()
- end
- function interface()
- clear()
- setButtonIDs()
- renderButtons()
- nextButton()
- timeTimer = os.startTimer(0)
- while true do
- local event, par1, X, Y = os.pullEvent()
- if (event == "timer") and (par1 == timeTimer) then
- printTime()
- timeTimer = os.startTimer(0.1) elseif
- (event == "mouse_click")then
- xPos = X
- yPos = Y
- getClickPos()
- end
- if pressedButton == 1 then
- button1() elseif
- pressedButton == 2 then
- button2() elseif
- pressedButton == 3 then
- button3() elseif
- pressedButton == 4 then
- button4() elseif
- pressedButton == 5 then
- button5() elseif
- pressedButton == 6 then
- button6() elseif
- pressedButton == 8 then
- interface2()
- end
- xPos = nil
- yPos = nil
- end
- end
- function interface2()
- clear()
- returnButton()
- button = 1
- buttonID1 = "Command"
- toggleButton()
- button = 2
- buttonID2 = "Help"
- toggleButton()
- setButtonIDs()
- while true do
- local event, par1, X, Y = os.pullEvent()
- if (event == "timer") and (par1 == timeTimer) then
- printTime()
- timeTimer = os.startTimer(0.1) elseif
- (event == "mouse_click")then
- xPos = X
- yPos = Y
- getClickPos()
- end
- if pressedButton == 1 then
- commandLine() elseif
- pressedButton == 2 then
- help() elseif
- pressedButton == 7 then
- interface()
- end
- end
- xPos = nil
- yPos = nil
- end
- function renderButtons()
- button = 1
- state = "on"
- while true do
- if button < 7 then
- toggleButton()
- button = button + 1 else
- break
- end
- end
- end
- function toggleButton()
- if pocket then
- e = 8
- f = 20
- if button == 1 then
- if state == "on" then
- paintutils.drawFilledBox(3, 2, 12, 6, 8192) elseif
- state == "off" then
- paintutils.drawFilledBox(3, 2, 12, 6, 16384)
- end
- text = buttonID1
- line = 4
- leftX()
- elseif button == 2 then
- if state == "on" then
- paintutils.drawFilledBox(15, 2, 24, 6, 8192) elseif
- state == "off" then
- paintutils.drawFilledBox(15, 2, 24, 6, 16384)
- end
- text = buttonID2
- line = 4
- rightX()
- elseif button == 3 then
- if state == "on" then
- paintutils.drawFilledBox(3, 8, 12, 12, 8192) elseif
- state == "off" then
- paintutils.drawFilledBox(3, 8, 12, 12, 16384)
- end
- text = buttonID3
- line = 10
- leftX()
- elseif button == 4 then
- if state == "on" then
- paintutils.drawFilledBox(15, 8, 24, 12, 8192) elseif
- state == "off" then
- paintutils.drawFilledBox(15, 8, 24, 12, 16384)
- end
- text = buttonID4
- line = 10
- rightX()
- elseif button == 5 then
- if state == "on" then
- paintutils.drawFilledBox(3, 14, 12, 18, 8192) elseif
- state == "off" then
- paintutils.drawFilledBox(3, 14, 12, 18, 16384)
- end
- text = buttonID5
- line = 16
- leftX()
- elseif button == 6 then
- if state == "on" then
- paintutils.drawFilledBox(15, 14, 24, 18, 8192) elseif
- state == "off" then
- paintutils.drawFilledBox(15, 14, 24, 18, 16384)
- end
- text = buttonID6
- line = 16
- rightX()
- end
- term.setBackgroundColor(32768)
- end
- end
- function returnButton()
- term.setCursorPos(1,y)
- paintutils.drawFilledBox(1, y, 6, y, 8192)
- term.setCursorPos(2,y)
- write("Back")
- term.setBackgroundColor(32768)
- end
- function nextButton()
- term.setCursorPos(20,y)
- paintutils.drawFilledBox(20, y, x, y, 8192)
- term.setCursorPos(22,y)
- write("Next")
- term.setBackgroundColor(32768)
- end
- function getClickPos()
- getResolution()
- term.setCursorPos(1,y)
- if (xPos == nil) or (yPos == nil) then
- event, button, xPos, yPos = os.pullEvent("mouse_click")
- end
- if (xPos > 2) and (xPos < 13) and (yPos > 1) and (yPos < 7) then
- pressedButton = 1 elseif
- (xPos > 14) and (xPos < 25) and (yPos > 1) and (yPos < 7) then
- pressedButton = 2 elseif
- (xPos > 2) and (xPos < 13) and (yPos > 7) and (yPos < 13) then
- pressedButton = 3 elseif
- (xPos > 14) and (xPos < 25) and (yPos > 7) and (yPos < 13) then
- pressedButton = 4 elseif
- (xPos > 2) and (xPos < 13) and (yPos > 13) and (yPos < 19) then
- pressedButton = 5 elseif
- (xPos > 14) and (xPos < 25) and (yPos > 13) and (yPos < 19) then
- pressedButton = 6 elseif
- (xPos > 0) and (xPos < 7) and (yPos == y) then
- pressedButton = 7 elseif
- (xPos > 20) and (xPos < 27) and (yPos == y) then
- pressedButton = 8
- end
- if debug == true then
- term.setCursorPos(1,y)
- term.setTextColor(8)
- write("X:")
- write(xPos)
- write(" Y:")
- write(yPos)
- term.setTextColor(1)
- sleep(1)
- term.clearLine()
- end
- linePos = yPos
- xPos = nil
- yPos = nil
- end
- function setButtonIDs()
- buttonID1 = "Mail"
- buttonID2 = " To do"
- buttonID3 = "Door"
- buttonID4 = " Compass"
- buttonID5 = " Voting"
- buttonID6 = " Events"
- end
- function button1()
- if debug == true then
- term.setCursorPos(1,y)
- term.setTextColor(8)
- write("button 1")
- term.setTextColor(1)
- sleep(1)
- term.clearLine()
- end
- mailFunc()
- pressedButton = nil
- xPos = nil
- yPos = nil
- end
- function button2()
- if debug == true then
- term.setCursorPos(1,y)
- term.setTextColor(8)
- write("buttton 2")
- term.setTextColor(1)
- sleep(1)
- term.clearLine()
- end
- toDo()
- pressedButton = nil
- xPos = nil
- yPos = nil
- end
- function button3()
- if debug == true then
- term.setTextColor(8)
- term.setCursorPos(1,y)
- write("buttton 3")
- term.setTextColor(1)
- sleep(1)
- term.clearLine()
- end
- door()
- pressedButton = nil
- xPos = nil
- yPos = nil
- end
- function button4()
- if debug == true then
- term.setCursorPos(1,y)
- term.setTextColor(8)
- write("buttton 4")
- term.setTextColor(1)
- sleep(1)
- term.clearLine()
- end
- compass()
- pressedButton = nil
- xPos = nil
- yPos = nil
- end
- function button5()
- if debug == true then
- term.setCursorPos(1,y)
- term.setTextColor(8)
- write("buttton 5")
- term.setTextColor(1)
- sleep(1)
- term.clearLine()
- end
- voting()
- pressedButton = nil
- xPos = nil
- yPos = nil
- end
- function button6()
- if debug == true then
- term.setCursorPos(1,y)
- term.setTextColor(8)
- write("buttton 6")
- term.setTextColor(1)
- sleep(1)
- term.clearLine()
- end
- events()
- pressedButton = nil
- xPos = nil
- yPos = nil
- end
- function printTime()
- getTime()
- term.setCursorPos(1,1)
- term.clearLine()
- write(time)
- end
- function door()
- clear()
- paintutils.drawImage(paintutils.loadImage("saves/door/key"),x/2-8,2)
- term.setBackgroundColor(32768)
- line = 2
- text = "You can now open"
- printCentered()
- text = "doors for 3 seconds"
- line = 1
- printCentered()
- text = "Insert the PDA"
- line = -1
- printCentered()
- text = "into a door disk drive"
- line = -2
- printCentered()
- getSessionKey()
- file = fs.open("saves/door/loginData", "w")
- file.writeLine(sessionKey)
- file.close()
- sleep(3)
- exists = fs.exists("saves/door/loginData")
- if exists == true then
- fs.delete("saves/door/loginData")
- end
- pressedButton = nil
- interface()
- return
- end
- function compass()
- file = fs.open("saves/compass/data/loc1","r")
- location1 = file.readLine()
- l1X = file.readLine()
- l1Z = file.readLine()
- file.close()
- file = fs.open("saves/compass/data/loc2","r")
- location2 = file.readLine()
- l2X = file.readLine()
- l2Z = file.readLine()
- file.close()
- clear()
- returnButton()
- text = " Where would"
- line = 6
- printCentered()
- text = " you like to go?"
- line = 5
- printCentered()
- button = 3
- buttonID3 = location1
- toggleButton()
- button = 4
- buttonID4 = location2
- toggleButton()
- button = 5
- buttonID5 = "Custom"
- toggleButton()
- button = 6
- buttonID6 = "Change"
- toggleButton()
- setButtonIDs()
- getLocation()
- while true do
- getClickPos()
- if pressedButton == 3 then
- if l1X == "0.0" then
- clear()
- text = " Before first use you"
- line = 6
- printCentered()
- line = 5
- text = " have to set the location"
- printCentered()
- sleep(1)
- change1()
- end
- returnButton()
- comTimer = os.startTimer(0) --compass timer
- while true do
- local event, par1, X, Y = os.pullEvent()
- if (event == "timer") and (par1 == comTimer) then
- getLocation()
- gX = l1X - cX -- go to = location 1 X - current X
- gZ = l1Z - cZ
- refreshCompass()
- comTimer = os.startTimer(1) elseif
- (event == "mouse_click") and (X > 0) and (X < 7) and (Y == y) then
- pressedButton = nil
- compass()
- return
- end
- end
- elseif pressedButton == 4 then
- if l2X == "0.0" then
- clear()
- text = "Before first use you"
- line = 6
- printCentered()
- text = "have to set the location"
- line = 5
- printCentered()
- sleep(1)
- change2()
- end
- comTimer = os.startTimer(0)
- while true do
- local event, par1, X, Y = os.pullEvent()
- if (event == "timer") and (par1 == comTimer) then
- getLocation()
- gX = l2X - cX -- go to
- gZ = l2Z - cZ
- refreshCompass()
- comTimer = os.startTimer(1) elseif
- (event == "mouse_click") and (X > 0) and (X < 7) and (Y == y) then
- pressedButton = nil
- compass()
- return
- end
- end
- elseif pressedButton == 5 then
- clear()
- text = "Type in the"
- line = 5
- printCentered()
- text = "coordinates"
- line = 4
- printCentered()
- text = "X coord.: "
- line = 2
- printCentered()
- text = "Z coord.: "
- line = 1
- printCentered()
- line = 2
- centerY()
- a = x/2
- term.setCursorPos(a, b)
- lcX = read()
- numCheck = tonumber(lcX)
- if numCheck == nil then
- text = "X can only"
- line = -3
- printCentered()
- text = "be a number"
- line = -4
- printCentered()
- sleep(1)
- change1()
- end
- line = 1
- centerY()
- a = x/2
- term.setCursorPos(a, b)
- lcZ = read()
- numCheck = tonumber(lcZ)
- if numCheck == nil then
- text = "Z can only"
- line = -3
- printCentered()
- text = "be a number"
- line = -4
- printCentered()
- sleep(1)
- change1()
- end
- comTimer = os.startTimer(0)
- while true do
- local event, par1, X, Y = os.pullEvent()
- if (event == "timer") and (par1 == comTimer) then
- getLocation()
- gX = lcX - cX -- go to
- gZ = lcZ - cZ
- refreshCompass()
- comTimer = os.startTimer(1) elseif
- (event == "mouse_click") and (X > 0) and (X < 7) and (Y == y) then
- pressedButton = nil
- compass()
- return
- end
- end
- elseif pressedButton == 6 then
- clear()
- returnButton()
- text = " Which location would"
- line = 6
- printCentered()
- text = " you like to change?"
- line = 5
- printCentered()
- button = 3
- buttonID3 = location1
- toggleButton()
- button = 4
- buttonID4 = location2
- toggleButton()
- toggleButton()
- setButtonIDs()
- getClickPos()
- if pressedButton == 3 then
- change1() elseif
- pressedButton == 4 then
- change2() elseif
- pressedButton == 7 then
- pressedButton = nil
- compass()
- return
- end
- elseif pressedButton == 7 then
- pressedButton = nil
- interface()
- return
- end
- end
- end
- function change1()
- clear()
- text = "Fill in"
- line = 6
- printCentered()
- text = "the next data"
- line = 5
- printCentered()
- text = "Name: "
- line = 3
- printCentered()
- text = "X coord.: "
- line = 2
- printCentered()
- text = "Z coord.: "
- line = 1
- printCentered()
- line = 3
- centerY()
- a = x/2
- term.setCursorPos(a, b)
- newName = read()
- lenght = string.len(newName)
- if (lenght>7) then
- text = "The name can only"
- line = -3
- printCentered()
- text = "be 7 letters long"
- line = -4
- printCentered()
- sleep(1)
- change1()
- end
- line = 2
- centerY()
- a = x/2
- term.setCursorPos(a, b)
- newX = read()
- numCheck = tonumber(newX)
- if numCheck == nil then
- text = "X can only"
- line = -3
- printCentered()
- text = "be a number"
- line = -4
- printCentered()
- sleep(1)
- change1()
- end
- line = 1
- centerY()
- a = x/2
- term.setCursorPos(a, b)
- newZ = read()
- numCheck = tonumber(newZ)
- if numCheck == nil then
- text = "Z can only"
- line = -3
- printCentered()
- text = "be a number"
- line = -4
- printCentered()
- sleep(1)
- change1()
- end
- file = fs.open("saves/compass/data/loc1", "w")
- file.writeLine(newName)
- file.writeLine(newX)
- file.writeLine(newZ)
- file.close()
- compass()
- end
- function change2()
- clear()
- text = "Fill in"
- line = 6
- printCentered()
- text = "the next data"
- line = 5
- printCentered()
- text = "Name: "
- line = 3
- printCentered()
- text = "X coord.: "
- line = 2
- printCentered()
- text = "Z coord.: "
- line = 1
- printCentered()
- line = 3
- centerY()
- a = x/2
- term.setCursorPos(a, b)
- newName = read()
- lenght = string.len(newName)
- if (lenght>7) then
- text = "The name can only"
- line = -3
- printCentered()
- text = "be 7 letters long"
- line = -4
- printCentered()
- sleep(1)
- change1()
- end
- line = 2
- centerY()
- a = x/2
- term.setCursorPos(a, b)
- newX = read()
- numCheck = tonumber(newX)
- if numCheck == nil then
- text = "X can only"
- line = -3
- printCentered()
- text = "be a number"
- line = -4
- printCentered()
- sleep(1)
- change1()
- end
- line = 1
- centerY()
- a = x/2
- term.setCursorPos(a, b)
- newZ = read()
- if numCheck == nil then
- text = "Z can only"
- line = -3
- printCentered()
- text = "be a number"
- line = -4
- printCentered()
- sleep(1)
- change1()
- end
- file = fs.open("saves/compass/data/loc2", "w")
- file.writeLine(newName)
- file.writeLine(newX)
- file.writeLine(newZ)
- file.close()
- compass()
- end
- function getLocation()
- cX, cY, cZ = gps.locate() --current
- if cX == nil then
- print("Failed to get location!")
- sleep(2)
- pressedButton = nil
- return
- else
- cX = math.round(cX)
- cY = math.round(cY)
- cZ = math.round(cZ)
- end
- end
- function refreshCompass()
- getDirections()
- number = gX
- getAbsolute()
- goX = Anumber
- number = gZ
- getAbsolute()
- goZ = Anumber
- clear()
- drawCompass()
- line = -7
- centerY()
- term.setCursorPos(1, b)
- if debug == true then
- term.setTextColor(8)
- print(cX, cY, cZ, gX, gZ)
- term.setTextColor(1)
- end
- if (goZ == 0) and (dZ == nil) then
- clear()
- text = "You have arrived"
- line = 1
- printCentered()
- text = "to your destination"
- line = 0
- printCentered() elseif
- dX == nil then
- print("Go", goZ, "blocks", dZ) elseif
- dZ == nil then
- print("Go", goX, "blocks", dX) elseif
- (goZ == 0) and (dZ == nil) then
- text = "You have arrived"
- line = 1
- printCentered()
- text = "to your destination"
- line = 0
- printCentered() else
- print("Go", goZ, "blocks", dZ, "and", goX, "blocks", dX)
- end
- returnButton()
- end
- function getDirections()
- if gX > 0 then
- dX = "East" else -- direction
- dX = "West"
- end
- if gX == 0 then
- dX = nil
- end
- if gZ > 0 then
- dZ = "South" else
- dZ = "North"
- end
- if gZ == 0 then
- dZ = nil
- end
- end
- function getAbsolute()
- if number < 0 then
- Anumber = -1*number else
- Anumber = number
- end
- end
- function drawCompass()
- if (dZ == "North") and (dX == nil) then
- image = paintutils.loadImage("Saves/compass/images/North")
- a = x/2 - 8
- paintutils.drawImage(image, a,2) elseif
- (dZ == "South") and (dX == nil) then
- image = paintutils.loadImage("Saves/compass/images/South")
- a = x/2 - 8
- paintutils.drawImage(image, a,2) elseif
- (dZ == nil) and (dX == "West") then
- image = paintutils.loadImage("Saves/compass/images/West")
- a = x/2 - 8
- paintutils.drawImage(image, a,2) elseif
- (dZ == nil) and (dX == "East") then
- image = paintutils.loadImage("Saves/compass/images/East")
- a = x/2 - 8
- paintutils.drawImage(image, a,2) elseif
- (dZ == "North") and (dX == "West") then
- image = paintutils.loadImage("Saves/compass/images/NorthWest")
- a = x/2 - 8
- paintutils.drawImage(image, a,2) elseif
- (dZ == "North") and (dX == "East") then
- image = paintutils.loadImage("Saves/compass/images/NorthEast")
- a = x/2 - 8
- paintutils.drawImage(image, a,2) elseif
- (dZ == "South") and (dX == "West")then
- image = paintutils.loadImage("Saves/compass/images/SouthWest")
- a = x/2 - 8
- paintutils.drawImage(image, a,2) elseif
- (dZ == "South") and (dX == "East")then
- image = paintutils.loadImage("Saves/compass/images/SouthEast")
- a = x/2 - 8
- paintutils.drawImage(image, a,2)
- term.setBackgroundColor(32768)
- end
- term.setBackgroundColor(32768)
- end
- function math.round(n)
- for i = 1, #tostring(n) do
- if string.sub(tostring(n), i, i) == "." then
- return tonumber(string.sub(tostring(n), i+1, i+1)) >= 5 and math.ceil(n) or math.floor(n)
- end
- end
- return n
- end
- function mailFunc()
- clear()
- print("Inbox")
- print("New")
- num = 0
- rednet.send(rID, "sendMail", Mail)
- rednet.send(rID, username, Mail)
- rednet.send(rID, num, Mail)
- mail = {[1] = {}, [2] = {}, [3] = {}, [4] = {}, [5] = {}, [6] = {}, [7] = {}, [8] = {}}
- PosY = 3
- for i = 1,8 do
- sID, exists = rednet.receive(Mail)
- if exists == "exists" then
- sID, mail[i][1] = rednet.receive(Mail) --sender
- sID, mail[i][2] = rednet.receive(Mail) --day
- sID, mail[i][3] = rednet.receive(Mail) --time
- sID, mail[i][4] = rednet.receive(Mail) --title
- sID, mail[i][5] = rednet.receive(Mail) --message
- write( "From: "..mail[i][1])
- daySent = math.round(mail[i][2])
- daySent = tostring(daySent)
- currentDay = math.round(os.day())
- currentDay = tostring(currentDay)
- if daySent == currentDay then
- term.setCursorPos(x-#mail[i][3]+1, PosY)
- write(mail[i][3])
- elseif daySent ~= currentDay then
- term.setCursorPos(x-#daySent-3, PosY)
- write("Day "..daySent)
- end
- print( "Title:", mail[i][4])
- end
- PosY = PosY + 2
- end
- returnButton()
- nextButton()
- openMail = nil
- while true do
- getClickPos()
- returnButton()
- nextButton()
- openMail = nil
- if linePos == 2 then
- sendMail()
- elseif (linePos == 3) or (linePos == 4) then
- openMail = 1
- elseif (linePos == 5) or (linePos == 6) then
- openMail = 2
- elseif (linePos == 7) or (linePos == 8) then
- openMail = 3
- elseif (linePos == 9) or (linePos == 10) then
- openMail = 4
- elseif (linePos == 11) or (linePos == 12) then
- openMail = 5
- elseif (linePos == 13) or (linePos == 14) then
- openMail = 6
- elseif (linePos == 15) or (linePos == 16) then
- openMail = 7
- elseif (linePos == 17) or (linePos == 18) then
- openMail = 8
- elseif pressedButton == 7 then
- pressedButton = nil
- interface()
- return
- elseif pressedButton == 8 then
- num = 9
- mailFunc()
- else openMail = nil
- end
- sleep(0.1)
- OpenMail()
- end
- end
- function OpenMail()
- if openMail ~= nil then
- if mail[openMail][1] ~= nil then
- clear()
- daySent = math.round(mail[openMail][2])
- daySent = tostring(daySent)
- print("From:", mail[openMail][1])
- print("Sent on day", daySent, "at", mail[openMail][3])
- print("Title: ", mail[openMail][4])
- print(mail[openMail][5])
- returnButton()
- while true do
- getClickPos()
- if pressedButton == 7 then
- pressedButton = nil
- linePos = nil
- openMail = nil
- mailFunc()
- return
- end
- end
- end
- end
- end
- function sendMail()
- clear()
- write("receiver: ")
- receiver = read()
- write("Title: ")
- name = read()
- write("message: ")
- message = read()
- sender = username
- rednet.send(rID, "createMail", Mail)
- rednet.send(rID, username, Mail)
- rednet.send(rID, sender, Mail)
- rednet.send(rID, receiver, Mail)
- rednet.send(rID, os.day(), Mail)
- getTime()
- rednet.send(rID, time, Mail)
- rednet.send(rID, name, Mail)
- rednet.send(rID, message, Mail)
- sID, mailMatch = rednet.receive(Mail)
- clear()
- if mailMatch == "sent" then
- printCentered()
- text = "Mail sent"
- line = 0
- printCentered()
- elseif mailMatch == "noMatch" then
- text = "There is no such user "
- line = 0
- printCentered()
- end
- sleep(1)
- mailFunc()
- return
- end
- function toDo()
- clear()
- getList()
- printList()
- returnButton()
- getClickPos()
- while true do
- returnButton()
- if linePos == 1 then
- listLine = 1
- elseif linePos == 2 then
- listLine = 2
- elseif linePos == 3 then
- listLine = 3
- elseif linePos == 4 then
- listLine = 4
- elseif linePos == 5 then
- listLine = 5
- elseif linePos == 6 then
- listLine = 6
- elseif linePos == 7 then
- listLine = 7
- elseif linePos == 8 then
- listLine = 8
- elseif linePos == 9 then
- listLine = 9
- elseif linePos == 10 then
- listLine = 10
- elseif pressedButton == 7 then
- listLine = nil
- pressedButton = nil
- interface()
- return
- else toDo()
- end
- printList()
- returnButton()
- button = 5
- buttonID5 = "Edit"
- toggleButton()
- button = 6
- buttonID6 = "Status"
- toggleButton()
- getClickPos()
- if pressedButton == 5 then
- editNum()
- elseif pressedButton == 6 then
- button = 5
- buttonID5 = "Complete"
- toggleButton()
- button = 6
- buttonID6 = "Normal"
- toggleButton()
- returnButton()
- getClickPos()
- if pressedButton == 5 then
- status = "complete"
- changeStatus()
- elseif pressedButton == 6 then
- status = "normal"
- changeStatus()
- elseif pressedButton == 7 then
- pressedButton = nil
- interface()
- return
- end
- elseif pressedButton == 7 then
- pressedButton = nil
- interface()
- return
- end
- end
- pressedButton = nil
- interface()
- return
- end
- function getList()
- rednet.send(rID, username, TDList)
- rednet.send(rID, "send", TDList)
- sID,Num1 = rednet.receive(TDList)
- sID,status1 = rednet.receive(TDList)
- sID,Num2 = rednet.receive(TDList)
- sID,status2 = rednet.receive(TDList)
- sID,Num3 = rednet.receive(TDList)
- sID,status3 = rednet.receive(TDList)
- sID,Num4 = rednet.receive(TDList)
- sID,status4 = rednet.receive(TDList)
- sID,Num5 = rednet.receive(TDList)
- sID,status5 = rednet.receive(TDList)
- sID,Num6 = rednet.receive(TDList)
- sID,status6 = rednet.receive(TDList)
- sID,Num7 = rednet.receive(TDList)
- sID,status7 = rednet.receive(TDList)
- sID,Num8 = rednet.receive(TDList)
- sID,status8 = rednet.receive(TDList)
- sID,Num9 = rednet.receive(TDList)
- sID,status9 = rednet.receive(TDList)
- sID,Num10 = rednet.receive(TDList)
- sID,status10 = rednet.receive(TDList)
- end
- function printList()
- clear()
- if listLine == 1 then
- paintutils.drawFilledBox(1,1,x,1,256)
- term.setCursorPos(1,1)
- end
- if status1 == "complete" then
- term.setTextColor(colors.lime)
- print("01. " ..Num1)
- term.setTextColor(colors.white) elseif
- status1 == "cancel" then
- term.setTextColor(colors.red)
- print("01. " ..Num1)
- term.setTextColor(colors.white) else
- term.setTextColor(colors.white)
- print("01. " ..Num1)
- end
- term.setBackgroundColor(32768)
- if listLine == 2 then
- paintutils.drawFilledBox(1,2,x,2,256)
- term.setCursorPos(1,2)
- end
- if status2 == "complete" then
- term.setTextColor(colors.lime)
- print("02. " ..Num2)
- term.setTextColor(colors.white) elseif
- status2 == "cancel" then
- term.setTextColor(colors.red)
- print("02. " ..Num2)
- term.setTextColor(colors.white) else
- term.setTextColor(colors.white)
- print("02. " ..Num2)
- end
- term.setBackgroundColor(32768)
- if listLine == 3 then
- paintutils.drawFilledBox(1,3,x,3,256)
- term.setCursorPos(1,3)
- end
- if status3 == "complete" then
- term.setTextColor(colors.lime)
- print("03. " ..Num3)
- term.setTextColor(colors.white) elseif
- status3 == "cancel" then
- term.setTextColor(colors.red)
- print("03. " ..Num3)
- term.setTextColor(colors.white) else
- term.setTextColor(colors.white)
- print("03. " ..Num3)
- end
- term.setBackgroundColor(32768)
- if listLine == 4 then
- paintutils.drawFilledBox(1,4,x,4,256)
- term.setCursorPos(1,4)
- end
- if status4 == "complete" then
- term.setTextColor(colors.lime)
- print("04. " ..Num4)
- term.setTextColor(colors.white) elseif
- status4 == "cancel" then
- term.setTextColor(colors.red)
- print("04. " ..Num4)
- term.setTextColor(colors.white) else
- term.setTextColor(colors.white)
- print("04. " ..Num4)
- end
- term.setBackgroundColor(32768)
- if listLine == 5 then
- paintutils.drawFilledBox(1,5,x,5,256)
- term.setCursorPos(1,5)
- end
- if status5 == "complete" then
- term.setTextColor(colors.lime)
- print("05. " ..Num5)
- term.setTextColor(colors.white) elseif
- status5 == "cancel" then
- term.setTextColor(colors.red)
- print("05. " ..Num5)
- term.setTextColor(colors.white) else
- term.setTextColor(colors.white)
- print("05. " ..Num5)
- end
- term.setBackgroundColor(32768)
- if listLine == 6 then
- paintutils.drawFilledBox(1,6,x,6,256)
- term.setCursorPos(1,6)
- end
- if status6 == "complete" then
- term.setTextColor(colors.lime)
- print("06. " ..Num6)
- term.setTextColor(colors.white) elseif
- status6 == "cancel" then
- term.setTextColor(colors.red)
- print("06. " ..Num6)
- term.setTextColor(colors.white) else
- term.setTextColor(colors.white)
- print("06. " ..Num6)
- end
- term.setBackgroundColor(32768)
- if listLine == 7 then
- paintutils.drawFilledBox(1,7,x,7,256)
- term.setCursorPos(1,7)
- end
- if status7 == "complete" then
- term.setTextColor(colors.lime)
- print("07 " ..Num7)
- term.setTextColor(colors.white) elseif
- status7 == "cancel" then
- term.setTextColor(colors.red)
- print("07. " ..Num7)
- term.setTextColor(colors.white) else
- term.setTextColor(colors.white)
- print("07. " ..Num7)
- end
- term.setBackgroundColor(32768)
- if listLine == 8 then
- paintutils.drawFilledBox(1,8,x,8,256)
- term.setCursorPos(1,8)
- end
- if status8 == "complete" then
- term.setTextColor(colors.lime)
- print("08. " ..Num8)
- term.setTextColor(colors.white) elseif
- status8 == "cancel" then
- term.setTextColor(colors.red)
- print("08. " ..Num8)
- term.setTextColor(colors.white) else
- term.setTextColor(colors.white)
- print("08. " ..Num8)
- end
- term.setBackgroundColor(32768)
- if listLine == 9 then
- paintutils.drawFilledBox(1,9,x,9,256)
- term.setCursorPos(1,9)
- end
- if status9 == "complete" then
- term.setTextColor(colors.lime)
- print("09. " ..Num9)
- term.setTextColor(colors.white) elseif
- status9 == "cancel" then
- term.setTextColor(colors.red)
- print("09. " ..Num9)
- term.setTextColor(colors.white) else
- term.setTextColor(colors.white)
- print("09. " ..Num9)
- end
- term.setBackgroundColor(32768)
- if listLine == 10 then
- paintutils.drawFilledBox(1,10,x,10,256)
- term.setCursorPos(1,10)
- end
- if status10 == "complete" then
- term.setTextColor(colors.lime)
- print("10. " ..Num10)
- term.setTextColor(colors.white) elseif
- status10 == "cancel" then
- term.setTextColor(colors.red)
- print("10. " ..Num10)
- term.setTextColor(colors.white) else
- term.setTextColor(colors.white)
- print("10. " ..Num10)
- end
- term.setBackgroundColor(32768)
- lineChange = listLine
- listLine = 0
- end
- function changeNum()
- rednet.send(rID, username, TDList)
- rednet.send(rID, numChange, TDList)
- rednet.send(rID, newNum, TDList)
- rednet.send(rID, status, TDList)
- end
- function editNum()
- term.setCursorPos(1,14)
- term.clearLine()
- term.setCursorPos(1,15)
- term.clearLine()
- term.setCursorPos(1,16)
- term.clearLine()
- term.setCursorPos(1,17)
- term.clearLine()
- term.setCursorPos(1,18)
- term.clearLine()
- term.setCursorPos(1,16)
- status = "normal"
- numChange = "change"..lineChange
- write("Edit: ")
- newNum = read()
- lenght = string.len(newNum)
- if lenght>23 then
- term.clearLine()
- write("Max lenght is 23")
- sleep(1)
- editNum()
- end
- changeNum()
- end
- function changeStatus()
- numChange = "change"..lineChange
- if lineChange == 1 then
- newNum = Num1
- elseif lineChange == 2 then
- newNum = Num2
- elseif lineChange == 3 then
- newNum = Num3
- elseif lineChange == 4 then
- newNum = Num4
- elseif lineChange == 5 then
- newNum = Num5
- elseif lineChange == 6 then
- newNum = Num6
- elseif lineChange == 7 then
- newNum = Num7
- elseif lineChange == 8 then
- newNum = Num8
- elseif lineChange == 9 then
- newNum = Num9
- elseif lineChange == 10 then
- newNum = Num10
- end
- changeNum()
- end
- function voting()
- clear()
- text = "The voting app is still WIP"
- line = 0
- printCentered()
- sleep(2)
- pressedButton = nil
- interface()
- return
- end
- function events()
- clear()
- text = "The events app is still WIP"
- line = 0
- printCentered()
- sleep(2)
- pressedButton = nil
- interface()
- end
- function help()
- clear()
- print("Please click on a topic you want help with")
- print("1. General")
- print("2. Mail")
- print("3. To do")
- print("4. Door")
- print("5. Compass")
- print("6. Voting")
- print("7. Events")
- print("8. Command")
- returnButton()
- while true do
- getClickPos()
- returnButton()
- if linePos == 3 then
- helpWith = 1
- elseif linePos == 4 then
- helpWith = 2
- elseif linePos == 5 then
- helpWith = 3
- elseif linePos == 6 then
- helpWith = 4
- elseif linePos == 7 then
- helpWith = 5
- elseif linePos == 8 then
- helpWith = 6
- elseif linePos == 9 then
- helpWith = 7
- elseif linePos == 10 then
- helpWith = 8
- elseif pressedButton == 7 then
- pressedButton = nil
- interface2()
- return
- end
- if helpWith == 1 then
- helpGeneral()
- elseif helpWith == 2 then
- end
- end
- pressedButton = nil
- interface2()
- end
- function helpGeneral()
- clear()
- print("1. Interface")
- print("2. Requirements")
- print("3. Credits")
- returnButton()
- while true do
- getClickPos()
- returnButton()
- if linePos == 1 then
- clear()
- 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.")
- returnButton()
- while true do
- getClickPos()
- if pressedButton == 7 then
- helpGeneral()
- end
- end
- elseif linePos == 2 then
- clear()
- 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")
- returnButton()
- while true do
- getClickPos()
- if pressedButton == 7 then
- helpGeneral()
- end
- end
- elseif pressedButton == 7 then
- pressedButton = nil
- help()
- return
- end
- end
- end
- -------------------------------------------------
- run = true
- if pocket then
- initialize()
- lockedScreen()
- while run == true do
- interface()
- end
- else
- print("No hackers allowed lol")
- sleep(1)
- os.shutdown()
- end
Add Comment
Please, Sign In to add comment