Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- tables to do add on functions on
- local table = table -- orig table functions
- local term = term -- orig term functions
- -- table add on functions
- table.find = function(tbl, value)
- local index
- for i,v in next, tbl do
- if type(i)=="number" then
- if v == value then
- index = i
- break
- end
- end
- end
- return index
- end
- table.pack = function(...)
- local args = {...}
- local rettbl = {}
- for i,v in next, args do
- table.insert(rettbl, v)
- end
- return rettbl
- end
- string.split = function(str, splitchar)
- local ret = {""}
- local curtest = ""
- str:gsub(".", function(char)
- if char==string.sub(splitchar,#curtest+1,#curtest+1) then
- curtest = curtest..char
- if curtest==splitchar then
- ret[#ret+1]=""
- curtest = ""
- end
- else
- ret[#ret] = ret[#ret]..char
- end
- end)
- return ret
- end
- -- general functions
- local getNames = function()
- return peripheral.getNames()
- end
- local getWirelessModems = function()
- local modems = {}
- local names = getNames()
- for i,v in next, names do
- if table.find(peripheral.getMethods(v), "isWireless") ~= nil then
- if peripheral.wrap(v).isWireless() == true then
- table.insert(modems, v)
- end
- end
- end
- return modems
- end
- local getPrinters = function()
- local modems = {}
- local names = getNames()
- for i,v in next, names do
- if string.find(v:lower(),"printer") then
- table.insert(modems, v)
- end
- end
- return modems
- end
- local openModems = function()
- local modems = getWirelessModems()
- for i,v in next, modems do
- rednet.open(v)
- end
- end
- openModems()
- local roundNumber = function(num)
- local ret = num
- local fullNum = math.floor(num)
- if num-fullNum % 1 ~= 0 then
- if num-fullNum % 1 >= 0.5 then
- ret = fullNum+1
- elseif num-fullNum % 1 < 0.5 then
- ret = fullNum
- end
- end
- return ret
- end
- local round = function(number, ...)
- local args = {...}
- local retNum, retDiff = 0, math.huge
- for i,v in next, args do
- if number >= 0 then
- if math.abs(number-v) < retDiff then
- retNum = v
- retDiff = math.abs(number-v)
- end
- elseif number <= 0 then
- if number+v < retDiff then
- retNum = v
- retDiff = number+v
- end
- end
- end
- return retNum, retDiff
- end
- local getSimilarString = function(str, ...)
- local searchtbl = {}
- local args = {...}
- for i,v in next, args do
- if table.find(searchtbl, v) == nil then
- table.insert(searchtbl, v)
- end
- end
- local curNUM, curSTR = 0, {}
- local similarChars = 0
- local sc = {}
- local numTBL = {}
- for i,v in next, searchtbl do
- sc[v]=0
- end
- local curCHAR = 0
- str:gsub(".", function(char)
- curCHAR = curCHAR+1
- for i,v in next, searchtbl do
- if v:sub(curCHAR,curCHAR):lower() == char:lower() then
- sc[v] = sc[v]+1
- end
- end
- end)
- for i,v in next, sc do
- if v>curNUM then
- curNUM = v
- end
- end
- for i,v in next, sc do
- if v==curNUM then
- table.insert(curSTR, tostring(i))
- end
- end
- return curSTR
- end
- local getColors = function()
- local retTBL = {}
- local usedColors = {}
- for i,v in next, colors do
- if type(v) == "number" and usedColors[i:lower()] == nil then
- table.insert(retTBL, {["CCode"]=v, ["CName"]=i})
- usedColors[i:lower()]=true
- end
- end
- return retTBL
- end
- local getColor = function(color)
- local clrTBL = getColors()
- for i,v in next, clrTBL do
- end
- local names, codes = {}, {}
- for i,v in next, clrTBL do
- table.insert(names, v.CName)
- table.insert(codes, v.CCode)
- end
- if type(color) == "number" then
- local closestNumber = round(color, unpack(codes))
- return closestNumber
- elseif type(color) == "string" then
- local simstr = getSimilarString(color, unpack(names))
- if #simstr>1 then
- return colors[simstr[math.random(1, #simstr)]]
- elseif #simstr<1 then
- return colors[names[math.random(1, #names)]]
- elseif #simstr==1 then
- return colors[simstr[1]]
- end
- end
- end
- local setBackgroundColor = function(color)
- local clr = getColor(color)
- term.setBackgroundColor(clr)
- end
- local setTextColor = function(color)
- local clr = getColor(color)
- term.setTextColor(clr)
- end
- local draw = {}
- draw.fillPixel = function(x, y, color)
- setBackgroundColor(color)
- term.setCursorPos(x,y)
- term.write(" ")
- end
- draw.fillSquare = function(startX, startY, endX, endY, color)
- setBackgroundColor(color)
- local x, y = term.getSize()
- for k=math.min(startY, endY), math.max(startY, endY) do
- term.setCursorPos(math.min(startX, endX), k)
- write(string.rep(" ", math.max(startX, endX)-math.min(startX, endX)))
- end
- end
- draw.createText = function(X, Y, text, textcolor, backgroundcolor)
- setTextColor(textcolor)
- setBackgroundColor(backgroundcolor)
- local posX = X-#text/2
- term.setCursorPos(posX, Y)
- term.write(text)
- end
- draw.createNormalText = function(x, y, text, textcolor, backgroundcolor)
- setTextColor(textcolor)
- setBackgroundColor(backgroundcolor)
- term.setCursorPos(x,y)
- term.write(text)
- end
- draw.createColoredText = function(x, y, text, backgroundcolor)
- local colorCodePrefix = "&"
- local colorCodes = {
- ["0"]=colors.white,
- ["1"]=colors.orange,
- ["2"]=colors.magenta,
- ["3"]=colors.lightBlue,
- ["4"]=colors.yellow,
- ["5"]=colors.lime,
- ["6"]=colors.pink,
- ["7"]=colors.gray,
- ["8"]=colors.lightGray,
- ["9"]=colors.cyan,
- ["a"]=colors.purple,
- ["b"]=colors.blue,
- ["c"]=colors.brown,
- ["d"]=colors.green,
- ["e"]=colors.red,
- ["f"]=colors.black,
- }
- setBackgroundColor(backgroundcolor)
- term.setCursorPos(x, y)
- local curSTR = ""text:gsub(".", function(str)
- local ret = ""
- if str == colorCodePrefix then
- curSTR = colorCodePrefix
- elseif colorCodes[str] ~= nil then
- if curSTR == colorCodePrefix then
- term.setTextColor(colorCodes[str])
- curSTR = ""
- else
- write(str)
- end
- else
- curSTR = ""
- write(str)
- end
- end)
- end
- draw.fillBackground = function(color)
- local x, y = term.getSize()
- setBackgroundColor(color)
- for k=1,y do
- term.setCursorPos(1, k)
- write(string.rep(" ", x))
- end
- end
- draw.fillLine = function(y, color)
- local sizex, sizey = term.getSize()
- setBackgroundColor(color)
- term.setCursorPos(1,y)
- write(string.rep(" ", sizex))
- end
- -- GUI making
- local zoostatus = true
- local generateExpirationDay = function(length)
- local daytoadd = 0
- if length == "Forever" then
- daytoadd = math.huge
- elseif length == "Month" then
- daytoadd = 2160
- elseif length == "Day" then
- daytoadd = 72
- end
- local curDay = os.day()
- local time = os.time()
- return {curDay+daytoadd, time}
- end
- -- Database --
- if fs.isDir("saves") == false then
- fs.makeDir("saves")
- end
- if fs.exists("saves/IDs") == false then
- local file = fs.open("saves/IDs", "w")
- file.writeLine("090={[\"ExpirationDay\"]={math.huge,0}, [\"Disabled\"]=false}")
- file.close()
- end
- local decode = function(line)
- local ID = line:gmatch("%d*")()
- local Disabled = string.gmatch(line, "%[\"Disabled\"%]=\"%a*\"")()
- local Days = string.gmatch(line, "[{](%d*)[,]")()
- local Time = string.gmatch(line, "[,](%d*)[}]")()
- dataTable={["ExpirationDay"]={tonumber(Days), tonumber(Time)}, ["Disabled"]=Disabled}
- return {ID, dataTable}
- end
- local getIDs = function()
- local tbl = {}
- local file = fs.open("saves/IDs", "r")
- local line = file.readLine()
- repeat
- if line ~= nil or line ~="" then
- local split = decode(line)
- tbl[split[1]]=split[2]
- else
- end
- line = file.readLine()
- until line==nil
- file.close()
- return tbl
- end
- local IDs = getIDs()
- local addCode = function(code, tbl)
- local file = fs.open("saves/IDs", "a")
- local str = tostring(code).."={".."[\"ExpirationDay\"]={"..tbl.ExpirationDay[1]..","..tbl.ExpirationDay[2].."},".."[\"Disabled\"]=\""..tbl.Disabled.."\"}"
- file.writeLine(str)
- file.close()
- IDs = getIDs()
- end
- local odds = {
- ["1"]={1,1},
- ["2"]={1,100},
- ["3"]={100,300},
- ["4"]={300,1000},
- ["5"]={600, 2500},
- ["6"]={800, 3000}
- }
- local generateIDlength = function()
- local ret = 0
- local num = math.random(1,3000)
- for i,v in next, odds do
- if num>v[1] and num<=v[2] then
- ret = i
- break
- end
- end
- return ret
- end
- local IDgenerator = function()
- local cur = string.rep("#", generateIDlength())
- local id = cur:gsub(".", function(str)
- return string.char(math.random(48, 57))
- end)
- return id
- end
- local generateID = function()
- local id = IDgenerator()
- for i=1,20 do
- if IDs[tostring(id)] ~= nil then
- id = IDgenerator()
- else
- break
- end
- end
- if IDs[tostring(id)]~=nil then
- return "failed"
- else
- return id
- end
- end
- local createNewID = function(length)
- local id = generateID()
- if id == "failed" then
- return "failed"
- else
- addCode(tostring(id), {
- ["ExpirationDay"]=generateExpirationDay(length),
- ["Disabled"]="false"
- })
- return id
- end
- end
- local checkValidID = function(id)
- local returnMessage = ""
- if IDs[tostring(id)] == nil then
- returnMessage="false"
- else
- local tbl = IDs[tostring(id)]
- local day = os.day()
- local time = os.time()
- print(tbl[1])
- if tbl["Disabled"]==true then
- returnMessage="false"
- else
- if day>=tbl["ExpirationDay"][1] then
- returnMessage = "false"
- else
- returnMessage = "true"
- end
- end
- end
- return returnMessage
- end
- local getTimeLeft = function(id)
- local ret = "nil"
- if IDs[tostring(id)] == nil then
- else
- local tbl = IDs[tostring(id)]
- local expiring = tbl.ExpirationDay
- ret = tostring(((expiring[1]-os.day())*20)/60).." - Hours"
- end
- return ret
- end
- local blacklistID = function(id)
- if IDs[tostring(id)] ~= nil then
- local tbl = IDs[id]
- IDs[id]["Disabled"]=true
- end
- end
- local dayInMonths = {
- ["january"]=31,
- ["february"]=28,
- ["mars"]=31,
- ["april"]=30,
- ["may"]=31,
- ["june"]=30,
- ["july"]=31,
- ["august"]=31,
- ["september"]=30,
- ["october"]=31,
- ["november"]=30,
- ["december"]=31
- }
- local monthOrder = {
- ["january"]=1,
- ["february"]=2,
- ["mars"]=3,
- ["april"]=4,
- ["may"]=5,
- ["june"]=6,
- ["july"]=7,
- ["august"]=8,
- ["september"]=9,
- ["october"]=10,
- ["november"]=11,
- ["december"]=12
- }
- local getRealTime = function()
- local api = "http://worldtimeapi.org/api/timezone/Etc/GMT.txt"
- local httpget = http.get(api)
- local readAll = httpget.readAll()
- local date = readAll:gmatch("datetime: %d*-%d*-%d*")()
- local realDate = date:gsub(".", function(str)
- if str:match("%d") or str:match("-") then
- return str
- else
- return ""
- end
- end)
- local time = readAll:gmatch("%d*:%d*:%d*")()
- return {realDate, time}
- end
- local getTimeOneDayOffset = function(tbl)
- local curtime = tbl[2]
- local date = tbl[1]
- local ret = {}
- local newDate = {
- ["year"]="",
- ["month"]="",
- ["day"]=""
- }
- local split = string.split(date,"-")
- for i,v in next, split do
- if i==1 then
- newDate.year = v
- elseif i==2 then
- newDate.month = v
- elseif i==3 then
- newDate.day = v
- end
- end
- local currentMonth = ""
- for i,v in next, monthOrder do
- if v==tonumber(newDate.month) then
- currentMonth = i
- end
- end
- local daysinthismonth = dayInMonths[currentMonth]
- if tonumber(newDate.day)+1>daysinthismonth then
- if newDate.month=="12" then
- newDate.year = tonumber(newDate.year)+1
- newDate.month = "01"
- newDate.day = "01"
- else
- local nextMonthNumber = monthOrder[currentMonth]+1
- local nextMonth = ""
- for i,v in next, monthOrder do
- if v==nextMonthNumber then
- nextMonth=i
- end
- end
- newDate.day = "01"
- if #tostring(nextMonthNumber)==1 then
- newDate.month="0"..tostring(nextMonthNumber)
- else
- newDate.month=tostring(nextMonthNumber)
- end
- end
- else
- local newday = tonumber(newDate.day)+1
- if #tostring(newday) == 1 then
- newday = "0"..tostring(newday)
- else
- newday = tostring(newday)
- end
- newDate.day = newday
- end
- ret[1] = tostring(newDate.year).."-"..tostring(newDate.month).."-"..tostring(newDate.day)
- ret[2] = tbl[2]
- return ret
- end
- local printInfo = function(id)
- local printers = getPrinters()
- if #printers >= 1 then
- local printer = printers[1]
- if peripheral.wrap(printer).getPaperLevel() > 0 and peripheral.wrap(printer).getInkLevel() > 0 then
- local pos = 1
- local str = ""
- local tbl = IDs[id]
- if tbl ~= nil then
- peripheral.wrap(printer).newPage()
- peripheral.wrap(printer).write(str)
- local valid = checkValidID(id)
- local time = getTimeLeft(id)
- pos = pos+2
- peripheral.wrap(printer).setCursorPos(1,pos)
- peripheral.wrap(printer).write("Expires in "..getTimeLeft(id))
- pos=pos+2
- peripheral.wrap(printer).setCursorPos(1,pos)
- peripheral.wrap(printer).write("Your ID is "..id)
- pos=pos+1
- peripheral.wrap(printer).setCursorPos(1,pos)
- peripheral.wrap(printer).write("EXPIRES: ")
- local expirationdate = getTimeOneDayOffset(getRealTime())
- pos=pos+1
- peripheral.wrap(printer).setCursorPos(1,pos)
- peripheral.wrap(printer).write(expirationdate[1])
- pos=pos+1
- peripheral.wrap(printer).setCursorPos(1,pos)
- peripheral.wrap(printer).write(expirationdate[2].." GMT+1")
- pos=pos+2
- peripheral.wrap(printer).setCursorPos(1,pos)
- peripheral.wrap(printer).write("ID is valid: "..valid)
- pos=pos+2
- peripheral.wrap(printer).setCursorPos(1,pos)
- peripheral.wrap(printer).write("Welcome to the zoo :)")
- peripheral.wrap(printer).endPage()
- else
- end
- end
- end
- end
- local isTyping = false
- local onEnter = function()
- end
- local typingtext = ""
- local typingX, typingY = 0, 0
- local maxTypingLetters = 0
- local typingColor = colors.white
- local currentGUI = "main"
- local loadinggui = false
- local guitbl = {}
- local checkvalididinfo = {}
- local checkvalidcurrentid = ""
- local isvalid = "nil"
- local validexpiratondate = "nil"
- local timeleft = "nil"
- local checkvalidinfomt = {
- __newindex = function(table, key, value)
- if key=="CurrentID" then
- checkvalidcurrentid = value
- guitbl["switchgui"]="checkidvalid"
- return nil
- elseif key=="checkvalid" then
- isvalid=value
- guitbl["switchgui"]="checkidvalid"
- elseif key=="timeleft" then
- timeleft=value
- guitbl["switchgui"]="checkidvalid"
- end
- return nil
- end
- }
- setmetatable(checkvalididinfo, checkvalidinfomt)
- local generateidNewID = "nil"
- local generateidinfo = {}
- local generateidinfomt = {
- __newindex = function(table, key, value)
- if key=="newid" then
- generateidNewID = value
- guitbl["switchgui"]="generateid"
- end
- end
- }
- setmetatable(generateidinfo, generateidinfomt)
- local checkcancelcurrentid = "nil"
- local checkcancelidinfo = {}
- local checkcancelidinfomt = {
- __newindex = function(table, key, value)
- if key=="CurrentID" then
- checkcancelcurrentid = value
- guitbl["switchgui"]="cancelid"
- end
- end
- }
- setmetatable(checkcancelidinfo, checkcancelidinfomt)
- local zootbl = {}
- local zoomt = {
- __newindex = function(self, key, value)
- if key == "closezoo" then
- zoostatus = false
- guitbl["switchgui"]="zoo"
- elseif key == "openzoo" then
- zoostatus = true
- guitbl["switchgui"]="zoo"
- end
- end
- }
- setmetatable(zootbl, zoomt)
- local guiDrawing = {
- ["main"]=function()
- loadinggui = true
- draw.fillBackground("magenta")
- draw.fillLine(1, "pink")
- local sizeX, sizeY = term.getSize()
- draw.createColoredText(1, 1, "&8[&0Main Menu&8]", "pink")
- draw.createColoredText(#"[Main Menu]"+2, 1, "&8[&0ID Menu&8]", "pink")
- draw.createColoredText(#"[Main Menu]"+#"[ID Menu]"+3, 1, "&8[&0Zoo&8]", "pink")
- draw.createText((sizeX)/2, (sizeY-1)/2+0, "Zoo Admin Panel", "white", "magenta")
- draw.createText((sizeX)/2, (sizeY-1)/2+1, "Controls the whole Zoo!", "white", "magenta")
- draw.createText((sizeX)/2, (sizeY-1)/2+2, "Computer #"..os.getComputerID(), "white", "magenta")
- loadinggui = false
- end,
- ["idmenu"]=function()
- loadinggui = true
- draw.fillBackground("magenta")
- draw.fillLine(1, "pink")
- local sizeX, sizeY = term.getSize()
- draw.createColoredText(1, 1, "&8[&0Main Menu&8]", "pink")
- draw.createColoredText(#"[Main Menu]"+2, 1, "&8[&0ID Menu&8]", "pink")
- draw.createColoredText(#"[Main Menu]"+#"[ID Menu]"+3, 1, "&8[&0Zoo&8]", "pink")
- draw.createText((sizeX)/2, 2, "ID Admin Panel", "white", "magenta")
- draw.createNormalText((sizeX/2)-10, sizeY/2, "Generate ID"..string.rep(" ",21-#"Generate ID"), "white", "pink")
- draw.createNormalText((sizeX/2)-10, sizeY/2+2, "Check Valid ID"..string.rep(" ",21-#"Check Valid ID"), "white", "pink")
- draw.createNormalText((sizeX/2)-10, sizeY/2+4, "Cancel ID"..string.rep(" ",21-#"Cancel ID"), "white", "pink")
- loadinggui = false
- end,
- ["checkidvalid"]=function()
- loadinggui = true
- draw.fillBackground("magenta")
- draw.fillLine(1, "pink")
- local sizeX, sizeY = term.getSize()
- draw.createColoredText(1, 1, "&8[&0Main Menu&8]", "pink")
- draw.createColoredText(#"[Main Menu]"+2, 1, "&8[&0ID Menu&8]", "pink")
- draw.createColoredText(#"[Main Menu]"+#"[ID Menu]"+3, 1, "&8[&0Zoo&8]", "pink")
- draw.createText((sizeX)/2, 2, "ID Information", "white", "magenta")
- draw.fillSquare(math.floor(sizeX/2)-15, sizeY/2-3, math.ceil(sizeX/2)+15, sizeY/2-3, "pink")
- draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2+2, math.ceil(sizeX/2)+10, sizeY/2+2, "pink")
- draw.createText(math.floor(sizeX/2), sizeY/2+2, "Check Is Valid", "white", "pink")
- draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2, math.ceil(sizeX/2)+10, sizeY/2, "pink")
- draw.createText(math.floor(sizeX/2), sizeY/2-1, "Current ID", "white", "magenta")
- draw.createText(math.floor(sizeX/2), sizeY/2, checkvalidcurrentid:sub(1,21), "white", "pink")
- draw.createText(math.floor(sizeX/2), sizeY/2+4, "Is Valid", "white", "magenta")
- draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2+5, math.ceil(sizeX/2)+10, sizeY/2+5, "pink")
- draw.createText(math.floor(sizeX/2), sizeY/2+5, isvalid, "white", "pink")
- draw.createText(math.floor(sizeX/2), sizeY/2+7, "Time Left", "white", "magenta")
- draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2+8, math.ceil(sizeX/2)+10, sizeY/2+8, "pink")
- draw.createText(math.floor(sizeX/2), sizeY/2+8, timeleft, "white", "pink")
- loadinggui = false
- end,
- ["generateid"]=function()
- loadinggui = true
- draw.fillBackground("magenta")
- draw.fillLine(1, "pink")
- local sizeX, sizeY = term.getSize()
- draw.createColoredText(1, 1, "&8[&0Main Menu&8]", "pink")
- draw.createColoredText(#"[Main Menu]"+2, 1, "&8[&0ID Menu&8]", "pink")
- draw.createColoredText(#"[Main Menu]"+#"[ID Menu]"+3, 1, "&8[&0Zoo&8]", "pink")
- draw.createText((sizeX)/2, 2, "Generate ID", "white", "magenta")
- draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2-3, math.ceil(sizeX/2)+10, sizeY/2-3, "pink")
- draw.createText(sizeX/2, sizeY/2-3, "Generate ID", "white", "pink")
- draw.createText(sizeX/2, sizeY/2+1, "New Generated ID", "white", "magenta")
- draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2+2, math.ceil(sizeX/2)+10, sizeY/2+2, "pink")
- draw.createText(sizeX/2, sizeY/2+2, tostring(generateidNewID), "white", "pink")
- draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2+4, math.ceil(sizeX/2)+10, sizeY/2+4, "pink")
- draw.createText(sizeX/2, sizeY/2+4, tostring("Print Information"), "white", "pink")
- loadinggui = false
- end,
- ["cancelid"]=function()
- loadinggui = true
- draw.fillBackground("magenta")
- draw.fillLine(1, "pink")
- local sizeX, sizeY = term.getSize()
- draw.createColoredText(1, 1, "&8[&0Main Menu&8]", "pink")
- draw.createColoredText(#"[Main Menu]"+2, 1, "&8[&0ID Menu&8]", "pink")
- draw.createColoredText(#"[Main Menu]"+#"[ID Menu]"+3, 1, "&8[&0Zoo&8]", "pink")
- draw.createText((sizeX)/2, 2, "Cancel IDs", "white", "magenta")
- draw.fillSquare(math.floor(sizeX/2)-15, sizeY/2-3, math.ceil(sizeX/2)+15, sizeY/2-3, "pink")
- draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2, math.ceil(sizeX/2)+10, sizeY/2, "pink")
- draw.createText(math.floor(sizeX/2), sizeY/2-1, "Current ID", "white", "magenta")
- draw.createText(math.floor(sizeX/2), sizeY/2, checkcancelcurrentid:sub(1,21), "white", "pink")
- draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2+2, math.ceil(sizeX/2)+10, sizeY/2+2, "pink")
- draw.createText(sizeX/2, sizeY/2+2, tostring("Cancel ID"), "white", "pink")
- loadinggui = false
- end,
- ["zoo"]=function()
- loadinggui = true
- draw.fillBackground("magenta")
- draw.fillLine(1, "pink")
- local sizeX, sizeY = term.getSize()
- draw.createColoredText(1, 1, "&8[&0Main Menu&8]", "pink")
- draw.createColoredText(#"[Main Menu]"+2, 1, "&8[&0ID Menu&8]", "pink")
- draw.createColoredText(#"[Main Menu]"+#"[ID Menu]"+3, 1, "&8[&0Zoo&8]", "pink")
- draw.createText((sizeX)/2, 2, "Zoo Admin Panel", "white", "magenta")
- draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2, math.ceil(sizeX/2)+10, sizeY/2, "pink")
- draw.createText(sizeX/2, sizeY/2, tostring("Close Down Zoo"), "white", "pink")
- draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2+2, math.ceil(sizeX/2)+10, sizeY/2+2, "pink")
- draw.createText(sizeX/2, sizeY/2+2, tostring("Open Up Zoo"), "white", "pink")
- draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2+5, math.ceil(sizeX/2)+10, sizeY/2+5, "pink")
- draw.createText(sizeX/2, sizeY/2+5, tostring((function() if zoostatus == true then return "Open" else return "Closed" end end)()), "white", "pink")
- loadinggui = false
- end
- }
- local drawGUI = function()
- if guiDrawing[currentGUI] ~= nil then
- guiDrawing[currentGUI]()
- end
- end
- local guimt = {
- __newindex = function(table, key, value)
- if key == "switchgui" and loadinggui == false then
- typingtext=""
- isTyping=false
- currentGUI = value
- drawGUI()
- end
- end
- }
- setmetatable(guitbl, guimt)
- local termSizeX, termSizeY = term.getSize()
- local buttons = {
- ["main"]={
- ["mainmenu"]={
- ["posX"]=1,
- ["posY"]=1,
- ["sizeX"]=11,
- ["sizeY"]=1,
- ["func"]=function()
- guitbl["switchgui"]="main"
- end
- },
- ["idmenu"]={
- ["posX"]=13,
- ["posY"]=1,
- ["sizeX"]=9,
- ["sizeY"]=1,
- ["func"]=function()
- guitbl["switchgui"]="idmenu"
- end
- },
- ["zoo"]={
- ["posX"]=22,
- ["posY"]=1,
- ["sizeX"]=5,
- ["sizeY"]=1,
- ["func"]=function()
- guitbl["switchgui"]="zoo"
- end
- }
- },
- ["idmenu"]={
- ["mainmenu"]={
- ["posX"]=1,
- ["posY"]=1,
- ["sizeX"]=11,
- ["sizeY"]=1,
- ["func"]=function()
- guitbl["switchgui"]="main"
- end
- },
- ["idmenu"]={
- ["posX"]=13,
- ["posY"]=1,
- ["sizeX"]=9,
- ["sizeY"]=1,
- ["func"]=function()
- guitbl["switchgui"]="idmenu"
- end
- },
- ["zoo"]={
- ["posX"]=22,
- ["posY"]=1,
- ["sizeX"]=5,
- ["sizeY"]=1,
- ["func"]=function()
- guitbl["switchgui"]="zoo"
- end
- },
- ["generateid"]={
- ["posX"]=(termSizeX/2)-10,
- ["posY"]=(termSizeY/2),
- ["sizeX"]=21,
- ["sizeY"]=1,
- ["func"]=function()
- guitbl["switchgui"]="generateid"
- end
- },
- ["checkvalidid"]={
- ["posX"]=(termSizeX/2)-10,
- ["posY"]=(termSizeY/2)+2,
- ["sizeX"]=21,
- ["sizeY"]=1,
- ["func"]=function()
- guitbl["switchgui"]="checkidvalid"
- end
- },
- ["cancelid"]={
- ["posX"]=(termSizeX/2)-10,
- ["posY"]=(termSizeY/2)+4,
- ["sizeX"]=21,
- ["sizeY"]=1,
- ["func"]=function()
- guitbl["switchgui"]="cancelid"
- end
- }
- },
- ["zoo"]={
- ["mainmenu"]={
- ["posX"]=1,
- ["posY"]=1,
- ["sizeX"]=11,
- ["sizeY"]=1,
- ["func"]=function()
- guitbl["switchgui"]="main"
- end
- },
- ["idmenu"]={
- ["posX"]=13,
- ["posY"]=1,
- ["sizeX"]=9,
- ["sizeY"]=1,
- ["func"]=function()
- guitbl["switchgui"]="idmenu"
- end
- },
- ["zoo"]={
- ["posX"]=22,
- ["posY"]=1,
- ["sizeX"]=5,
- ["sizeY"]=1,
- ["func"]=function()
- guitbl["switchgui"]="zoo"
- end
- },
- ["closezoo"]={
- ["posX"]=math.floor(termSizeX/2)-10,
- ["posY"]=termSizeY/2,
- ["sizeX"]=21,
- ["sizeY"]=1,
- ["func"]=function()
- zootbl["closezoo"]=false
- end
- },
- ["openzoo"]={
- ["posX"]=math.floor(termSizeX/2)-10,
- ["posY"]=termSizeY/2+2,
- ["sizeX"]=21,
- ["sizeY"]=1,
- ["func"]=function()
- zootbl["openzoo"]=true
- end
- }
- },
- ["checkidvalid"]={
- ["mainmenu"]={
- ["posX"]=1,
- ["posY"]=1,
- ["sizeX"]=11,
- ["sizeY"]=1,
- ["func"]=function()
- guitbl["switchgui"]="main"
- end
- },
- ["idmenu"]={
- ["posX"]=13,
- ["posY"]=1,
- ["sizeX"]=9,
- ["sizeY"]=1,
- ["func"]=function()
- guitbl["switchgui"]="idmenu"
- end
- },
- ["zoo"]={
- ["posX"]=22,
- ["posY"]=1,
- ["sizeX"]=5,
- ["sizeY"]=1,
- ["func"]=function()
- guitbl["switchgui"]="zoo"
- end
- },
- ["searchbar"]={
- ["posX"]=math.floor(termSizeX/2)-15,
- ["posY"]=termSizeY/2-3,
- ["sizeX"]=31,
- ["sizeY"]=1,
- ["func"]=function()
- typingX = math.floor(termSizeX/2)-15
- typingY = termSizeY/2-3
- typingColor = colors.pink
- maxTypingLetters = 31
- isTyping = true
- onEnter = function(text)
- checkvalididinfo["CurrentID"]=text
- end
- end
- },
- ["validbutton"]={
- ["posX"]=math.floor(termSizeX/2)-10,
- ["posY"]=math.floor(termSizeY/2)+2,
- ["sizeX"]=21,
- ["sizeY"]=1,
- ["func"]=function()
- checkvalididinfo["checkvalid"]=checkValidID(checkvalidcurrentid)
- checkvalididinfo["timeleft"]=getTimeLeft(checkvalidcurrentid)
- end
- },
- },
- ["generateid"]={
- ["generateidbutton"]={
- ["posX"]=math.floor(termSizeX/2)-10,
- ["posY"]=termSizeY/2-3,
- ["sizeX"]=21,
- ["sizeY"]=1,
- ["func"]=function()
- generateidinfo["newid"]=createNewID("Day")
- end
- },
- ["mainmenu"]={
- ["posX"]=1,
- ["posY"]=1,
- ["sizeX"]=11,
- ["sizeY"]=1,
- ["func"]=function()
- guitbl["switchgui"]="main"
- end
- },
- ["idmenu"]={
- ["posX"]=13,
- ["posY"]=1,
- ["sizeX"]=9,
- ["sizeY"]=1,
- ["func"]=function()
- guitbl["switchgui"]="idmenu"
- end
- },
- ["zoo"]={
- ["posX"]=22,
- ["posY"]=1,
- ["sizeX"]=5,
- ["sizeY"]=1,
- ["func"]=function()
- guitbl["switchgui"]="zoo"
- end
- },
- ["printinformation"]={
- ["posX"]=math.floor(termSizeX/2)-10,
- ["posY"]=termSizeY/2+4,
- ["sizeX"]=21,
- ["sizeY"]=1,
- ["func"]=function()
- if generateidNewID ~= "nil" then
- printInfo(generateidNewID)
- end
- end
- }
- },
- ["cancelid"]={
- ["mainmenu"]={
- ["posX"]=1,
- ["posY"]=1,
- ["sizeX"]=11,
- ["sizeY"]=1,
- ["func"]=function()
- guitbl["switchgui"]="main"
- end
- },
- ["idmenu"]={
- ["posX"]=13,
- ["posY"]=1,
- ["sizeX"]=9,
- ["sizeY"]=1,
- ["func"]=function()
- guitbl["switchgui"]="idmenu"
- end
- },
- ["zoo"]={
- ["posX"]=22,
- ["posY"]=1,
- ["sizeX"]=5,
- ["sizeY"]=1,
- ["func"]=function()
- guitbl["switchgui"]="zoo"
- end
- },
- ["search"]={
- ["posX"]=math.floor(termSizeX/2-15),
- ["posY"]=termSizeY/2-3,
- ["sizeX"]=31,
- ["sizeY"]=1,
- ["func"]=function()
- typingX = math.floor(termSizeX/2)-15
- typingY = termSizeY/2-3
- typingColor = colors.pink
- maxTypingLetters = 31
- isTyping = true
- onEnter = function(text)
- checkcancelidinfo["CurrentID"]=text
- end
- end
- },
- ["cancelid"]={
- ["posX"]=math.floor(termSizeX/2)-10,
- ["posY"]=termSizeY/2+2,
- ["sizeX"]=21,
- ["sizeY"]=2,
- ["func"]=function()
- if checkcancelcurrentid ~= "nil" then
- blacklistID(checkcancelcurrentid)
- end
- end
- }
- }
- }
- local updateText = function()
- draw.fillSquare(typingX, typingY, typingX+maxTypingLetters, typingY, typingColor)
- typingtext=typingtext:sub(1,maxTypingLetters)
- term.setCursorPos(typingX, typingY)
- write(typingtext)
- end
- guitbl["switchgui"]="main"
- local onButton = function(x, y)
- if buttons[tostring(currentGUI)] ~= nil then
- for i,v in next, buttons[currentGUI] do
- if x>=math.floor(v.posX) and x<=math.floor(v.posX+(v.sizeX-1)) then
- if y>=math.floor(v.posY) and y<=math.floor(v.posY+(v.sizeY-1)) then
- v.func()
- break
- else
- isTyping=false
- end
- else
- isTyping=false
- end
- end
- end
- end
- local eventloop = function()
- while true do
- local event, a1, a2, a3 = os.pullEvent()
- if event == "mouse_click" then
- if a1 == 1 then
- onButton(a2, a3)
- end
- elseif event == "key" then
- if isTyping == true then
- if #keys.getName(a1) == 1 then
- typingtext=typingtext..keys.getName(a1)
- elseif a1>=2 and a1<=10 then
- typingtext=typingtext..tostring(a1-1)
- elseif a1==11 then
- typingtext=typingtext.."0"
- elseif a1==14 then
- typingtext=typingtext:sub(1, #typingtext-1)
- elseif a1==28 then
- elseif a1==57 then
- typingtext=typingtext.." "
- end
- if a1==28 then
- onEnter(typingtext)
- isTyping=false
- typingtext = ""
- updateText()
- else
- updateText()
- end
- end
- if a1==50 then
- error("hey")
- end
- end
- end
- end
- local rednetloop = function()
- while true do
- local id, message, protocol = rednet.receive()
- if message:gmatch("validid_%d+")() then
- local validstatus = checkValidID(message:sub(#"validid_.",#message))
- if validstatus == "true" then
- if zoostatus == false then
- rednet.send(id, "Zoo is closed")
- else
- rednet.send(id, "isvalid_"..message:sub(#"validid_.", #message).."_".."true")
- end
- elseif validstatus == "false" then
- rednet.send(id, "isvalid_"..message:sub(#"validid_.", #message).."_".."false")
- end
- end
- end
- end
- parallel.waitForAny(rednetloop, eventloop)
Add Comment
Please, Sign In to add comment