Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function startup()
- if fs.exists("disk2") then
- fs.delete("disk/")
- end
- for k,v in pairs(peripheral.getNames()) do
- if peripheral.getType(peripheral.getNames()[k]) == "modem" then
- rednet.open(peripheral.getNames()[k])
- end
- end
- readingOutput = {}
- blinkIsOn = true
- scrollmenuLen={}
- scrollmenuInfos={}
- dropdown = {}
- dropdown["loaded"] = {}
- dropdown["loaded"]["len"] = 0
- orderQueue = {}
- shopItems = {
- {["name"]="Coal",["price"]=2,["category"]="ores",["slot"]=1,["chest"]=1},
- {["name"]="Iron Ingot",["price"]=5,["category"]="ores",["slot"]=2,["chest"]=1},
- {["name"]="Copper Ingot",["price"]=2,["category"]="ores",["slot"]=3,["chest"]=1},
- {["name"]="Gold Ingot",["price"]=6,["category"]="ores",["slot"]=4,["chest"]=1},
- {["name"]="Lapis Lazuli",["price"]=6,["category"]="ores",["slot"]=5,["chest"]=1},
- {["name"]="Redstone Dust",["price"]=6,["category"]="ores",["slot"]=6,["chest"]=1},
- {["name"]="Diamond",["price"]=10,["category"]="ores",["slot"]=7,["chest"]=1},
- {["name"]="Emerald",["price"]=13,["category"]="ores",["slot"]=8,["chest"]=1},
- {["name"]="Netherite Ingot",["price"]=25,["category"]="ores",["slot"]=9,["chest"]=1},
- {["name"]="Osmium Ingot",["price"]=5,["category"]="ores",["slot"]=10,["chest"]=1},
- {["name"]="Uranium Ingot",["price"]=7,["category"]="ores",["slot"]=11,["chest"]=1},
- {["name"]="Silver Ingot",["price"]=5,["category"]="ores",["slot"]=12,["chest"]=1},
- {["name"]="Aluminum Ingot",["price"]=5,["category"]="ores",["slot"]=13,["chest"]=1},
- {["name"]="Zinc Ingot",["price"]=5,["category"]="ores",["slot"]=14,["chest"]=1},
- {["name"]="Steel Ingot",["price"]=7,["category"]="ores",["slot"]=15,["chest"]=1},
- {["name"]="Electrum Ingot",["price"]=7,["category"]="ores",["slot"]=16,["chest"]=1},
- {["name"]="Manasteel Ingot",["price"]=10,["category"]={},["slot"]=17,["chest"]=1},
- {["name"]="Terrasteel Ingot",["price"]=20,["category"]={},["slot"]=18,["chest"]=1},
- {["name"]="Lead Ingot",["price"]=5,["category"]={},["slot"]=19,["chest"]=1},
- {["name"]="Nickel Ingot",["price"]=5,["category"]={},["slot"]=20,["chest"]=1},
- {["name"]="Platinum Ingot",["price"]=5,["category"]={},["slot"]=21,["chest"]=1},
- {["name"]="Tin Ingot",["price"]=5,["category"]={},["slot"]=22,["chest"]=1},
- {["name"]="Invar Ingot",["price"]=6,["category"]={},["slot"]=23,["chest"]=1},
- {["name"]="Bronze Ingot",["price"]=5,["category"]={},["slot"]=24,["chest"]=1},
- {["name"]="Enderium Ingot",["price"]=10,["category"]={},["slot"]=25,["chest"]=1},
- {["name"]="Lumium Ingot",["price"]=10,["category"]={},["slot"]=26,["chest"]=1},
- {["name"]="Signalum Ingot",["price"]=12,["category"]={},["slot"]=27,["chest"]=1},
- {["name"]="Constantan Ingot",["price"]=6,["category"]={},["slot"]=28,["chest"]=1},
- {["name"]="Brass Ingot",["price"]=5,["category"]={},["slot"]=29,["chest"]=1},
- {["name"]="Allthemodium Ingot",["price"]=200,["category"]={},["slot"]=30,["chest"]=1},
- {["name"]="Graphite Ingot",["price"]=3,["category"]={},["slot"]=31,["chest"]=1},
- {["name"]="Draconium Ingot",["price"]=8,["category"]={},["slot"]=32,["chest"]=1},
- {["name"]="Awakened Draconium Ingot",["price"]=30,["category"]={},["slot"]=33,["chest"]=1},
- {["name"]="Copper Alloy Ingot",["price"]=7,["category"]={},["slot"]=34,["chest"]=1},
- {["name"]="Energetic Alloy Ingot",["price"]=15,["category"]={},["slot"]=35,["chest"]=1},
- {["name"]="Vibrant Alloy Ingot",["price"]=18,["category"]={},["slot"]=36,["chest"]=1},
- {["name"]="Redstone Alloy Ingot",["price"]=8,["category"]={},["slot"]=37,["chest"]=1},
- {["name"]="Conductive Alloy Ingot",["price"]=13,["category"]={},["slot"]=38,["chest"]=1},
- {["name"]="Pulsating Alloy Ingot",["price"]=7,["category"]={},["slot"]=39,["chest"]=1},
- {["name"]="Dark Steel Ingot",["price"]=10,["category"]={},["slot"]=40,["chest"]=1},
- {["name"]="Soularium Ingot",["price"]=8,["category"]={},["slot"]=41,["chest"]=1},
- {["name"]="End Steel Ingot",["price"]=14,["category"]={},["slot"]=42,["chest"]=1},
- {["name"]="Deorum Ingot",["price"]=15,["category"]={},["slot"]=43,["chest"]=1},
- {["name"]="Obsidian Ingot",["price"]=5,["category"]={},["slot"]=44,["chest"]=1},
- {["name"]="Force Ingot",["price"]=7,["category"]={},["slot"]=45,["chest"]=1},
- {["name"]="Refined Obsidian Ingot",["price"]=14,["category"]={},["slot"]=46,["chest"]=1},
- {["name"]="Refined Glowstone Ingot",["price"]=12,["category"]={},["slot"]=47,["chest"]=1},
- {["name"]="Prosperity Ingot",["price"]=7,["category"]={},["slot"]=48,["chest"]=1},
- {["name"]="Inferium Ingot",["price"]=8,["category"]={},["slot"]=49,["chest"]=1},
- {["name"]="Prudentium Ingot",["price"]=10,["category"]={},["slot"]=50,["chest"]=1},
- {["name"]="Tertium Ingot",["price"]=13,["category"]={},["slot"]=51,["chest"]=1},
- {["name"]="Imperium Ingot",["price"]=18,["category"]={},["slot"]=52,["chest"]=1},
- {["name"]="Supremium Ingot",["price"]=25,["category"]={},["slot"]=53,["chest"]=1},
- {["name"]="Soulium Ingot",["price"]=9,["category"]={},["slot"]=54,["chest"]=1},
- {["name"]="Prismalium Ingot",["price"]=14,["category"]={},["slot"]=55,["chest"]=1},
- {["name"]="Melodium Ingot",["price"]=16,["category"]={},["slot"]=56,["chest"]=1},
- {["name"]="Stellarium Ingot",["price"]=40,["category"]={},["slot"]=57,["chest"]=1},
- {["name"]="Soul Infused ingot",["price"]=10,["category"]={},["slot"]=58,["chest"]=1},
- {["name"]="Shellite ingot",["price"]=14,["category"]={},["slot"]=59,["chest"]=1},
- {["name"]="Twinite ingot",["price"]=12,["category"]={},["slot"]=60,["chest"]=1},
- {["name"]="Dragonsteel ingot",["price"]=15,["category"]={},["slot"]=61,["chest"]=1}
- }
- chestIDs = {972}
- chestOrders = {}
- orderTimers = {}
- chest = peripheral.wrap("back")
- drive = peripheral.wrap("front")
- fs.delete("disk/startup")
- password = "sdfewkwlsfirpqasdw+ödö230182jdjwwoqqyy<<12203464s5fvb7v53545755.55,477ddlw+w##k,kkk<iiwß10wwwl3.f,s,siw000dlf.göötää5klxmy,<kkhpi33k5k6mmddn.z--+#'*!)§=)§($//$L?DJW)(CJM"
- end
- function main()
- while true do
- os.startTimer(5)
- info1,info2,info3,info4 = os.pullEvent()
- if info1 == "rednet_message" then
- if type(info3) == "table" then
- if info3["action"] == "paid" then
- responseID = pay(info3["amount"])
- rednet.send(responseID,{["action"]="paid",["amount"]=info3["amount"]})
- if orderIsDone() then
- rednet.send(lastID,{["action"]="orderIsDone"})
- end
- end
- if info3["action"] == "newOrder" and fs.exists("pocketIDs/"..info2) then
- rednet.send(info2,{["action"]="listedOrder",["orderPos"]=addToOrderQueue(info3["order"])})
- end
- if info3["action"] == "canceledOrder" and fs.exists("pocketIDs/"..info2) then
- cancelOrder(info2)
- end
- if info3["action"] == "getItems" and fs.exists("pocketIDs/"..info2) then
- rednet.send(info2,{["action"]="sendingItems",["items"]=shopItems})
- end
- if info3["action"] == "newPocket" and info3["password"] == password then
- file = fs.open("pocketIDs/"..info2,"w")
- file.flush()
- file.close()
- end
- end
- end
- if (not rs.getInput("left")) and newPocketTimer == nil then
- newPocketTimer = os.startTimer(1)
- end
- if info1 == "timer" then
- for k,v in pairs(orderQueue) do
- if info2 == orderTimers[k] then
- cancelOrder(orderQueue[k]["id"])
- end
- end
- if info2 == newPocketTimer then
- outputNewPocket()
- end
- if info2 == resetNewPocketTimer then
- newPocketTimer = nil
- end
- end
- end
- end
- function outputNewPocket()
- fs.delete("disk/startup")
- fs.delete("disk/password")
- fs.copy("pocketProgram","disk/startup")
- file = fs.open("disk/password","w")
- file.write(password)
- file.flush()
- file.close()
- chest.pullItems("front",1)
- resetNewPocketTimer = os.startTimer(10)
- end
- function cancelOrder(id)
- for k,v in pairs(orderQueue) do
- if orderQueue[k]["id"] == id then
- for i=1,table.maxn(orderQueue)-k+1 do
- orderQueue[k+i-1] = orderQueue[i+k]
- end
- end
- end
- for k,v in pairs(orderQueue) do
- rednet.send(orderQueue[k]["id"],{["action"]="changedOrder",["orderPos"]=k})
- end
- end
- function orderIsDone()
- if type(orderQueue[1]) == "table" then
- if orderQueue[1]["price"] < 0 or orderQueue[1]["price"] == 0 then
- buyCurrentOrder()
- lastID = orderQueue[1]["id"]
- for k,v in pairs(orderQueue) do
- orderQueue[k] = orderQueue[k+1]
- end
- return true
- else
- return false
- end
- else
- return false
- end
- end
- function buyCurrentOrder()
- for k,v in pairs(chestIDs) do
- chestOrders[k] = {}
- end
- for k,v in pairs(orderQueue[1]["cartInfo"]) do
- table.insert(chestOrders[orderQueue[1]["cartInfo"][k]["chest"]],{["slot"]=orderQueue[1]["cartInfo"][k]["slot"],["amount"]=orderQueue[1]["cartInfo"][k]["amount"]})
- end
- for k,v in pairs(chestIDs) do
- if chestOrders[k][1] ~= nil then
- rednet.send(chestIDs[k],{["action"]="buy",["order"]=chestOrders[k]})
- end
- end
- end
- function pay(amount)
- if type(orderQueue[1]) == "table" then
- orderQueue[1]["price"] = orderQueue[1]["price"]-amount
- return orderQueue[1]["id"]
- else
- return 0
- end
- end
- function addToOrderQueue(order)
- table.insert(orderQueue,order)
- orderTimers[table.maxn(orderQueue)] = os.startTimer(90)
- return table.maxn(orderQueue)
- end
- -------------------------------------------------
- startup()
- term.clear()
- main()
Add Comment
Please, Sign In to add comment