Daniel_I_Am

Community Goals Xmas Edition 0.0.1

Dec 23rd, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.28 KB | None | 0 0
  1. transposer = {"dc3","26f","ded","3da"}
  2. redstoneFlush = "cd7"
  3. outputRedstoneIOs = {"bf6", "7b4", "27c", "7c7", "007"}
  4.  
  5. component = require("component")
  6. sides = require("sides")
  7. term = require("term")
  8. fs = require("filesystem")
  9. event = require("event")
  10. os = require("os")
  11. io = require("io")
  12.  
  13. gpu = component.gpu
  14. internet = component.internet
  15. keyboard = component.keyboard
  16. debugCard = component.debug
  17.  
  18. transposer = {component.proxy(component.get(transposer[1])),component.proxy(component.get(transposer[2])),component.proxy(component.get(transposer[3])),component.proxy(component.get(transposer[4]))}
  19. outputRedstoneIOs = {component.proxy(component.get(outputRedstoneIOs[1])),component.proxy(component.get(outputRedstoneIOs[2])),component.proxy(component.get(outputRedstoneIOs[3])),component.proxy(component.get(outputRedstoneIOs[4])), component.proxy(component.get(outputRedstoneIOs[5]))}
  20. width = 120
  21. height = 30
  22. gpu.setResolution(width, height)
  23.  
  24. colorTable = {
  25.     uncommon = {
  26.         PrimaryCol = 0x36c95e,
  27.         SecondaryCol = 0x1b642f,
  28.     textCol = 0xffffff,
  29.     progressFilled = 0x00ff00,
  30.     progressEmpty = 0x000000
  31.     },
  32.     rare = {
  33.         SecondaryCol = 0x4283d8,
  34.         PrimaryCol = 0x21416c,
  35.     textCol = 0xffffff,
  36.     progressFilled = 0x0000ff,
  37.     progressEmpty = 0x000000
  38.     },
  39.     epic = {
  40.         SecondaryCol = 0x9c52c8,
  41.         PrimaryCol = 0x4e2964,
  42.     textCol = 0xffffff,
  43.     progressFilled = 0xcc66ff,
  44.     progressEmpty = 0x000000
  45.     },
  46.     legendary = {
  47.         SecondaryCol = 0xdd871c,
  48.         PrimaryCol = 0x6e430e,
  49.     textCol = 0xffffff,
  50.     progressFilled = 0xff9933,
  51.     progressEmpty = 0x000000
  52.     }
  53. }
  54.  
  55. --variables
  56. currentTier = 1
  57. subObjective = 1
  58. link = "http://www.endercompanies.com/time.php"
  59. dataFile = "data.txt"
  60. multiplier = 1
  61. redstoneFlushSide = sides.east
  62. redstoneOutputSide = sides.top
  63. goalCompletionTime = 3600 --to solve
  64. inbetweenGoalTime = 30 --completed a t4
  65. betweenGoalTime = 1 --when completed
  66. leftOffset = 20
  67.  
  68. --completion at:
  69. completionTier1 = 6
  70. completionTier2 = 4
  71. completionTier3 = 2
  72. completionTier4 = 1
  73.  
  74. function addRect(x1,y1,x2,y2,color)
  75.     temp = gpu.getBackground()
  76.     gpu.setBackground(color)
  77.     gpu.fill(x1,y1,x2-x1+1,y2-y1+1," ")
  78.     gpu.setBackground(temp)
  79. end
  80.  
  81. function addProgressBar(x1,y1,x2,y2,sideWidth,sideHeight,borderColor,filledBarColor,emptyBarColor,textColor,headerText,filledPercentage,isSideways,isInverted)
  82.     isSideways = isSideways or false
  83.     isInverted = isInverted or false
  84.     if type(x1)~="number" then throwError("addProgressBar() argument 1 (x1) type int expected, "..type(x1).." found") end
  85.     if type(x2)~="number" then throwError("addProgressBar() argument 3 (x2) type int expected, "..type(x2).." found") end
  86.     if type(y1)~="number" then throwError("addProgressBar() argument 2 (y1) type int expected, "..type(y1).." found") end
  87.     if type(y2)~="number" then throwError("addProgressBar() argument 4 (y2) type int expected, "..type(y2).." found") end
  88.     if type(sideWidth)~="number" then throwError("addProgressBar() argument 5 (sideWidth) type int expected, "..type(sideWidth).." found") end
  89.     if type(sideHeight)~="number" then throwError("addProgressBar() argument 6 (sideHeight) type int expected, "..type(sideHeight).." found") end
  90.     if type(filledPercentage)~="number" then throwError("addProgressBar() argument 11 (filledPercentage) type float expected, "..type(filledPercentage).." found") end
  91.     if filledPercentage > 1 then filledPercentage = 1 end
  92.     if isSideways == false then
  93.         addRect(x1,y1,x2,y2,borderColor)
  94.         addRect(x1+sideWidth,y1+sideHeight,x2-sideWidth,y2-sideHeight,emptyBarColor)
  95.         barSize = (y2-y1-2*sideHeight)
  96.         pixelsFilled = math.floor(filledPercentage*barSize+0.5)
  97.         if isInverted == false then
  98.             addRect(x1+sideWidth,y2-sideHeight-pixelsFilled,x2-sideWidth,y2-sideHeight,filledBarColor)
  99.         elseif isInverted == true then
  100.             addRect(x1+sideWidth,y1+sideHeight,x2-sideWidth,y1+sideHeight+pixelsFilled,filledBarColor)
  101.         else
  102.             throwError("addProgressBar() argument 13 (isInverted) type boolean expected, "..type(isInverted).." found")
  103.         end
  104.     elseif isSideways == true then
  105.         addRect(x1,y1,x2,y2,borderColor)
  106.         addRect(x1+sideWidth,y1+sideHeight,x2-sideWidth,y2-sideHeight,emptyBarColor)
  107.         barSize = (x2-x1-2*sideWidth)
  108.         pixelsFilled = math.floor(filledPercentage*barSize+0.5)
  109.         if isInverted == false then
  110.             addRect(x1+sideWidth,y1+sideHeight,x1+sideWidth+pixelsFilled,y2-sideHeight,filledBarColor)
  111.         elseif isInverted == true then
  112.             addRect(x2-sideWidth-pixelsFilled,y1+sideHeight,x2-sideWidth,y2-sideHeight,filledBarColor)
  113.         else
  114.             throwError("addProgressBar() argument 13 (isInverted) type boolean expected, "..type(isInverted).." found")
  115.         end
  116.     else
  117.         throwError("addProgressBar() argument 12 (isSideways) type boolean expected, "..type(isSideways).." found")
  118.     end
  119.     if sideHeight>0 then
  120.         col = {f = gpu.getForeground(),b = gpu.getBackground()}
  121.         centerX = math.ceil((x1+x2)/2)
  122.         centerY = math.floor(y1+sideHeight/2)
  123.         gpu.setForeground(textColor)
  124.         gpu.setBackground(borderColor)
  125.         gpu.set(centerX-(string.len(tostring(headerText))/2),centerY,tostring(headerText))
  126.         gpu.setForeground(col.f)
  127.         gpu.setBackground(col.b)
  128.         centerX = nil
  129.         centerY = nil
  130.         col = nil
  131.     end
  132. end
  133.  
  134. function throwError(errorMessage)
  135.     errorMessage = errorMessage or "Unknown Error"
  136.     gpu.setResolution(gpu.maxResolution())
  137.     gpu.setForeground(0xff0000)
  138.     gpu.setBackground(0x000000)
  139.     term.clear()
  140.     print("The program ran into a serious error during execution.")
  141.     print(errorMessage)
  142.     gpu.setForeground(0xffffff)
  143.     os.exit()
  144. end
  145.  
  146. function listToPages(list,entriesPerPage)
  147.     pageList = {}
  148.     value = nil
  149.     tempList = {}
  150.    
  151.     for i = 1,#list,entriesPerPage do
  152.         tempList = {}
  153.         for j = 1,entriesPerPage do
  154.             value = table.remove(list, 1)
  155.             table.insert(tempList, value)
  156.         end
  157.         table.insert(pageList, tempList)
  158.     end
  159.     return pageList
  160. end
  161.  
  162. function completedObjective()
  163.     givePointToEveryoneOnline(currentTier)
  164.     if currentTier == 1 then
  165.         if subObjective >= completionTier1 then
  166.             subObjective = 1
  167.             currentTier = 2
  168.         else
  169.             subObjective = subObjective + 1
  170.         end
  171.     elseif currentTier == 2 then
  172.         if subObjective >= completionTier2 then
  173.             subObjective = 1
  174.             currentTier = 3
  175.         else
  176.             subObjective = subObjective + 1
  177.         end
  178.     elseif currentTier == 3 then
  179.         if subObjective >= completionTier3 then
  180.             subObjective = 1
  181.             currentTier = 4
  182.         else
  183.             subObjective = subObjective + 1
  184.         end
  185.     elseif currentTier == 4 then
  186.         if subObjective >= completionTier4 then
  187.             finishedObjective()
  188.         else
  189.             subObjective = subObjective + 1
  190.         end
  191.     end
  192. --  multiplier = 2 ^ (currentTier - 1)
  193.     if currentTier == 1 then multiplier = 0.5 + completionData
  194.     elseif currentTier == 2 then multiplier = 2 + completionData
  195.     elseif currentTier == 3 then multiplier = 6 + completionData * 2
  196.     else multiplier = 40 + completionData * 4
  197. end
  198. end
  199.  
  200. function getTime()
  201.     page = internet.request(link)
  202.     page.read()
  203.     local current = page.read()
  204.     local formattedTime = {}
  205.     local currentDate = string.sub(current, 1,string.find(current, ", ")-1)
  206.     local currentTime = string.sub(current, string.find(current, ", ")+2)
  207.     local currentDay = string.sub(current, 1,string.find(currentDate, " ")-1)
  208.     if currentDay == "Mon" then currentDay = 1 elseif currentDay == "Tue" then currentDay = 2 elseif currentDay == "Wed" then currentDay = 3 elseif currentDay == "Thu" then currentDay = 4 elseif currentDay == "Fri" then currentDay = 5 elseif currentDay == "Sat" then currentDay = 6 elseif currentDay == "Sun" then currentDay = 7 end
  209.     local currentHour = string.sub(currentTime, string.find(currentTime, " ")+1,string.find(currentTime, ":")-1)
  210.     local currentMinute = string.sub(string.sub(string.sub(currentTime, string.find(currentTime, " ")+1),string.find(string.sub(currentTime, string.find(currentTime, " ")+1), ":")+1),1,string.find(string.sub(string.sub(currentTime, string.find(currentTime, " ")+1),string.find(string.sub(currentTime, string.find(currentTime, " ")+1), ":")+1)," ")-1)
  211.     return {tonumber(currentDay), tonumber(currentHour), tonumber(currentMinute)}
  212. end
  213.  
  214. function addTimeToTime(currentTime, deltaTime)
  215.     day = currentTime[1]
  216.     hour = currentTime[2]
  217.     minute = currentTime[3]
  218.     local minute = minute + deltaTime
  219.     local hour = hour + math.floor(minute/60)
  220.     local day = day + math.floor(hour/24)
  221.     local minute = minute%60
  222.     local hour = hour%24
  223.     return {day, hour, minute}
  224. end
  225.  
  226. function getItems()
  227.     local s = {sides.north, sides.east, sides.south, sides.west}
  228.     local items = {}
  229.     for t = 1, #transposer do
  230.         for i = 1, #s do
  231.         size, error = transposer[t].getInventorySize(s[i])
  232.             if error ~= "no inventory" then
  233.                 for j = 2,5 do
  234.                     item = transposer[t].getStackInSlot(s[i], j)
  235.                     if item ~= nil then
  236.                         while string.find(item.label, "§") do
  237.                             item.label = string.sub(item.label, 1, string.find(item.label, "§")-1) .. string.sub(item.label, string.find(item.label, "§")+3)
  238.                         end
  239.                         table.insert(items, item)
  240.                     else
  241.                         table.insert(items, {label = "Unknown"})
  242.                     end
  243.                 end
  244.             else
  245.                 error = nil
  246.             end
  247.         end
  248.     end
  249.     return items --{item1, item2, item3, item4, item5, [...] } if there is no itemx then it is 'Unknown'
  250. end
  251.  
  252. function fileRead(fileLocation)
  253.     local str = {}
  254.     if fs.exists("/home/"..fileLocation) then
  255.         f = io.open("/home/"..fileLocation, "r")
  256.         repeat
  257.             line = f:read("*line")
  258.             if line ~= nil then
  259.                 table.insert(str, line)
  260.             end
  261.         until line == nil
  262.     else
  263.         throwError("File /home/"..fileLocation.." not found!")
  264.     end
  265.     f:close()
  266.     f = nil
  267.     return str
  268. end
  269.  
  270. function fileWrite(fileLocation, str, isOverwrite)
  271.     if isOverwrite==true then mode = "w" else mode = "a" end
  272.     f = io.open("/home/"..fileLocation,mode)
  273.     f:write(tostring(str).."\n")
  274.     f:close()
  275. end
  276.  
  277. function pickNewObjective()
  278.     local n = math.random(#objectives)
  279.     outputRedstoneIOs[5].setOutput(redstoneOutputSide, 15)
  280.     os.sleep(1)
  281.     outputRedstoneIOs[5].setOutput(redstoneOutputSide, 0)
  282.     return objectives[n]
  283. end
  284.  
  285. function finishedObjective()
  286.     w = 20
  287.     h = 6
  288. fileWrite("completionData.txt",completionData+1,true)
  289.     gpu.setResolution(w,h)
  290.     addRect(1,1,w,h,secondaryCol)
  291.     centerText("Completed Objective!", 1, w, 2, textCol, secondaryCol)
  292.     centerText("It will reset in:", 1, w, 3, textCol, secondaryCol)
  293.     timeLeft = inbetweenGoalTime
  294.     repeat
  295.         os.sleep(1)
  296.         timeLeft = timeLeft - 1
  297.         centerText("    " .. timeLeft .. " seconds  ", 1, w, 4, textCol, secondaryCol)
  298.     until timeLeft < 0
  299.     os.execute("reboot")
  300. end
  301.  
  302. function makeObjectives()
  303.     local objectiveItems = getItems()
  304.     local objectiveAmountsTemp = fileRead("data.txt")
  305.     objectiveAmountsTemp = objectiveAmountsTemp[1]
  306.     objectiveAmounts = {}
  307.     while string.find(objectiveAmountsTemp, ";") do
  308.         local a = string.find(objectiveAmountsTemp, ";")
  309.         table.insert(objectiveAmounts, string.sub(objectiveAmountsTemp, 1, a-1))
  310.         objectiveAmountsTemp = string.sub(objectiveAmountsTemp, a+1)
  311.     end
  312.     table.insert(objectiveAmounts, objectiveAmountsTemp)
  313.     objectives = {}
  314.     for i = 1, #objectiveItems do
  315.         if #objectiveAmounts<i then
  316.             table.insert(objectiveAmounts, 1)
  317.         end
  318.         table.insert(objectives, {objectiveItems[i].label, objectiveAmounts[i]})
  319.     end
  320.     local objectivesCopy = {}
  321.     for i=1,#objectives do table.insert(objectivesCopy, objectives[i]) end
  322.     local pagedObjectives = listToPages(objectivesCopy, 20)
  323.     for j = 1, #pagedObjectives do
  324.         for i = 1,#pagedObjectives[j] do
  325.             print(pagedObjectives[j][i][1] .." = "..pagedObjectives[j][i][2])
  326.         end
  327.         --print("please click the screen to continue")
  328.         --event.pull("touch")
  329.         print("please wait ... loading ...")
  330.         os.sleep(2)
  331.         term.clear()
  332.     end
  333. end
  334.  
  335. function resetStuff()
  336.     gpu.setForeground(0xffffff)
  337.     gpu.setBackground(0x000000)
  338.     term.clear()
  339. end
  340.  
  341. function init()
  342.     completionDataArray = fileRead("completionData.txt")
  343.     completionData = tonumber(completionDataArray[1])
  344.     timeLeft = goalCompletionTime
  345.     resetStuff()
  346.     makeObjectives()
  347.     currentObjective = pickNewObjective()
  348.     findItem()
  349.     givePointToEveryoneOnline(0)
  350.     sortedNames, sortedCounts = sortArray(playerPoints, "d")
  351.     term.clear()
  352. end
  353.  
  354. function main()
  355.     update()
  356.     screen()
  357.     os.sleep(1)
  358. end
  359.  
  360. function findItem()
  361.     correctTransposer = nil
  362.     local s = {sides.north, sides.east, sides.south, sides.west}
  363.     for i = 1,#transposer do
  364.         for j = 1, #s do
  365.             size, error = transposer[i].getInventorySize(s[j])
  366.             if error ~= "no inventory" then
  367.                 for k = 2,5 do
  368.                     local itemLabel = transposer[i].getStackInSlot(s[j], k).label
  369.                     while string.find(itemLabel, "§") do
  370.                         itemLabel = string.sub(itemLabel, 1, string.find(itemLabel, "§")-1) .. string.sub(itemLabel, string.find(itemLabel, "§")+3)
  371.                     end
  372.                     if itemLabel == currentObjective[1] then
  373.                         correctDrawerSide = s[j]
  374.                         correctTransposer = transposer[i]
  375.                         correctSlot = k
  376.                         return
  377.                     end
  378.                 end
  379.             end
  380.         end
  381.     end
  382.     throwError("finditem() "..correctSlot)
  383. end
  384.  
  385. function debugLog(str)
  386.         fileWrite("debug.log", str, false)
  387. end
  388.  
  389. function loadPoints()
  390.     lineArray = {}
  391.     playerPoints = {}
  392.     debugLog("attempting to read file 'points.txt'")
  393.     lineArray = fileRead("points.txt")
  394.     debugLog("Succesfully read file")
  395.     debugLog("")
  396.     for i = 1, #lineArray do
  397.         line = lineArray[i]
  398.         local a = string.find(line, ":")
  399.         local pointer = string.sub(line, 1, a-1)
  400.         local value = string.sub(line, a+1)
  401.         playerPoints[pointer] = value
  402.         debugLog("Assigned '" .. value .. "' to '" .. pointer .. "' in 'PlayerPoints'")
  403.     end
  404.     for k,v in pairs(playerPoints) do print(k,v) end
  405.     --event.pull("touch")
  406. end
  407.  
  408. function givePointToEveryoneOnline(toAdd)
  409.     lineArray = {}
  410.     playerPoints = {}
  411.     debugLog("attempting to read file 'points.txt'")
  412.     lineArray = fileRead("points.txt")
  413.     debugLog("Succesfully read file")
  414.     debugLog("")
  415.     for i = 1, #lineArray do
  416.         line = lineArray[i]
  417.         local a = string.find(line, ":")
  418.         local pointer = string.sub(line, 1, a-1)
  419.         local value = string.sub(line, a+1)
  420.         playerPoints[pointer] = value
  421.         debugLog("Assigned '" .. value .. "' to '" .. pointer .. "' in 'PlayerPoints'")
  422.     end
  423.     debugLog("")
  424.     onlinePlayers = debugCard.getPlayers()
  425.     for i = 1, #onlinePlayers do debugLog("Player " .. onlinePlayers[i] .. " is online and has been found") end
  426.     debugLog("")
  427.     for i = 1, #onlinePlayers do
  428.         player = tostring(onlinePlayers[i])
  429.         currentValue = playerPoints[player]
  430.         if currentValue == nil then currentValue = 0 end
  431.         newValue = currentValue + toAdd
  432.         debugLog("Player '" .. player .. "' now has '" .. newValue .. "' points")
  433.         playerPoints[player] = newValue
  434.     end
  435.     debugLog("")
  436.     if fs.exists("/home/points.txt") then fs.remove("/home/points.txt") end
  437.     for k,v in pairs(playerPoints) do
  438.         fileWrite("points.txt", k .. ":" .. v, false)
  439.         debugLog("Written '" .. k .. ":" .. v .."' to file 'points.txt'")
  440.     end
  441.     debugLog("")
  442.     debugLog("Finished data manipulation")
  443.     sortedNames, sortedCounts = sortArray(playerPoints, "d")
  444. end
  445.  
  446. function sortArray(array, mode)
  447.     local i = 0
  448.     local pointers = {}
  449.     local data = {}
  450.     local arrayCopy = {}
  451.     for k,v in pairs(array) do
  452.         arrayCopy[k] = v
  453.     end
  454.     for k,v in pairs(arrayCopy) do
  455.         pointers[i] = k
  456.         data[i] = v
  457.         i = i + 1
  458.     end
  459.     mode = mode or "a"
  460.     if mode == "d" then
  461.         for i = 0, #data do
  462.             for j = 0, #data - i - 1 do
  463.                 local a = tonumber(data[j])
  464.                 local b = tonumber(data[j+1])
  465.                 local c = pointers[j]
  466.                 local d = pointers[j+1]
  467.                 if a < b then
  468.                     data[j] = b
  469.                     pointers[j] = d
  470.                     data[j+1] = a
  471.                     pointers[j+1] = c
  472.                 end
  473.             end
  474.         end
  475.         return pointers, data
  476.     else
  477.         for i = 0, #data do
  478.             for j = 0, #data - i - 1 do
  479.                 local a = data[j]
  480.                 local b = data[j+1]
  481.                 local c = pointers[j]
  482.                 local d = pointers[j+1]
  483.                 if a > b then
  484.                     data[j] = b
  485.                     pointers[j] = d
  486.                     data[j+1] = a
  487.                     pointers[j+1] = c
  488.                 end
  489.             end
  490.         end
  491.         return pointers, data
  492.     end
  493.     return nil
  494. end
  495.  
  496. function flushDrawers()
  497.     component.proxy(component.get(redstoneFlush)).setOutput(redstoneFlushSide, 15)
  498.     repeat
  499.         os.sleep(1)
  500.     until correctTransposer.getStackInSlot(correctDrawerSide, correctSlot).size == 0
  501.     component.proxy(component.get(redstoneFlush)).setOutput(redstoneFlushSide, 0)
  502. end
  503.  
  504. function checkItem()
  505.     local transposerAmount = correctTransposer.getStackInSlot(correctDrawerSide, correctSlot).size
  506.     if transposerAmount >= currentObjective[2]*multiplier then
  507.         storedAmount = transposerAmount
  508.         filledPercentage = 1
  509.         screen()
  510.         flushDrawers()
  511.         newGoal()
  512.         return nil
  513.     end
  514.     return transposerAmount
  515. end
  516.  
  517. function newGoal()
  518.     completedObjective()
  519.     displaySleepTime(height - 11,betweenGoalTime, textCol, secondaryCol, "Time left until next objective:", "")
  520.     currentObjective = pickNewObjective()
  521.     findItem()
  522.     timeLeft = goalCompletionTime
  523. end
  524.  
  525. function update()
  526.     storedAmount = checkItem()
  527.     if storedAmount ~= nil then
  528.         filledPercentage = storedAmount/(currentObjective[2]*multiplier)
  529.     else
  530.         filledPercentage = 0
  531.     end
  532.     timeLeft = timeLeft - 1
  533.     if timeLeft == -1 then
  534.             component.proxy(component.get(redstoneFlush)).setOutput(redstoneFlushSide, 15)
  535.             os.sleep(5)
  536.             component.proxy(component.get(redstoneFlush)).setOutput(redstoneFlushSide, 0)
  537.         os.execute("reboot")
  538.     end
  539. end
  540.  
  541. function centerText(str, x1, x2, y, FGCol, BGCol)
  542.     local w,_ = gpu.getResolution()
  543.     x1 = x1 or 1
  544.     x2 = x2 or w
  545.     y = y or 1
  546.     str = str or "text"
  547.     FGCol = FGCol or 0xffffff
  548.     BGCol = BGCol or 0x000000
  549.     local prevFG = gpu.getForeground()
  550.     local prevBG = gpu.getBackground()
  551.     local l = string.len(tostring(str))
  552.     local center = math.floor((x1+x2)/2)
  553.     local startPos = math.ceil(center - (l-1)/2)
  554.     gpu.setForeground(FGCol)
  555.     gpu.setBackground(BGCol)
  556.     gpu.set(startPos,y,str)
  557.     gpu.setForeground(prevFG)
  558.     gpu.setBackground(prevBG)
  559. end
  560.  
  561. function displaySleepTime(y,toSleep, txtcol, bgcol, textToShowPre, textToShowPost)
  562.     repeat
  563.         centerText("     " .. textToShowPre .. " " .. math.floor(toSleep/60) .. " minutes and " .. toSleep%60 .. " seconds" .. textToShowPost .. "   ", 1 + leftOffset, width, y, txtcol, bgcol)
  564.         toSleep = toSleep - 1
  565.         os.sleep(1)
  566.     until toSleep == -1
  567. end
  568.  
  569. function screen()
  570.     --if currentTier == 1 then
  571.         primaryCol = colorTable.uncommon.PrimaryCol
  572.         secondaryCol = colorTable.uncommon.SecondaryCol
  573.         textCol = colorTable.uncommon.textCol
  574.         progressFilled = colorTable.uncommon.progressFilled
  575.         progressEmpty = colorTable.uncommon.progressEmpty
  576.     --end
  577.     if currentTier == 2 then
  578.         primaryCol = colorTable.rare.PrimaryCol
  579.         secondaryCol = colorTable.rare.SecondaryCol
  580.         textCol = colorTable.rare.textCol
  581.         progressFilled = colorTable.rare.progressFilled
  582.         progressEmpty = colorTable.rare.progressEmpty
  583.     end
  584.     if currentTier == 3 then
  585.         primaryCol = colorTable.epic.PrimaryCol
  586.         secondaryCol = colorTable.epic.SecondaryCol
  587.         textCol = colorTable.epic.textCol
  588.         progressFilled = colorTable.epic.progressFilled
  589.         progressEmpty = colorTable.epic.progressEmpty
  590.     end
  591.     if currentTier == 4 then
  592.         primaryCol = colorTable.legendary.PrimaryCol
  593.         secondaryCol = colorTable.legendary.SecondaryCol
  594.         textCol = colorTable.legendary.textCol
  595.         progressFilled = colorTable.legendary.progressFilled
  596.         progressEmpty = colorTable.legendary.progressEmpty
  597.     end
  598.     addRect(1 + leftOffset,1,width,height,primaryCol)
  599.     addRect(8 + leftOffset,4,width-8,height-4,secondaryCol)
  600.     gpu.setBackground(primaryCol)
  601.     gpu.setForeground(textCol)
  602.     addProgressBar(12 + leftOffset,height - 10,width - 12,height - 6,2,1,primaryCol,progressFilled,progressEmpty,0x000000,"",filledPercentage,true,false)
  603.    
  604.     centerText("COMMUNITY CHALLENGE", 1 + leftOffset, width, 5, textCol, secondaryCol)
  605.     centerText("Work together to complete this challenge", 1 + leftOffset, width, 7, textCol, secondaryCol)
  606.     centerText("And everyone online will be rewarded!", 1 + leftOffset, width, 9, textCol, secondaryCol)
  607.     centerText("The current tier: " .. currentTier .. " - " .. subObjective, 1 + leftOffset, width, 11, textCol, secondaryCol)
  608.    
  609.     centerText("Deliver " .. currentObjective[2]*multiplier .. " of " .. currentObjective[1] .. " to our community chest!", 1 + leftOffset, width, height - 12, textCol, secondaryCol)
  610.     centerText("Time remaining: " .. timeLeft, 1 + leftOffset, width, height - 11, textCol, secondaryCol)
  611.     if storedAmount ~= nil then
  612.         centerText("Current objective is at: ".. storedAmount .." / ".. currentObjective[2]*multiplier, 1 + leftOffset, width, height-5, textCol, secondaryCol)
  613.     end
  614.     addRect(1,1,leftOffset,height,primaryCol)
  615.     if sortedNames~= nil then
  616.         for i = 0, math.min(height-8,#sortedNames) do
  617.             gpu.set(1,i+4,i+1 ..  ". " .. sortedNames[i] .. ": " .. sortedCounts[i])
  618.         end
  619.     end
  620. end
  621.  
  622. init()
  623. repeat
  624.     main()
  625. until false
Advertisement
Add Comment
Please, Sign In to add comment