Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("button")
- local slots = {}
- local gold = 0
- local diamond = 0
- local selectedSlot = 0
- local sysTime = os.clock()
- local addingTime = false
- m = peripheral.wrap("back")
- function mainMenu()
- print("mainMenu")
- m.clear()
- m.setTextScale(1)
- button.clearTable()
- button.setTable("Slot 1", showSlot, 1, 2, 8, 3, 3)
- button.setTable("Slot 2", showSlot, 2, 2, 8, 5, 5)
- button.setTable("Slot 3", showSlot, 3, 2, 8, 7, 7)
- button.setTable("Slot 4", showSlot, 4, 2, 8, 9, 9)
- button.setTable("Slot 5", showSlot, 5, 2, 8, 11, 11)
- button.setTable("Slot 6", showSlot, 6, 12, 18, 3, 3)
- button.setTable("Slot 7", showSlot, 7, 12, 18, 5, 5)
- button.setTable("Slot 8", showSlot, 8, 12, 18, 7, 7)
- button.setTable("Slot 9", showSlot, 9, 12, 18, 9, 9)
- button.setTable("Slot 10", showSlot, 10, 12, 18, 11, 11)
- button.setTable("Slot 11", showSlot, 11, 22, 28, 3, 3)
- button.setTable("Slot 12", showSlot, 12, 22, 28, 5, 5)
- button.setTable("Slot 13", showSlot, 13, 22, 28, 7, 7)
- button.setTable("Slot 14", showSlot, 14, 22, 28, 9, 9)
- button.setTable("Slot 15", showSlot, 15, 22, 28, 11, 11)
- button.setTable("Page 2", mainMenu2, "", 18, 25, 12, 12)
- button.label(3, 1, "Welcome to the Lava Store")
- for i=1,15 do
- if slots[i]["exp"] > 0 then
- button.toggleButton("Slot "..i)
- end
- end
- button.screen()
- end
- function mainMenu2()
- print("mainMenu2")
- m.clear()
- m.setTextScale(1)
- button.clearTable()
- button.setTable("Slot 16", showSlot, 16, 2, 8, 3, 3)
- button.setTable("Slot 17", showSlot, 17, 2, 8, 5, 5)
- button.setTable("Slot 18", showSlot, 18, 2, 8, 7, 7)
- button.setTable("Slot 19", showSlot, 19, 2, 8, 9, 9)
- button.setTable("Slot 20", showSlot, 20, 2, 8, 11, 11)
- button.setTable("Slot 21", showSlot, 21, 12, 18, 3, 3)
- button.setTable("Slot 22", showSlot, 22, 12, 18, 5, 5)
- button.setTable("Slot 23", showSlot, 23, 12, 18, 7, 7)
- button.setTable("Slot 24", showSlot, 24, 12, 18, 9, 9)
- button.setTable("Slot 25", showSlot, 25, 12, 18, 11, 11)
- button.setTable("Slot 26", showSlot, 26, 22, 28, 3, 3)
- button.setTable("Slot 27", showSlot, 27, 22, 28, 5, 5)
- button.setTable("Slot 28", showSlot, 28, 22, 28, 7, 7)
- button.setTable("Slot 29", showSlot, 29, 22, 28, 9, 9)
- button.setTable("Slot 30", showSlot, 30, 22, 28, 11, 11)
- button.setTable("Page 1", mainMenu, "", 18, 25, 12, 12)
- button.label(3, 1, "Welcome to the Lava Store")
- for i=16,30 do
- if slots[i]["exp"] > 0 then
- button.toggleButton("Slot "..i)
- end
- end
- button.screen()
- end
- function showSlot(slot)
- print("showSlot "..slot)
- redstone.setBundledOutput("bottom", colors.red)
- m.clear()
- m.setTextScale(1)
- button.clearTable()
- button.label(6, 1, "Lava Store Slot "..slot)
- button.setTable("Add Time", addTime, slot, 10, 22, 5, 7)
- button.setTable("Main Menu", mainMenu, "", 10, 22, 9, 11)
- local time = 0
- if slots[slot]["exp"] then
- time = math.floor((slots[slot]["exp"]/60)/60)
- end
- button.label(4, 3, time.." Hours")
- button.screen()
- end
- function addTime(slot)
- print("addTime "..slot)
- selectedSlot = slot
- showChest()
- m.clear()
- button.clearTable()
- button.label(5, 1, "Adding Time to Slot "..slot)
- button.label(5, 3, "Gold Ingot - 12 hours")
- button.label(5, 4, "Diamond - 48 hours")
- button.setTable("Deposit", depost, slot, 3, 14, 9, 11)
- button.setTable("Cancel", hideChest, slot, 16, 27, 9, 11)
- button.screen()
- end
- function depost(slot)
- print("depost "..slot)
- redstone.setBundledOutput("bottom", colors.green + colors.blue)
- m.clear()
- button.clearTable()
- button.label(5, 1, "Adding Time to Slot "..slot)
- button.label(7, 7, "Processing...")
- hideChest(-1)
- end
- function updateTime()
- -- print("updateTime")
- local addTime = 0
- addTime = addTime + (gold * 12 * 60 * 60)
- addTime = addTime + (diamond * 48 * 60 * 60)
- slots[selectedSlot]["exp"] = slots[selectedSlot]["exp"] + addTime
- saveTimes()
- gold = 0
- diamond = 0
- end
- function getEvent()
- print("getEvent")
- event, side, x, y = os.pullEvent()
- if event == "monitor_touch" then
- button.checkxy(x, y)
- elseif event == "redstone" then
- getRedstone()
- else
- sleep(0.5)
- end
- end
- function getRedstone()
- print("getRedstone")
- if colors.test(redstone.getBundledInput("left"), colors.gray) then
- gold = gold + 1
- print(gold.." Gold Ingots")
- end
- if colors.test(redstone.getBundledInput("left"), colors.pink) then
- diamond = diamond + 1
- print(diamond.." Diamonds")
- end
- if colors.test(redstone.getBundledInput("left"), colors.yellow) then
- subtTime()
- return
- end
- if redstone.getBundledInput("left") == colors.green and selectedSlot > 0 and addingTime then
- updateTime()
- showSlot(selectedSlot)
- addingTime = false
- end
- end
- function subtTime()
- print("subTime")
- local newTime = os.clock()
- local timeDiff = newTime - sysTime
- print(timeDiff)
- for i=1,30 do
- if slots[i]["exp"] > timeDiff then
- slots[i]["exp"] = slots[i]["exp"] - timeDiff
- else
- slots[i]["exp"] = 0
- end
- end
- sysTime = os.clock()
- saveTimes()
- end
- function showChest()
- -- print("showChest")
- gold = 0
- diamond = 0
- redstone.setBundledOutput("bottom", 0)
- redstone.setBundledOutput("bottom", colors.gray)
- end
- function hideChest(slot)
- -- print("hideChest "..slot)
- redstone.setBundledOutput("bottom", 0)
- redstone.setBundledOutput("bottom", colors.blue)
- redstone.setBundledOutput("bottom", colors.pink + colors.blue)
- sleep(4)
- redstone.setBundledOutput("bottom", colors.red + colors.blue)
- if slot > 0 then
- selectedSlot = 0
- showSlot(slot)
- elseif slot == -1 then
- sleep(3)
- addingTime = true
- redstone.setBundledOutput("bottom", colors.red + colors.green + colors.blue)
- sleep(1)
- end
- end
- function getTimes()
- -- print("getTimes")
- local file = io.open("accounts", "r")
- local tempData = ""
- if not file then
- file = io.open("accounts", "w")
- file:flush()
- file:close()
- file = io.open("accounts", "r")
- end
- for line in file:lines() do
- tempData = tempData..line
- end
- file:close()
- if tempData ~= "" then
- slots = textutils.unserialize(tempData)
- else
- file = io.open("accounts_bu", "r")
- tempData = ""
- if not file then
- file = io.open("accounts_bu", "w")
- file:flush()
- file:close()
- file = io.open("accounts_bu", "r")
- end
- for line in file:lines() do
- tempData = tempData..line
- end
- if tempData ~= "" then
- slots = textutils.unserialize(tempData)
- else
- for i=1,30 do
- slots[i] = {}
- slots[i]["exp"] = 0
- end
- end
- saveTimes()
- end
- return(slots)
- end
- function saveTimes()
- -- print("saveTimes")
- local file = io.open("accounts", "w")
- local data = textutils.serialize(slots)
- file:write(data)
- file:flush()
- file:close()
- file = io.open("accounts_bu", "w")
- file:write(data)
- file:flush()
- file:close()
- updateOutputs()
- end
- function updateOutputs()
- print("updateOutputs")
- local output = 0
- local topOutput = 0
- if slots[1]["exp"] > 0 then
- output = output + 1
- end
- if slots[2]["exp"] > 0 then
- output = output + 2
- end
- if slots[3]["exp"] > 0 then
- output = output + 4
- end
- if slots[4]["exp"] > 0 then
- output = output + 8
- end
- if slots[5]["exp"] > 0 then
- output = output + 16
- end
- if slots[6]["exp"] > 0 then
- output = output + 32
- end
- if slots[7]["exp"] > 0 then
- output = output + 64
- end
- if slots[8]["exp"] > 0 then
- output = output + 128
- end
- if slots[9]["exp"] > 0 then
- output = output + 256
- end
- if slots[10]["exp"] > 0 then
- output = output + 512
- end
- if slots[11]["exp"] > 0 then
- output = output + 1024
- end
- if slots[12]["exp"] > 0 then
- output = output + 2048
- end
- if slots[13]["exp"] > 0 then
- output = output + 4096
- end
- if slots[14]["exp"] > 0 then
- output = output + 8192
- end
- if slots[15]["exp"] > 0 then
- output = output + 16384
- end
- if slots[16]["exp"] > 0 then
- topOutput = topOutput + 1
- end
- if slots[17]["exp"] > 0 then
- topOutput = topOutput + 2
- end
- if slots[18]["exp"] > 0 then
- topOutput = topOutput + 4
- end
- if slots[19]["exp"] > 0 then
- topOutput = topOutput + 8
- end
- if slots[20]["exp"] > 0 then
- topOutput = topOutput + 16
- end
- if slots[21]["exp"] > 0 then
- topOutput = topOutput + 32
- end
- if slots[22]["exp"] > 0 then
- topOutput = topOutput + 64
- end
- if slots[23]["exp"] > 0 then
- topOutput = topOutput + 128
- end
- if slots[24]["exp"] > 0 then
- topOutput = topOutput + 256
- end
- if slots[25]["exp"] > 0 then
- topOutput = topOutput + 512
- end
- if slots[26]["exp"] > 0 then
- topOutput = topOutput + 1024
- end
- if slots[27]["exp"] > 0 then
- topOutput = topOutput + 2048
- end
- if slots[28]["exp"] > 0 then
- topOutput = topOutput + 4096
- end
- if slots[29]["exp"] > 0 then
- topOutput = topOutput + 8192
- end
- if slots[30]["exp"] > 0 then
- topOutput = topOutput + 16384
- end
- -- print(output)
- -- print(topOutput)
- redstone.setBundledOutput("right", output)
- redstone.setBundledOutput("top", topOutput)
- end
- function startUp()
- print("startUp")
- hideChest(0)
- updateOutputs()
- end
- function fixAccts()
- print("fixAccts")
- for i=16,30 do
- slots[i] = {}
- slots[i]["exp"] = 0
- end
- saveTimes()
- end
- --fixAccts()
- --print(slots[1]['exp'])
- getTimes()
- --slots[14]["exp"] = 604800
- --slots[15]["exp"] = 604800
- --slots[3]["exp"] = 50040000
- --slots[13]["exp"] = 604800
- startUp()
- mainMenu()
- while true do
- getEvent()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement