Advertisement
zeplintwo

lavaStore

Feb 23rd, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.24 KB | None | 0 0
  1. os.loadAPI("button")
  2. local slots = {}
  3. local gold = 0
  4. local diamond = 0
  5. local selectedSlot = 0
  6. local sysTime = os.clock()
  7. local addingTime = false
  8.  
  9. m = peripheral.wrap("back")
  10.  
  11. function mainMenu()
  12.  print("mainMenu")
  13.  m.clear()
  14.  m.setTextScale(1)
  15.  button.clearTable()
  16.  button.setTable("Slot 1", showSlot, 1, 2, 8, 3, 3)
  17.  button.setTable("Slot 2", showSlot, 2, 2, 8, 5, 5)
  18.  button.setTable("Slot 3", showSlot, 3, 2, 8, 7, 7)
  19.  button.setTable("Slot 4", showSlot, 4, 2, 8, 9, 9)
  20.  button.setTable("Slot 5", showSlot, 5, 2, 8, 11, 11)
  21.  button.setTable("Slot 6", showSlot, 6, 12, 18, 3, 3)
  22.  button.setTable("Slot 7", showSlot, 7, 12, 18, 5, 5)
  23.  button.setTable("Slot 8", showSlot, 8, 12, 18, 7, 7)
  24.  button.setTable("Slot 9", showSlot, 9, 12, 18, 9, 9)
  25.  button.setTable("Slot 10", showSlot, 10, 12, 18, 11, 11)
  26.  button.setTable("Slot 11", showSlot, 11, 22, 28, 3, 3)
  27.  button.setTable("Slot 12", showSlot, 12, 22, 28, 5, 5)
  28.  button.setTable("Slot 13", showSlot, 13, 22, 28, 7, 7)
  29.  button.setTable("Slot 14", showSlot, 14, 22, 28, 9, 9)
  30.  button.setTable("Slot 15", showSlot, 15, 22, 28, 11, 11)
  31.  button.setTable("Page 2", mainMenu2, "", 18, 25, 12, 12)
  32.  button.label(3, 1, "Welcome to the Lava Store")
  33.  for i=1,15 do
  34.   if slots[i]["exp"] > 0 then
  35.    button.toggleButton("Slot "..i)
  36.   end
  37.  end
  38.  button.screen()
  39. end
  40.  
  41. function mainMenu2()
  42.  print("mainMenu2")
  43.  m.clear()
  44.  m.setTextScale(1)
  45.  button.clearTable()
  46.  button.setTable("Slot 16", showSlot, 16, 2, 8, 3, 3)
  47.  button.setTable("Slot 17", showSlot, 17, 2, 8, 5, 5)
  48.  button.setTable("Slot 18", showSlot, 18, 2, 8, 7, 7)
  49.  button.setTable("Slot 19", showSlot, 19, 2, 8, 9, 9)
  50.  button.setTable("Slot 20", showSlot, 20, 2, 8, 11, 11)
  51.  button.setTable("Slot 21", showSlot, 21, 12, 18, 3, 3)
  52.  button.setTable("Slot 22", showSlot, 22, 12, 18, 5, 5)
  53.  button.setTable("Slot 23", showSlot, 23, 12, 18, 7, 7)
  54.  button.setTable("Slot 24", showSlot, 24, 12, 18, 9, 9)
  55.  button.setTable("Slot 25", showSlot, 25, 12, 18, 11, 11)
  56.  button.setTable("Slot 26", showSlot, 26, 22, 28, 3, 3)
  57.  button.setTable("Slot 27", showSlot, 27, 22, 28, 5, 5)
  58.  button.setTable("Slot 28", showSlot, 28, 22, 28, 7, 7)
  59.  button.setTable("Slot 29", showSlot, 29, 22, 28, 9, 9)
  60.  button.setTable("Slot 30", showSlot, 30, 22, 28, 11, 11)
  61.  button.setTable("Page 1", mainMenu, "", 18, 25, 12, 12)
  62.  button.label(3, 1, "Welcome to the Lava Store")
  63.  for i=16,30 do
  64.   if slots[i]["exp"] > 0 then
  65.    button.toggleButton("Slot "..i)
  66.   end
  67.  end
  68.  button.screen()
  69. end
  70.  
  71.  
  72. function showSlot(slot)
  73.  print("showSlot "..slot)
  74.  redstone.setBundledOutput("bottom", colors.red)
  75.  m.clear()
  76.  m.setTextScale(1)
  77.  button.clearTable()
  78.  button.label(6, 1, "Lava Store Slot "..slot)
  79.  button.setTable("Add Time", addTime, slot, 10, 22, 5, 7)
  80.  button.setTable("Main Menu", mainMenu, "", 10, 22, 9, 11)
  81.  local time = 0
  82.  if slots[slot]["exp"] then
  83.   time = math.floor((slots[slot]["exp"]/60)/60)
  84.  end
  85.  button.label(4, 3, time.." Hours")
  86.  button.screen()
  87. end
  88.  
  89. function addTime(slot)
  90.  print("addTime "..slot)
  91.  selectedSlot = slot
  92.  showChest()
  93.  m.clear()
  94.  button.clearTable()
  95.  button.label(5, 1, "Adding Time to Slot "..slot)
  96.  button.label(5, 3, "Gold Ingot - 12 hours")
  97.  button.label(5, 4, "Diamond - 48 hours")
  98.  button.setTable("Deposit", depost, slot, 3, 14, 9, 11)
  99.  button.setTable("Cancel", hideChest, slot, 16, 27, 9, 11)
  100.  button.screen()
  101. end
  102.  
  103. function depost(slot)
  104.  print("depost "..slot)
  105.  redstone.setBundledOutput("bottom", colors.green + colors.blue)
  106.  m.clear()
  107.  button.clearTable()
  108.  button.label(5, 1, "Adding Time to Slot "..slot)
  109.  button.label(7, 7, "Processing...")
  110.  hideChest(-1)
  111. end
  112.  
  113. function updateTime()
  114. -- print("updateTime")
  115.  local addTime = 0
  116.  addTime = addTime + (gold * 12 * 60 * 60)
  117.  addTime = addTime + (diamond * 48 * 60 * 60)
  118.  slots[selectedSlot]["exp"] = slots[selectedSlot]["exp"] + addTime
  119.  saveTimes()
  120.  gold = 0
  121.  diamond = 0
  122. end
  123.  
  124. function getEvent()
  125.  print("getEvent")
  126.  event, side, x, y = os.pullEvent()
  127.  if event == "monitor_touch" then
  128.   button.checkxy(x, y)
  129.  elseif event == "redstone" then
  130.   getRedstone()
  131.  else
  132.   sleep(0.5)
  133.  end
  134. end
  135.  
  136. function getRedstone()
  137.  print("getRedstone")
  138.  if colors.test(redstone.getBundledInput("left"), colors.gray) then
  139.   gold = gold + 1
  140.   print(gold.." Gold Ingots")
  141.  end
  142.  if colors.test(redstone.getBundledInput("left"), colors.pink) then
  143.   diamond = diamond + 1
  144.   print(diamond.."  Diamonds")
  145.  end
  146.  if colors.test(redstone.getBundledInput("left"), colors.yellow) then
  147.   subtTime()
  148.   return
  149.  end
  150.  if redstone.getBundledInput("left") == colors.green and selectedSlot > 0 and addingTime then
  151.   updateTime()
  152.   showSlot(selectedSlot)
  153.   addingTime = false
  154.  end
  155. end
  156.  
  157. function subtTime()
  158.  print("subTime")
  159.  local newTime = os.clock()
  160.  local timeDiff = newTime - sysTime
  161.  print(timeDiff)
  162.  for i=1,30 do
  163.   if slots[i]["exp"] > timeDiff then
  164.    slots[i]["exp"] = slots[i]["exp"] - timeDiff
  165.   else
  166.    slots[i]["exp"] = 0
  167.   end
  168.  end
  169.  sysTime = os.clock()
  170.  saveTimes()
  171. end
  172.  
  173. function showChest()
  174. -- print("showChest")
  175.  gold = 0
  176.  diamond = 0
  177.  redstone.setBundledOutput("bottom", 0)
  178.  redstone.setBundledOutput("bottom", colors.gray)
  179. end
  180.  
  181. function hideChest(slot)
  182. -- print("hideChest "..slot)
  183.  redstone.setBundledOutput("bottom", 0)
  184.  redstone.setBundledOutput("bottom", colors.blue)
  185.  redstone.setBundledOutput("bottom", colors.pink + colors.blue)
  186.  sleep(4)
  187.  redstone.setBundledOutput("bottom", colors.red + colors.blue)
  188.  if slot > 0 then
  189.   selectedSlot = 0
  190.   showSlot(slot)
  191.  elseif slot == -1 then
  192.   sleep(3)
  193.   addingTime = true
  194.   redstone.setBundledOutput("bottom", colors.red + colors.green + colors.blue)
  195.   sleep(1)
  196.  end
  197. end
  198.  
  199. function getTimes()
  200. -- print("getTimes")
  201.  local file = io.open("accounts", "r")
  202.  local tempData = ""
  203.  if not file then
  204.   file = io.open("accounts", "w")
  205.   file:flush()
  206.   file:close()
  207.   file = io.open("accounts", "r")
  208.  end
  209.  for line in file:lines() do
  210.   tempData = tempData..line
  211.  end
  212.  file:close()
  213.  if tempData ~= "" then
  214.   slots = textutils.unserialize(tempData)
  215.  else
  216.   file = io.open("accounts_bu", "r")
  217.   tempData = ""
  218.   if not file then
  219.    file = io.open("accounts_bu", "w")
  220.    file:flush()
  221.    file:close()
  222.    file = io.open("accounts_bu", "r")
  223.   end
  224.   for line in file:lines() do
  225.    tempData = tempData..line
  226.   end
  227.   if tempData ~= "" then
  228.    slots = textutils.unserialize(tempData)
  229.   else
  230.    for i=1,30 do
  231.     slots[i] = {}
  232.     slots[i]["exp"] = 0
  233.    end
  234.   end
  235.   saveTimes()
  236.  end
  237.  return(slots)
  238. end
  239.  
  240. function saveTimes()
  241. -- print("saveTimes")
  242.  local file = io.open("accounts", "w")
  243.  local data = textutils.serialize(slots)
  244.  file:write(data)
  245.  file:flush()
  246.  file:close()
  247.  file = io.open("accounts_bu", "w")
  248.  file:write(data)
  249.  file:flush()
  250.  file:close()
  251.  updateOutputs()
  252. end
  253.  
  254. function updateOutputs()
  255.  print("updateOutputs")
  256.  local output = 0
  257.  local topOutput = 0
  258.  if slots[1]["exp"] > 0 then
  259.   output = output + 1
  260.  end
  261.  if slots[2]["exp"] > 0 then
  262.   output = output + 2
  263.  end
  264.  if slots[3]["exp"] > 0 then
  265.   output = output + 4
  266.  end
  267.  if slots[4]["exp"] > 0 then
  268.   output = output + 8
  269.  end
  270.  if slots[5]["exp"] > 0 then
  271.   output = output + 16
  272.  end
  273.  if slots[6]["exp"] > 0 then
  274.   output = output + 32
  275.  end
  276.  if slots[7]["exp"] > 0 then
  277.   output = output + 64
  278.  end
  279.  if slots[8]["exp"] > 0 then
  280.   output = output + 128
  281.  end
  282.  if slots[9]["exp"] > 0 then
  283.   output = output + 256
  284.  end
  285.  if slots[10]["exp"] > 0 then
  286.   output = output + 512
  287.  end
  288.  if slots[11]["exp"] > 0 then
  289.   output = output + 1024
  290.  end
  291.  if slots[12]["exp"] > 0 then
  292.   output = output + 2048
  293.  end
  294.  if slots[13]["exp"] > 0 then
  295.   output = output + 4096
  296.  end
  297.  if slots[14]["exp"] > 0 then
  298.   output = output + 8192
  299.  end
  300.  if slots[15]["exp"] > 0 then
  301.   output = output + 16384
  302.  end
  303.  if slots[16]["exp"] > 0 then
  304.   topOutput = topOutput + 1
  305.  end
  306.  if slots[17]["exp"] > 0 then
  307.   topOutput = topOutput + 2
  308.  end
  309.  if slots[18]["exp"] > 0 then
  310.   topOutput = topOutput + 4
  311.  end
  312.  if slots[19]["exp"] > 0 then
  313.   topOutput = topOutput + 8
  314.  end
  315.  if slots[20]["exp"] > 0 then
  316.   topOutput = topOutput + 16
  317.  end
  318.  if slots[21]["exp"] > 0 then
  319.   topOutput = topOutput + 32
  320.  end
  321.  if slots[22]["exp"] > 0 then
  322.   topOutput = topOutput + 64
  323.  end
  324.  if slots[23]["exp"] > 0 then
  325.   topOutput = topOutput + 128
  326.  end
  327.  if slots[24]["exp"] > 0 then
  328.   topOutput = topOutput + 256
  329.  end
  330.  if slots[25]["exp"] > 0 then
  331.   topOutput = topOutput + 512
  332.  end
  333.  if slots[26]["exp"] > 0 then
  334.   topOutput = topOutput + 1024
  335.  end
  336.  if slots[27]["exp"] > 0 then
  337.   topOutput = topOutput + 2048
  338.  end
  339.  if slots[28]["exp"] > 0 then
  340.   topOutput = topOutput + 4096
  341.  end
  342.  if slots[29]["exp"] > 0 then
  343.   topOutput = topOutput + 8192
  344.  end
  345.  if slots[30]["exp"] > 0 then
  346.   topOutput = topOutput + 16384
  347.  end
  348. -- print(output)
  349. -- print(topOutput)
  350.  redstone.setBundledOutput("right", output)
  351.  redstone.setBundledOutput("top", topOutput)
  352. end
  353.  
  354. function startUp()
  355.  print("startUp")
  356.  hideChest(0)
  357.  updateOutputs()
  358. end
  359.  
  360. function fixAccts()
  361.  print("fixAccts")
  362.  for i=16,30 do
  363.   slots[i] = {}
  364.   slots[i]["exp"] = 0
  365.  end
  366.  saveTimes()
  367. end
  368.  
  369.  
  370. --fixAccts()
  371. --print(slots[1]['exp'])
  372. getTimes()
  373. --slots[14]["exp"] = 604800
  374. --slots[15]["exp"] = 604800
  375. --slots[3]["exp"] = 50040000
  376. --slots[13]["exp"] = 604800
  377.  
  378. startUp()
  379. mainMenu()
  380. while true do
  381.  getEvent()
  382. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement