Advertisement
TeoMessiKing

Untitled

Jul 1st, 2021 (edited)
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.94 KB | None | 0 0
  1. -- tables to do add on functions on
  2.  
  3. local table = table -- orig table functions
  4. local term = term -- orig term functions
  5.  
  6. -- table add on functions
  7.  
  8. table.find = function(tbl, value)
  9. local index
  10. for i,v in next, tbl do
  11. if type(i)=="number" then
  12. if v == value then
  13. index = i
  14. break
  15. end
  16. end
  17. end
  18. return index
  19. end
  20.  
  21.  
  22.  
  23. table.pack = function(...)
  24. local args = {...}
  25. local rettbl = {}
  26. for i,v in next, args do
  27. table.insert(rettbl, v)
  28. end
  29. return rettbl
  30. end
  31.  
  32. string.split = function(str, splitchar)
  33. local ret = {""}
  34. local curtest = ""
  35. str:gsub(".", function(char)
  36. if char==string.sub(splitchar,#curtest+1,#curtest+1) then
  37. curtest = curtest..char
  38. if curtest==splitchar then
  39. ret[#ret+1]=""
  40. curtest = ""
  41. end
  42. else
  43. ret[#ret] = ret[#ret]..char
  44. end
  45. end)
  46. return ret
  47. end
  48.  
  49.  
  50.  
  51. -- general functions
  52.  
  53.  
  54. local getNames = function()
  55. return peripheral.getNames()
  56. end
  57.  
  58. local getWirelessModems = function()
  59. local modems = {}
  60. local names = getNames()
  61. for i,v in next, names do
  62. if table.find(peripheral.getMethods(v), "isWireless") ~= nil then
  63. if peripheral.wrap(v).isWireless() == true then
  64. table.insert(modems, v)
  65. end
  66. end
  67. end
  68. return modems
  69. end
  70.  
  71. local getPrinters = function()
  72. local modems = {}
  73. local names = getNames()
  74. for i,v in next, names do
  75. if string.find(v:lower(),"printer") then
  76. table.insert(modems, v)
  77. end
  78. end
  79. return modems
  80. end
  81.  
  82. local openModems = function()
  83. local modems = getWirelessModems()
  84. for i,v in next, modems do
  85. rednet.open(v)
  86. end
  87. end
  88.  
  89.  
  90.  
  91. openModems()
  92.  
  93. local roundNumber = function(num)
  94. local ret = num
  95. local fullNum = math.floor(num)
  96. if num-fullNum % 1 ~= 0 then
  97. if num-fullNum % 1 >= 0.5 then
  98. ret = fullNum+1
  99. elseif num-fullNum % 1 < 0.5 then
  100. ret = fullNum
  101. end
  102. end
  103. return ret
  104. end
  105.  
  106. local round = function(number, ...)
  107. local args = {...}
  108. local retNum, retDiff = 0, math.huge
  109. for i,v in next, args do
  110. if number >= 0 then
  111. if math.abs(number-v) < retDiff then
  112. retNum = v
  113. retDiff = math.abs(number-v)
  114. end
  115. elseif number <= 0 then
  116. if number+v < retDiff then
  117. retNum = v
  118. retDiff = number+v
  119. end
  120. end
  121. end
  122. return retNum, retDiff
  123. end
  124.  
  125. local getSimilarString = function(str, ...)
  126. local searchtbl = {}
  127. local args = {...}
  128. for i,v in next, args do
  129. if table.find(searchtbl, v) == nil then
  130. table.insert(searchtbl, v)
  131. end
  132. end
  133. local curNUM, curSTR = 0, {}
  134. local similarChars = 0
  135. local sc = {}
  136. local numTBL = {}
  137. for i,v in next, searchtbl do
  138. sc[v]=0
  139. end
  140. local curCHAR = 0
  141. str:gsub(".", function(char)
  142. curCHAR = curCHAR+1
  143. for i,v in next, searchtbl do
  144. if v:sub(curCHAR,curCHAR):lower() == char:lower() then
  145. sc[v] = sc[v]+1
  146. end
  147. end
  148. end)
  149. for i,v in next, sc do
  150. if v>curNUM then
  151. curNUM = v
  152. end
  153. end
  154. for i,v in next, sc do
  155. if v==curNUM then
  156. table.insert(curSTR, tostring(i))
  157. end
  158. end
  159. return curSTR
  160. end
  161.  
  162.  
  163.  
  164. local getColors = function()
  165. local retTBL = {}
  166. local usedColors = {}
  167. for i,v in next, colors do
  168. if type(v) == "number" and usedColors[i:lower()] == nil then
  169. table.insert(retTBL, {["CCode"]=v, ["CName"]=i})
  170. usedColors[i:lower()]=true
  171. end
  172. end
  173. return retTBL
  174. end
  175.  
  176. local getColor = function(color)
  177. local clrTBL = getColors()
  178. for i,v in next, clrTBL do
  179. end
  180. local names, codes = {}, {}
  181. for i,v in next, clrTBL do
  182. table.insert(names, v.CName)
  183. table.insert(codes, v.CCode)
  184. end
  185.  
  186. if type(color) == "number" then
  187. local closestNumber = round(color, unpack(codes))
  188. return closestNumber
  189. elseif type(color) == "string" then
  190. local simstr = getSimilarString(color, unpack(names))
  191. if #simstr>1 then
  192. return colors[simstr[math.random(1, #simstr)]]
  193. elseif #simstr<1 then
  194. return colors[names[math.random(1, #names)]]
  195. elseif #simstr==1 then
  196. return colors[simstr[1]]
  197. end
  198. end
  199. end
  200.  
  201. local setBackgroundColor = function(color)
  202. local clr = getColor(color)
  203. term.setBackgroundColor(clr)
  204. end
  205.  
  206. local setTextColor = function(color)
  207. local clr = getColor(color)
  208. term.setTextColor(clr)
  209. end
  210.  
  211. local draw = {}
  212.  
  213. draw.fillPixel = function(x, y, color)
  214. setBackgroundColor(color)
  215. term.setCursorPos(x,y)
  216. term.write(" ")
  217. end
  218.  
  219. draw.fillSquare = function(startX, startY, endX, endY, color)
  220. setBackgroundColor(color)
  221. local x, y = term.getSize()
  222. for k=math.min(startY, endY), math.max(startY, endY) do
  223. term.setCursorPos(math.min(startX, endX), k)
  224. write(string.rep(" ", math.max(startX, endX)-math.min(startX, endX)))
  225. end
  226. end
  227.  
  228. draw.createText = function(X, Y, text, textcolor, backgroundcolor)
  229. setTextColor(textcolor)
  230. setBackgroundColor(backgroundcolor)
  231. local posX = X-#text/2
  232. term.setCursorPos(posX, Y)
  233. term.write(text)
  234. end
  235.  
  236. draw.createNormalText = function(x, y, text, textcolor, backgroundcolor)
  237. setTextColor(textcolor)
  238. setBackgroundColor(backgroundcolor)
  239. term.setCursorPos(x,y)
  240. term.write(text)
  241. end
  242.  
  243. draw.createColoredText = function(x, y, text, backgroundcolor)
  244. local colorCodePrefix = "&"
  245. local colorCodes = {
  246. ["0"]=colors.white,
  247. ["1"]=colors.orange,
  248. ["2"]=colors.magenta,
  249. ["3"]=colors.lightBlue,
  250. ["4"]=colors.yellow,
  251. ["5"]=colors.lime,
  252. ["6"]=colors.pink,
  253. ["7"]=colors.gray,
  254. ["8"]=colors.lightGray,
  255. ["9"]=colors.cyan,
  256. ["a"]=colors.purple,
  257. ["b"]=colors.blue,
  258. ["c"]=colors.brown,
  259. ["d"]=colors.green,
  260. ["e"]=colors.red,
  261. ["f"]=colors.black,
  262. }
  263. setBackgroundColor(backgroundcolor)
  264. term.setCursorPos(x, y)
  265. local curSTR = ""text:gsub(".", function(str)
  266. local ret = ""
  267. if str == colorCodePrefix then
  268. curSTR = colorCodePrefix
  269. elseif colorCodes[str] ~= nil then
  270. if curSTR == colorCodePrefix then
  271. term.setTextColor(colorCodes[str])
  272. curSTR = ""
  273. else
  274. write(str)
  275. end
  276. else
  277. curSTR = ""
  278. write(str)
  279. end
  280.  
  281. end)
  282. end
  283.  
  284. draw.fillBackground = function(color)
  285. local x, y = term.getSize()
  286. setBackgroundColor(color)
  287. for k=1,y do
  288. term.setCursorPos(1, k)
  289. write(string.rep(" ", x))
  290. end
  291. end
  292.  
  293. draw.fillLine = function(y, color)
  294. local sizex, sizey = term.getSize()
  295. setBackgroundColor(color)
  296. term.setCursorPos(1,y)
  297. write(string.rep(" ", sizex))
  298. end
  299.  
  300. -- GUI making
  301.  
  302. local zoostatus = true
  303.  
  304. local generateExpirationDay = function(length)
  305. local daytoadd = 0
  306. if length == "Forever" then
  307. daytoadd = math.huge
  308. elseif length == "Day" then
  309. daytoadd = 1234
  310. end
  311. local curDay = os.day()
  312. local time = os.time()
  313. return {curDay+daytoadd, time}
  314. end
  315.  
  316. -- Database --
  317.  
  318. if fs.isDir("saves") == false then
  319. fs.makeDir("saves")
  320. end
  321.  
  322. if fs.exists("saves/IDs") == false then
  323. local file = fs.open("saves/IDs", "w")
  324. file.writeLine("090={[\"ExpirationDay\"]={math.huge,0}, [\"Disabled\"]=false}")
  325. file.close()
  326. end
  327.  
  328. local decode = function(line)
  329. local ID = line:gmatch("%d*")()
  330. local Disabled = string.gmatch(line, "%[\"Disabled\"%]=\"%a*\"")()
  331. local Days = string.gmatch(line, "[{](%d*)[,]")()
  332. local Time = string.gmatch(line, "[,](%d*)[}]")()
  333. dataTable={["ExpirationDay"]={tonumber(Days), tonumber(Time)}, ["Disabled"]=Disabled}
  334. return {ID, dataTable}
  335. end
  336.  
  337. local getIDs = function()
  338. local tbl = {}
  339. local file = fs.open("saves/IDs", "r")
  340. local line = file.readLine()
  341. repeat
  342. if line ~= nil or line ~="" then
  343. local split = decode(line)
  344. tbl[split[1]]=split[2]
  345. else
  346. end
  347. line = file.readLine()
  348. until line==nil
  349. file.close()
  350. return tbl
  351. end
  352.  
  353. local IDs = getIDs()
  354.  
  355.  
  356. local addCode = function(code, tbl)
  357. local file = fs.open("saves/IDs", "a")
  358. local str = tostring(code).."={".."[\"ExpirationDay\"]={"..tbl.ExpirationDay[1]..","..tbl.ExpirationDay[2].."},".."[\"Disabled\"]=\""..tbl.Disabled.."\"}"
  359. file.writeLine(str)
  360. file.close()
  361. IDs = getIDs()
  362. end
  363.  
  364.  
  365. local odds = {
  366. ["1"]={1,1},
  367. ["2"]={1,100},
  368. ["3"]={100,300},
  369. ["4"]={300,1000},
  370. ["5"]={600, 2500},
  371. ["6"]={800, 3000}
  372. }
  373.  
  374. local generateIDlength = function()
  375. local ret = 0
  376. local num = math.random(1,3000)
  377. for i,v in next, odds do
  378. if num>v[1] and num<=v[2] then
  379. ret = i
  380. break
  381. end
  382. end
  383. return ret
  384. end
  385.  
  386. local IDgenerator = function()
  387. local cur = string.rep("#", generateIDlength())
  388. local id = cur:gsub(".", function(str)
  389. return string.char(math.random(48, 57))
  390. end)
  391. return id
  392. end
  393.  
  394. local generateID = function()
  395. local id = IDgenerator()
  396. for i=1,20 do
  397. if IDs[tostring(id)] ~= nil then
  398. id = IDgenerator()
  399. else
  400. break
  401. end
  402. end
  403.  
  404. if IDs[tostring(id)]~=nil then
  405. return "failed"
  406. else
  407. return id
  408. end
  409. end
  410.  
  411. local createNewID = function(length)
  412. local id = generateID()
  413. if id == "failed" then
  414. return "failed"
  415. else
  416. addCode(tostring(id), {
  417. ["ExpirationDay"]=generateExpirationDay(length),
  418. ["Disabled"]="false"
  419. })
  420. return id
  421. end
  422. end
  423.  
  424. local checkValidID = function(id)
  425. local returnMessage = ""
  426. if IDs[tostring(id)] == nil then
  427. returnMessage="false"
  428. else
  429. local tbl = IDs[tostring(id)]
  430. local day = os.day()
  431. local time = os.time()
  432. print(tbl[1])
  433. if tbl["Disabled"]==true then
  434. returnMessage="false"
  435. else
  436. if day>=tbl["ExpirationDay"][1] then
  437. returnMessage = "false"
  438. else
  439. returnMessage = "true"
  440. end
  441. end
  442. end
  443. return returnMessage
  444. end
  445.  
  446. local getTimeLeft = function(id)
  447. local ret = "nil"
  448. if IDs[tostring(id)] == nil then
  449. else
  450. local tbl = IDs[tostring(id)]
  451. local expiring = tbl.ExpirationDay
  452.  
  453. ret = tostring((24/(1234)*(expiring[1]-os.day()))).." - Hours"
  454. end
  455. return ret
  456. end
  457.  
  458. local blacklistID = function(id)
  459. if IDs[tostring(id)] ~= nil then
  460. local tbl = IDs[id]
  461. IDs[id]["Disabled"]=true
  462. end
  463. end
  464.  
  465. local dayInMonths = {
  466. ["january"]=31,
  467. ["february"]=28,
  468. ["mars"]=31,
  469. ["april"]=30,
  470. ["may"]=31,
  471. ["june"]=30,
  472. ["july"]=31,
  473. ["august"]=31,
  474. ["september"]=30,
  475. ["october"]=31,
  476. ["november"]=30,
  477. ["december"]=31
  478. }
  479.  
  480. local monthOrder = {
  481. ["january"]=1,
  482. ["february"]=2,
  483. ["mars"]=3,
  484. ["april"]=4,
  485. ["may"]=5,
  486. ["june"]=6,
  487. ["july"]=7,
  488. ["august"]=8,
  489. ["september"]=9,
  490. ["october"]=10,
  491. ["november"]=11,
  492. ["december"]=12
  493. }
  494.  
  495. local getRealTime = function()
  496. local api = "http://worldtimeapi.org/api/timezone/Etc/GMT.txt"
  497. local httpget = http.get(api)
  498. local readAll = httpget.readAll()
  499. local date = readAll:gmatch("datetime: %d*-%d*-%d*")()
  500. local realDate = date:gsub(".", function(str)
  501. if str:match("%d") or str:match("-") then
  502. return str
  503. else
  504. return ""
  505. end
  506. end)
  507. local time = readAll:gmatch("%d*:%d*:%d*")()
  508. return {realDate, time}
  509. end
  510.  
  511. local getTimeOneDayOffset = function(tbl)
  512. local curtime = tbl[2]
  513. local date = tbl[1]
  514. local ret = {}
  515. local newDate = {
  516. ["year"]="",
  517. ["month"]="",
  518. ["day"]=""
  519. }
  520. local split = string.split(date,"-")
  521. for i,v in next, split do
  522. if i==1 then
  523. newDate.year = v
  524. elseif i==2 then
  525. newDate.month = v
  526. elseif i==3 then
  527. newDate.day = v
  528. end
  529. end
  530. local currentMonth = ""
  531. for i,v in next, monthOrder do
  532. if v==tonumber(newDate.month) then
  533. currentMonth = i
  534. end
  535. end
  536. local daysinthismonth = dayInMonths[currentMonth]
  537. if tonumber(newDate.day)+1>daysinthismonth then
  538. if newDate.month=="12" then
  539. newDate.year = tonumber(newDate.year)+1
  540. newDate.month = "01"
  541. newDate.day = "01"
  542. else
  543. local nextMonthNumber = monthOrder[currentMonth]+1
  544. local nextMonth = ""
  545. for i,v in next, monthOrder do
  546. if v==nextMonthNumber then
  547. nextMonth=i
  548. end
  549. end
  550. newDate.day = "01"
  551. if #tostring(nextMonthNumber)==1 then
  552. newDate.month="0"..tostring(nextMonthNumber)
  553. else
  554. newDate.month=tostring(nextMonthNumber)
  555. end
  556. end
  557. else
  558. local newday = tonumber(newDate.day)+1
  559. if #tostring(newday) == 1 then
  560. newday = "0"..tostring(newday)
  561. else
  562. newday = tostring(newday)
  563. end
  564. newDate.day = newday
  565. end
  566. ret[1] = tostring(newDate.year).."-"..tostring(newDate.month).."-"..tostring(newDate.day)
  567. ret[2] = tbl[2]
  568. return ret
  569. end
  570.  
  571.  
  572.  
  573. local printInfo = function(id)
  574. local printers = getPrinters()
  575. if #printers >= 1 then
  576. local printer = printers[1]
  577. if peripheral.wrap(printer).getPaperLevel() > 0 and peripheral.wrap(printer).getInkLevel() > 0 then
  578. local pos = 1
  579. local str = ""
  580. local tbl = IDs[id]
  581. if tbl ~= nil then
  582. peripheral.wrap(printer).newPage()
  583. peripheral.wrap(printer).write(str)
  584.  
  585. local valid = checkValidID(id)
  586. local time = getTimeLeft(id)
  587. pos = pos+2
  588. peripheral.wrap(printer).setCursorPos(1,pos)
  589. peripheral.wrap(printer).write("Expires in "..getTimeLeft(id))
  590. pos=pos+2
  591. peripheral.wrap(printer).setCursorPos(1,pos)
  592. peripheral.wrap(printer).write("Your ID is "..id)
  593. pos=pos+1
  594. peripheral.wrap(printer).setCursorPos(1,pos)
  595. peripheral.wrap(printer).write("EXPIRES: ")
  596. local expirationdate = getTimeOneDayOffset(getRealTime())
  597. pos=pos+1
  598. peripheral.wrap(printer).setCursorPos(1,pos)
  599. peripheral.wrap(printer).write(expirationdate[1])
  600. pos=pos+1
  601. peripheral.wrap(printer).setCursorPos(1,pos)
  602. peripheral.wrap(printer).write(expirationdate[2].." GMT+1")
  603. pos=pos+2
  604. peripheral.wrap(printer).setCursorPos(1,pos)
  605. peripheral.wrap(printer).write("ID is valid: "..valid)
  606. pos=pos+2
  607. peripheral.wrap(printer).setCursorPos(1,pos)
  608. peripheral.wrap(printer).write("Welcome to the zoo :)")
  609. peripheral.wrap(printer).endPage()
  610. else
  611.  
  612. end
  613. end
  614. end
  615. end
  616.  
  617. local isTyping = false
  618. local onEnter = function()
  619.  
  620. end
  621. local typingtext = ""
  622. local typingX, typingY = 0, 0
  623. local maxTypingLetters = 0
  624. local typingColor = colors.white
  625. local currentGUI = "main"
  626. local loadinggui = false
  627.  
  628. local guitbl = {}
  629.  
  630. local checkvalididinfo = {}
  631.  
  632. local checkvalidcurrentid = ""
  633. local isvalid = "nil"
  634. local validexpiratondate = "nil"
  635. local timeleft = "nil"
  636.  
  637. local checkvalidinfomt = {
  638. __newindex = function(table, key, value)
  639. if key=="CurrentID" then
  640. checkvalidcurrentid = value
  641. guitbl["switchgui"]="checkidvalid"
  642. return nil
  643. elseif key=="checkvalid" then
  644. isvalid=value
  645. guitbl["switchgui"]="checkidvalid"
  646. elseif key=="timeleft" then
  647. timeleft=value
  648. guitbl["switchgui"]="checkidvalid"
  649. end
  650. return nil
  651. end
  652. }
  653.  
  654. setmetatable(checkvalididinfo, checkvalidinfomt)
  655.  
  656. local generateidNewID = "nil"
  657.  
  658. local generateidinfo = {}
  659.  
  660. local generateidinfomt = {
  661. __newindex = function(table, key, value)
  662. if key=="newid" then
  663. generateidNewID = value
  664. guitbl["switchgui"]="generateid"
  665. end
  666. end
  667. }
  668.  
  669. setmetatable(generateidinfo, generateidinfomt)
  670.  
  671. local checkcancelcurrentid = "nil"
  672. local checkcancelidinfo = {}
  673.  
  674. local checkcancelidinfomt = {
  675. __newindex = function(table, key, value)
  676. if key=="CurrentID" then
  677. checkcancelcurrentid = value
  678. guitbl["switchgui"]="cancelid"
  679. end
  680. end
  681. }
  682.  
  683. setmetatable(checkcancelidinfo, checkcancelidinfomt)
  684.  
  685. local zootbl = {}
  686.  
  687. local zoomt = {
  688. __newindex = function(self, key, value)
  689. if key == "closezoo" then
  690. zoostatus = false
  691. guitbl["switchgui"]="zoo"
  692. elseif key == "openzoo" then
  693. zoostatus = true
  694. guitbl["switchgui"]="zoo"
  695. end
  696. end
  697. }
  698.  
  699. setmetatable(zootbl, zoomt)
  700.  
  701. local guiDrawing = {
  702. ["main"]=function()
  703. loadinggui = true
  704. draw.fillBackground("magenta")
  705. draw.fillLine(1, "pink")
  706. local sizeX, sizeY = term.getSize()
  707. draw.createColoredText(1, 1, "&8[&0Main Menu&8]", "pink")
  708. draw.createColoredText(#"[Main Menu]"+2, 1, "&8[&0ID Menu&8]", "pink")
  709. draw.createColoredText(#"[Main Menu]"+#"[ID Menu]"+3, 1, "&8[&0Zoo&8]", "pink")
  710. draw.createText((sizeX)/2, (sizeY-1)/2+0, "Zoo Admin Panel", "white", "magenta")
  711. draw.createText((sizeX)/2, (sizeY-1)/2+1, "Controls the whole Zoo!", "white", "magenta")
  712. draw.createText((sizeX)/2, (sizeY-1)/2+2, "Computer #"..os.getComputerID(), "white", "magenta")
  713. loadinggui = false
  714. end,
  715. ["idmenu"]=function()
  716. loadinggui = true
  717. draw.fillBackground("magenta")
  718. draw.fillLine(1, "pink")
  719. local sizeX, sizeY = term.getSize()
  720. draw.createColoredText(1, 1, "&8[&0Main Menu&8]", "pink")
  721. draw.createColoredText(#"[Main Menu]"+2, 1, "&8[&0ID Menu&8]", "pink")
  722. draw.createColoredText(#"[Main Menu]"+#"[ID Menu]"+3, 1, "&8[&0Zoo&8]", "pink")
  723. draw.createText((sizeX)/2, 2, "ID Admin Panel", "white", "magenta")
  724. draw.createNormalText((sizeX/2)-10, sizeY/2, "Generate ID"..string.rep(" ",21-#"Generate ID"), "white", "pink")
  725. draw.createNormalText((sizeX/2)-10, sizeY/2+2, "Check Valid ID"..string.rep(" ",21-#"Check Valid ID"), "white", "pink")
  726. draw.createNormalText((sizeX/2)-10, sizeY/2+4, "Cancel ID"..string.rep(" ",21-#"Cancel ID"), "white", "pink")
  727. loadinggui = false
  728.  
  729. end,
  730. ["checkidvalid"]=function()
  731. loadinggui = true
  732. draw.fillBackground("magenta")
  733. draw.fillLine(1, "pink")
  734. local sizeX, sizeY = term.getSize()
  735. draw.createColoredText(1, 1, "&8[&0Main Menu&8]", "pink")
  736. draw.createColoredText(#"[Main Menu]"+2, 1, "&8[&0ID Menu&8]", "pink")
  737. draw.createColoredText(#"[Main Menu]"+#"[ID Menu]"+3, 1, "&8[&0Zoo&8]", "pink")
  738. draw.createText((sizeX)/2, 2, "ID Information", "white", "magenta")
  739. draw.fillSquare(math.floor(sizeX/2)-15, sizeY/2-3, math.ceil(sizeX/2)+15, sizeY/2-3, "pink")
  740. draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2+2, math.ceil(sizeX/2)+10, sizeY/2+2, "pink")
  741. draw.createText(math.floor(sizeX/2), sizeY/2+2, "Check Is Valid", "white", "pink")
  742. draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2, math.ceil(sizeX/2)+10, sizeY/2, "pink")
  743. draw.createText(math.floor(sizeX/2), sizeY/2-1, "Current ID", "white", "magenta")
  744. draw.createText(math.floor(sizeX/2), sizeY/2, checkvalidcurrentid:sub(1,21), "white", "pink")
  745. draw.createText(math.floor(sizeX/2), sizeY/2+4, "Is Valid", "white", "magenta")
  746. draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2+5, math.ceil(sizeX/2)+10, sizeY/2+5, "pink")
  747. draw.createText(math.floor(sizeX/2), sizeY/2+5, isvalid, "white", "pink")
  748. draw.createText(math.floor(sizeX/2), sizeY/2+7, "Time Left", "white", "magenta")
  749. draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2+8, math.ceil(sizeX/2)+10, sizeY/2+8, "pink")
  750. draw.createText(math.floor(sizeX/2), sizeY/2+8, timeleft, "white", "pink")
  751. loadinggui = false
  752. end,
  753. ["generateid"]=function()
  754. loadinggui = true
  755. draw.fillBackground("magenta")
  756. draw.fillLine(1, "pink")
  757. local sizeX, sizeY = term.getSize()
  758. draw.createColoredText(1, 1, "&8[&0Main Menu&8]", "pink")
  759. draw.createColoredText(#"[Main Menu]"+2, 1, "&8[&0ID Menu&8]", "pink")
  760. draw.createColoredText(#"[Main Menu]"+#"[ID Menu]"+3, 1, "&8[&0Zoo&8]", "pink")
  761. draw.createText((sizeX)/2, 2, "Generate ID", "white", "magenta")
  762. draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2-3, math.ceil(sizeX/2)+10, sizeY/2-3, "pink")
  763. draw.createText(sizeX/2, sizeY/2-3, "Generate ID", "white", "pink")
  764. draw.createText(sizeX/2, sizeY/2+1, "New Generated ID", "white", "magenta")
  765. draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2+2, math.ceil(sizeX/2)+10, sizeY/2+2, "pink")
  766. draw.createText(sizeX/2, sizeY/2+2, tostring(generateidNewID), "white", "pink")
  767. draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2+4, math.ceil(sizeX/2)+10, sizeY/2+4, "pink")
  768. draw.createText(sizeX/2, sizeY/2+4, tostring("Print Information"), "white", "pink")
  769.  
  770. loadinggui = false
  771. end,
  772. ["cancelid"]=function()
  773. loadinggui = true
  774. draw.fillBackground("magenta")
  775. draw.fillLine(1, "pink")
  776. local sizeX, sizeY = term.getSize()
  777. draw.createColoredText(1, 1, "&8[&0Main Menu&8]", "pink")
  778. draw.createColoredText(#"[Main Menu]"+2, 1, "&8[&0ID Menu&8]", "pink")
  779. draw.createColoredText(#"[Main Menu]"+#"[ID Menu]"+3, 1, "&8[&0Zoo&8]", "pink")
  780. draw.createText((sizeX)/2, 2, "Cancel IDs", "white", "magenta")
  781. draw.fillSquare(math.floor(sizeX/2)-15, sizeY/2-3, math.ceil(sizeX/2)+15, sizeY/2-3, "pink")
  782. draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2, math.ceil(sizeX/2)+10, sizeY/2, "pink")
  783. draw.createText(math.floor(sizeX/2), sizeY/2-1, "Current ID", "white", "magenta")
  784. draw.createText(math.floor(sizeX/2), sizeY/2, checkcancelcurrentid:sub(1,21), "white", "pink")
  785. draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2+2, math.ceil(sizeX/2)+10, sizeY/2+2, "pink")
  786. draw.createText(sizeX/2, sizeY/2+2, tostring("Cancel ID"), "white", "pink")
  787. loadinggui = false
  788. end,
  789. ["zoo"]=function()
  790. loadinggui = true
  791. draw.fillBackground("magenta")
  792. draw.fillLine(1, "pink")
  793. local sizeX, sizeY = term.getSize()
  794. draw.createColoredText(1, 1, "&8[&0Main Menu&8]", "pink")
  795. draw.createColoredText(#"[Main Menu]"+2, 1, "&8[&0ID Menu&8]", "pink")
  796. draw.createColoredText(#"[Main Menu]"+#"[ID Menu]"+3, 1, "&8[&0Zoo&8]", "pink")
  797. draw.createText((sizeX)/2, 2, "Zoo Admin Panel", "white", "magenta")
  798. draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2, math.ceil(sizeX/2)+10, sizeY/2, "pink")
  799. draw.createText(sizeX/2, sizeY/2, tostring("Close Down Zoo"), "white", "pink")
  800. draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2+2, math.ceil(sizeX/2)+10, sizeY/2+2, "pink")
  801. draw.createText(sizeX/2, sizeY/2+2, tostring("Open Up Zoo"), "white", "pink")
  802. draw.fillSquare(math.floor(sizeX/2)-10, sizeY/2+5, math.ceil(sizeX/2)+10, sizeY/2+5, "pink")
  803. draw.createText(sizeX/2, sizeY/2+5, tostring((function() if zoostatus == true then return "Open" else return "Closed" end end)()), "white", "pink")
  804. loadinggui = false
  805. end
  806. }
  807.  
  808. local drawGUI = function()
  809. if guiDrawing[currentGUI] ~= nil then
  810. guiDrawing[currentGUI]()
  811. end
  812. end
  813.  
  814.  
  815. local guimt = {
  816. __newindex = function(table, key, value)
  817. if key == "switchgui" and loadinggui == false then
  818. typingtext=""
  819. isTyping=false
  820. currentGUI = value
  821. drawGUI()
  822. end
  823. end
  824. }
  825.  
  826. setmetatable(guitbl, guimt)
  827.  
  828. local termSizeX, termSizeY = term.getSize()
  829.  
  830. local buttons = {
  831. ["main"]={
  832. ["mainmenu"]={
  833. ["posX"]=1,
  834. ["posY"]=1,
  835. ["sizeX"]=11,
  836. ["sizeY"]=1,
  837. ["func"]=function()
  838. guitbl["switchgui"]="main"
  839. end
  840. },
  841. ["idmenu"]={
  842. ["posX"]=13,
  843. ["posY"]=1,
  844. ["sizeX"]=9,
  845. ["sizeY"]=1,
  846. ["func"]=function()
  847. guitbl["switchgui"]="idmenu"
  848. end
  849. },
  850. ["zoo"]={
  851. ["posX"]=22,
  852. ["posY"]=1,
  853. ["sizeX"]=5,
  854. ["sizeY"]=1,
  855. ["func"]=function()
  856. guitbl["switchgui"]="zoo"
  857. end
  858. }
  859. },
  860. ["idmenu"]={
  861. ["mainmenu"]={
  862. ["posX"]=1,
  863. ["posY"]=1,
  864. ["sizeX"]=11,
  865. ["sizeY"]=1,
  866. ["func"]=function()
  867. guitbl["switchgui"]="main"
  868. end
  869. },
  870. ["idmenu"]={
  871. ["posX"]=13,
  872. ["posY"]=1,
  873. ["sizeX"]=9,
  874. ["sizeY"]=1,
  875. ["func"]=function()
  876. guitbl["switchgui"]="idmenu"
  877. end
  878. },
  879. ["zoo"]={
  880. ["posX"]=22,
  881. ["posY"]=1,
  882. ["sizeX"]=5,
  883. ["sizeY"]=1,
  884. ["func"]=function()
  885. guitbl["switchgui"]="zoo"
  886. end
  887. },
  888. ["generateid"]={
  889. ["posX"]=(termSizeX/2)-10,
  890. ["posY"]=(termSizeY/2),
  891. ["sizeX"]=21,
  892. ["sizeY"]=1,
  893. ["func"]=function()
  894. guitbl["switchgui"]="generateid"
  895. end
  896. },
  897. ["checkvalidid"]={
  898. ["posX"]=(termSizeX/2)-10,
  899. ["posY"]=(termSizeY/2)+2,
  900. ["sizeX"]=21,
  901. ["sizeY"]=1,
  902. ["func"]=function()
  903. guitbl["switchgui"]="checkidvalid"
  904. end
  905. },
  906. ["cancelid"]={
  907. ["posX"]=(termSizeX/2)-10,
  908. ["posY"]=(termSizeY/2)+4,
  909. ["sizeX"]=21,
  910. ["sizeY"]=1,
  911. ["func"]=function()
  912. guitbl["switchgui"]="cancelid"
  913. end
  914. }
  915. },
  916. ["zoo"]={
  917. ["mainmenu"]={
  918. ["posX"]=1,
  919. ["posY"]=1,
  920. ["sizeX"]=11,
  921. ["sizeY"]=1,
  922. ["func"]=function()
  923. guitbl["switchgui"]="main"
  924. end
  925. },
  926. ["idmenu"]={
  927. ["posX"]=13,
  928. ["posY"]=1,
  929. ["sizeX"]=9,
  930. ["sizeY"]=1,
  931. ["func"]=function()
  932. guitbl["switchgui"]="idmenu"
  933. end
  934. },
  935. ["zoo"]={
  936. ["posX"]=22,
  937. ["posY"]=1,
  938. ["sizeX"]=5,
  939. ["sizeY"]=1,
  940. ["func"]=function()
  941. guitbl["switchgui"]="zoo"
  942. end
  943. },
  944. ["closezoo"]={
  945. ["posX"]=math.floor(termSizeX/2)-10,
  946. ["posY"]=termSizeY/2,
  947. ["sizeX"]=21,
  948. ["sizeY"]=1,
  949. ["func"]=function()
  950. zootbl["closezoo"]=false
  951. end
  952. },
  953. ["openzoo"]={
  954. ["posX"]=math.floor(termSizeX/2)-10,
  955. ["posY"]=termSizeY/2+2,
  956. ["sizeX"]=21,
  957. ["sizeY"]=1,
  958. ["func"]=function()
  959. zootbl["openzoo"]=true
  960. end
  961. }
  962. },
  963. ["checkidvalid"]={
  964. ["mainmenu"]={
  965. ["posX"]=1,
  966. ["posY"]=1,
  967. ["sizeX"]=11,
  968. ["sizeY"]=1,
  969. ["func"]=function()
  970. guitbl["switchgui"]="main"
  971. end
  972. },
  973. ["idmenu"]={
  974. ["posX"]=13,
  975. ["posY"]=1,
  976. ["sizeX"]=9,
  977. ["sizeY"]=1,
  978. ["func"]=function()
  979. guitbl["switchgui"]="idmenu"
  980. end
  981. },
  982. ["zoo"]={
  983. ["posX"]=22,
  984. ["posY"]=1,
  985. ["sizeX"]=5,
  986. ["sizeY"]=1,
  987. ["func"]=function()
  988. guitbl["switchgui"]="zoo"
  989. end
  990. },
  991. ["searchbar"]={
  992. ["posX"]=math.floor(termSizeX/2)-15,
  993. ["posY"]=termSizeY/2-3,
  994. ["sizeX"]=31,
  995. ["sizeY"]=1,
  996. ["func"]=function()
  997. typingX = math.floor(termSizeX/2)-15
  998. typingY = termSizeY/2-3
  999. typingColor = colors.pink
  1000. maxTypingLetters = 31
  1001. isTyping = true
  1002. onEnter = function(text)
  1003. checkvalididinfo["CurrentID"]=text
  1004. end
  1005. end
  1006. },
  1007. ["validbutton"]={
  1008. ["posX"]=math.floor(termSizeX/2)-10,
  1009. ["posY"]=math.floor(termSizeY/2)+2,
  1010. ["sizeX"]=21,
  1011. ["sizeY"]=1,
  1012. ["func"]=function()
  1013. checkvalididinfo["checkvalid"]=checkValidID(checkvalidcurrentid)
  1014. checkvalididinfo["timeleft"]=getTimeLeft(checkvalidcurrentid)
  1015. end
  1016. },
  1017. },
  1018. ["generateid"]={
  1019. ["generateidbutton"]={
  1020. ["posX"]=math.floor(termSizeX/2)-10,
  1021. ["posY"]=termSizeY/2-3,
  1022. ["sizeX"]=21,
  1023. ["sizeY"]=1,
  1024. ["func"]=function()
  1025. generateidinfo["newid"]=createNewID("Day")
  1026. end
  1027. },
  1028. ["mainmenu"]={
  1029. ["posX"]=1,
  1030. ["posY"]=1,
  1031. ["sizeX"]=11,
  1032. ["sizeY"]=1,
  1033. ["func"]=function()
  1034. guitbl["switchgui"]="main"
  1035. end
  1036. },
  1037. ["idmenu"]={
  1038. ["posX"]=13,
  1039. ["posY"]=1,
  1040. ["sizeX"]=9,
  1041. ["sizeY"]=1,
  1042. ["func"]=function()
  1043. guitbl["switchgui"]="idmenu"
  1044. end
  1045. },
  1046. ["zoo"]={
  1047. ["posX"]=22,
  1048. ["posY"]=1,
  1049. ["sizeX"]=5,
  1050. ["sizeY"]=1,
  1051. ["func"]=function()
  1052. guitbl["switchgui"]="zoo"
  1053. end
  1054. },
  1055. ["printinformation"]={
  1056. ["posX"]=math.floor(termSizeX/2)-10,
  1057. ["posY"]=termSizeY/2+4,
  1058. ["sizeX"]=21,
  1059. ["sizeY"]=1,
  1060. ["func"]=function()
  1061. if generateidNewID ~= "nil" then
  1062. printInfo(generateidNewID)
  1063. end
  1064. end
  1065. }
  1066. },
  1067. ["cancelid"]={
  1068. ["mainmenu"]={
  1069. ["posX"]=1,
  1070. ["posY"]=1,
  1071. ["sizeX"]=11,
  1072. ["sizeY"]=1,
  1073. ["func"]=function()
  1074. guitbl["switchgui"]="main"
  1075. end
  1076. },
  1077. ["idmenu"]={
  1078. ["posX"]=13,
  1079. ["posY"]=1,
  1080. ["sizeX"]=9,
  1081. ["sizeY"]=1,
  1082. ["func"]=function()
  1083. guitbl["switchgui"]="idmenu"
  1084. end
  1085. },
  1086. ["zoo"]={
  1087. ["posX"]=22,
  1088. ["posY"]=1,
  1089. ["sizeX"]=5,
  1090. ["sizeY"]=1,
  1091. ["func"]=function()
  1092. guitbl["switchgui"]="zoo"
  1093. end
  1094. },
  1095. ["search"]={
  1096. ["posX"]=math.floor(termSizeX/2-15),
  1097. ["posY"]=termSizeY/2-3,
  1098. ["sizeX"]=31,
  1099. ["sizeY"]=1,
  1100. ["func"]=function()
  1101. typingX = math.floor(termSizeX/2)-15
  1102. typingY = termSizeY/2-3
  1103. typingColor = colors.pink
  1104. maxTypingLetters = 31
  1105. isTyping = true
  1106. onEnter = function(text)
  1107. checkcancelidinfo["CurrentID"]=text
  1108. end
  1109. end
  1110. },
  1111. ["cancelid"]={
  1112. ["posX"]=math.floor(termSizeX/2)-10,
  1113. ["posY"]=termSizeY/2+2,
  1114. ["sizeX"]=21,
  1115. ["sizeY"]=2,
  1116. ["func"]=function()
  1117. if checkcancelcurrentid ~= "nil" then
  1118. blacklistID(checkcancelcurrentid)
  1119. end
  1120. end
  1121. }
  1122. }
  1123.  
  1124. }
  1125.  
  1126. local updateText = function()
  1127. draw.fillSquare(typingX, typingY, typingX+maxTypingLetters, typingY, typingColor)
  1128. typingtext=typingtext:sub(1,maxTypingLetters)
  1129. term.setCursorPos(typingX, typingY)
  1130. write(typingtext)
  1131. end
  1132.  
  1133. guitbl["switchgui"]="main"
  1134.  
  1135. local onButton = function(x, y)
  1136. if buttons[tostring(currentGUI)] ~= nil then
  1137. for i,v in next, buttons[currentGUI] do
  1138. if x>=math.floor(v.posX) and x<=math.floor(v.posX+(v.sizeX-1)) then
  1139. if y>=math.floor(v.posY) and y<=math.floor(v.posY+(v.sizeY-1)) then
  1140. v.func()
  1141. break
  1142. else
  1143. isTyping=false
  1144. end
  1145. else
  1146. isTyping=false
  1147. end
  1148. end
  1149. end
  1150. end
  1151.  
  1152.  
  1153. local eventloop = function()
  1154. while true do
  1155. local event, a1, a2, a3 = os.pullEvent()
  1156. if event == "mouse_click" then
  1157. if a1 == 1 then
  1158.  
  1159. onButton(a2, a3)
  1160. end
  1161. elseif event == "key" then
  1162. if isTyping == true then
  1163. if #keys.getName(a1) == 1 then
  1164. typingtext=typingtext..keys.getName(a1)
  1165. elseif a1>=2 and a1<=10 then
  1166. typingtext=typingtext..tostring(a1-1)
  1167. elseif a1==11 then
  1168. typingtext=typingtext.."0"
  1169. elseif a1==14 then
  1170. typingtext=typingtext:sub(1, #typingtext-1)
  1171. elseif a1==28 then
  1172.  
  1173. elseif a1==57 then
  1174. typingtext=typingtext.." "
  1175. end
  1176. if a1==28 then
  1177. onEnter(typingtext)
  1178. isTyping=false
  1179. typingtext = ""
  1180. updateText()
  1181. else
  1182. updateText()
  1183. end
  1184. end
  1185. if a1==50 then
  1186. error("hey")
  1187. end
  1188. end
  1189. end
  1190. end
  1191.  
  1192. local rednetloop = function()
  1193. while true do
  1194. local id, message, protocol = rednet.receive()
  1195. if message:gmatch("validid_%d+")() then
  1196. local validstatus = checkValidID(message:sub(#"validid_.",#message))
  1197. if validstatus == "true" then
  1198. if zoostatus == false then
  1199. rednet.send(id, "Zoo is closed")
  1200. else
  1201. rednet.send(id, "isvalid_"..message:sub(#"validid_.", #message).."_".."true")
  1202. end
  1203. elseif validstatus == "false" then
  1204. rednet.send(id, "isvalid_"..message:sub(#"validid_.", #message).."_".."false")
  1205. end
  1206. end
  1207. end
  1208. end
  1209.  
  1210. parallel.waitForAny(rednetloop, eventloop)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement