Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- file = fs.open("local-name", "r") --read user
- name = file.readLine()
- file.close()
- function calc_color(color)
- return math.pow(2, color - 1)
- end
- function msg(gap, line, color, groundb, text)
- term.setBackgroundColor(calc_color(groundb))
- term.setCursorPos(gap,line)
- term.setTextColor(calc_color(color))
- text = term.write(text)
- end
- function RequestItems()
- -- CONSTANTS
- local INTERVAL = 1
- local PIPE_SIDE = "back"
- local REQUEST_IDS = {
- -- Beispiel für IDs mit Varianten
- [2491] = {
- ["2491:7"] = Output_AE_Amount, --AE Output + Menge
- },
- [20261] = {
- ["20261:69"] = Output_Shiny_Amount, --Shiny Output + Menge
- },
- [254] = {
- ["254:6"] = Output_Tungsten_Amount, --Tungsten Output + Menge
- },
- }
- -- IMPLEMENTATION
- function convertNBT(nbt)
- local conv = {}
- if (nbt == nil) then
- return nil
- elseif (nbt["type"] == "NBTTagCompound") or (nbt["type"] == "NBTTagList") then
- for key, value in pairs(nbt["value"]) do
- conv[key] = convertNBT(value)
- end
- else
- conv = nbt["value"]
- end
- return conv
- end
- function getItems(pipe)
- pipe.getAvailableItems()
- local event, result = os.pullEvent("available_items_return")
- return result
- end
- function inList(item)
- local id = item.id
- local dmg = item.dmg
- local idKey = tostring(id)
- local exists, requestAmount = false, 0
- if REQUEST_IDS[id] then
- if type(REQUEST_IDS[id]) == "table" then
- local variantKey = idKey .. ":" .. tostring(dmg)
- if REQUEST_IDS[id][variantKey] then
- exists = true
- requestAmount = REQUEST_IDS[id][variantKey]
- end
- else
- exists = true
- requestAmount = REQUEST_IDS[id]
- end
- end
- return exists, requestAmount
- end
- -- MAIN
- local pipe = peripheral.wrap(PIPE_SIDE)
- while true do
- for i, result in pairs(getItems(pipe)) do
- local iid, amount = unpack(result)
- local item = {
- id = pipe.getItemID(iid),
- dmg = pipe.getItemDamage(iid),
- nbt = convertNBT(pipe.getNBTTagCompound(iid))
- }
- local exists, requestAmount = inList(item)
- if exists then
- pipe.makeRequest(iid, requestAmount)
- sleep(1)
- end
- end
- sleep(5)
- os.reboot()
- end
- end
- local function createFormatter()
- return function(input)
- local str = tostring(input)
- return (str .. string.rep(' ', 5 - #str)):sub(1, 5)
- end
- end
- function Output()
- local event, button, X, Y = os.pullEvent("mouse_click")
- if X >= 02 and X <= 06 and Y == 14 and (Output_AE_Amount+16) < AEs_Amount then --AE +16
- Output_AE_Amount = Output_AE_Amount + 16
- elseif X >= 02 and X <= 06 and Y == 15 and (Output_Shiny_Amount+16) < Shiny_Amount then --Shiny +16
- Output_Shiny_Amount = Output_Shiny_Amount + 16
- elseif X >= 02 and X <= 06 and Y == 16 and (Output_Tungsten_Amount+16) < Tungsten_Amount then --Tungsten +16
- Output_Tungsten_Amount = Output_Tungsten_Amount + 16
- elseif X >= 08 and X <= 11 and Y == 14 and Output_AE_Amount < AEs_Amount then --AE +1
- Output_AE_Amount = Output_AE_Amount + 1
- elseif X >= 08 and X <= 11 and Y == 15 and Output_Shiny_Amount < Shiny_Amount then --Shiny +1
- Output_Shiny_Amount = Output_Shiny_Amount + 1
- elseif X >= 08 and X <= 11 and Y == 16 and Output_Tungsten_Amount < Tungsten_Amount then --Tungsten +1
- Output_Tungsten_Amount = Output_Tungsten_Amount + 1
- elseif X >= 19 and X <= 22 and Y == 14 and Output_AE_Amount >= 1 then --AE -1
- Output_AE_Amount = Output_AE_Amount - 1
- elseif X >= 19 and X <= 22 and Y == 15 and Output_Shiny_Amount >= 1 then --Shiny -1
- Output_Shiny_Amount = Output_Shiny_Amount - 1
- elseif X >= 19 and X <= 22 and Y == 16 and Output_Tungsten_Amount >= 1 then --Tungsten -1
- Output_Tungsten_Amount = Output_Tungsten_Amount - 1
- elseif X >= 24 and X <= 28 and Y == 14 and Output_AE_Amount >= 16 then --AE -16
- Output_AE_Amount = Output_AE_Amount - 16
- elseif X >= 24 and X <= 28 and Y == 15 and Output_Shiny_Amount >= 16 then --Shiny -16
- Output_Shiny_Amount = Output_Shiny_Amount - 16
- elseif X >= 24 and X <= 28 and Y == 16 and Output_Tungsten_Amount >= 16 then --Tungsten +16
- Output_Tungsten_Amount = Output_Tungsten_Amount - 16
- elseif X >= 47 and X <= 52 and Y == 19 then --Back Button
- os.reboot()
- elseif X >= 02 and X <= 24 and Y == 19 then --Payout Button
- print(AEs_Amount)
- print(Output_AE_Amount)
- print(Shiny_Amount)
- print(Output_Shiny_Amount)
- print(Tungsten_Amount)
- print(Output_Tungsten_Amount)
- New_AEs_Amount = AEs_Amount - Output_AE_Amount
- New_Shiny_Amount = Shiny_Amount - Output_Shiny_Amount
- New_Tungsten_Amount = Tungsten_Amount - Output_Tungsten_Amount
- fs.delete("Users/" .. name)
- file = fs.open("Users/" .. name, "w")
- file.close()
- local file = fs.open("Users/" .. name, "a")
- file.write("Adjustable Emitter= " .. New_AEs_Amount .. "\n")
- file.write("Shiny Ingot= " .. New_Shiny_Amount .. "\n")
- file.write("Tungsten Ore= " .. New_Tungsten_Amount .. "\n")
- file.close()
- print(" ")
- print("addierte Werte:")
- print("AEs:", New_AEs_Amount)
- print("Shiny:", New_Shiny_Amount)
- print("Tungsten:", New_Tungsten_Amount)
- RequestItems()
- end
- updateNumber = createFormatter()
- msg(13,14,04,16, updateNumber(Output_AE_Amount))
- msg(13,15,04,16, updateNumber(Output_Shiny_Amount))
- msg(13,16,04,16, updateNumber(Output_Tungsten_Amount))
- Output()
- end
- function ladeItems()
- local datei = fs.open("Users/" .. name, "r") -- Datei im Lesemodus öffnen
- if not datei then
- print("Fehler: Datei konnte nicht geöffnet werden.")
- return
- end
- local items = {}
- -- Schleife durch jede Zeile der Datei
- repeat
- local zeile = datei.readLine()
- if zeile then
- -- Trenne den Itemnamen und die Menge anhand des Gleichheitszeichens
- local itemName, menge = zeile:match("([^=]+)%s*=%s*(%d+)")
- if itemName and menge then
- items[itemName] = tonumber(menge)
- else
- print("Fehlerhafte Zeile in der Datei: " .. zeile)
- end
- end
- until not zeile
- datei.close() -- Datei schließen
- return items
- end
- --Program Start--
- local itemTabelle = ladeItems()
- -- Beispiel: Verwendung der abgerufenen Informationen
- if itemTabelle then
- AEs_Amount = itemTabelle["Adjustable Emitter"]
- Shiny_Amount = itemTabelle["Shiny Ingot"]
- Tungsten_Amount = itemTabelle["Tungsten Ore"]
- msg(01,01,16,16," ")
- term.clear()
- msg(01,01,02,16," Account: "..name) --überschrift
- msg(01,02,08,16,"---------------------------------------------------")
- msg(14,04,06,16,"$$$ $$$")
- msg(18,04,05,16,"Trading-City Bank")
- msg(18,05,01,16,"~~~~~~~~~~~~~~~~~")
- msg(02,08,01,16,"Your Items:")
- msg(02,09,01,16,"~~~~~~~~~~~")
- msg(19,08,09,16," " .. AEs_Amount .. "x")
- msg(19,09,09,16," " .. Shiny_Amount .. "x")
- msg(19,10,09,16," " .. Tungsten_Amount .. "x")
- msg(01,18,08,16,"---------------------------------------------------")
- msg(47,19,16,01," back")
- msg(02,19,01,15," click here for payout ")
- msg(30,08,09,16,"Adjustable Emitters")
- msg(30,09,09,16,"Shiny Ingot")
- msg(30,10,09,16,"Tungste Ore")
- msg(30,14,09,16,"Adjustable Emitters")
- msg(30,15,09,16,"Shiny Ingot")
- msg(30,16,09,16,"Tungste Ore")
- msg(02,12,01,16,"Select Your Output:")
- msg(02,13,01,16,"~~~~~~~~~~~~~~~~~~~")
- customMaxLength = 5
- Output_AE_Amount = 0
- Output_Shiny_Amount = 0
- Output_Tungsten_Amount = 0
- for yPos = 14,16 do
- msg(02,yPos,01,15," +16 ")
- msg(08,yPos,01,15," +1 ")
- msg(13,yPos,04,16,"0 ")
- msg(19,yPos,01,15," -1 ")
- msg(24,yPos,01,15," -16 ")
- end
- Output()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement