Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --loading button touch api
- os.loadAPI("api/touch")
- os.loadAPI("api/json")
- --Monitor setup
- mName = "monitor_9"
- mview = peripheral.wrap(mName)
- mview.setTextScale(0.5)
- --initializing buttons for monitor
- --btview = touch.new(mName)
- --server id
- sid = 21
- --rednet Info
- rside = "left"
- rednet.open(rside)
- --placeholders
- kaddress = "k83f76uzyz"
- foundItem = {""}
- curCat = "free"
- curSelProd = "None"
- kristStart = 0
- kristStartVal = 0
- multiplierItem = 0
- --Shop Items and Info
- shopItems = {
- free = {
- feather = {amnt = 1, ldesc = "Used in Rings, Arrows, and Books!", desc = "Misc.", iname = "minecraft:feather", idamage = 0},
- egg = {amnt = 1, ldesc = "Useful for starting a chicken farm!", desc = "Farming", iname = "minecraft:egg", idamage = 0 }
- },
- paid = {
- diamond = {price = 10, amnt = 1, ldesc = "Who doesn't like diamonds?", desc = "Valuable", iname = "minecraft:diamond", idamage = 0 },
- redstone = {price = 3, amnt = 1, ldesc = "Through the power of redstone.", desc = "Valuable", iname = "minecraft:redstone", idamage = 0},
- iron = {price = 4, amnt = 1, ldesc = "Iron man would be proud.", desc = "Valuable", iname = "minecraft:iron_ingot", idamage = 0},
- gold = {price = 6, amnt = 1, ldesc = "Gold's hard to come by man.", desc = "Valuable", iname = "minecraft:gold_ingot", idamage = 0},
- chicken = {price = 1, amnt = 1, ldesc = "Better than KFC!", desc = "Food", iname = "minecraft:cooked_chicken", idamage = 0}
- },
- special = {
- cake = {price = 1, amnt = 1, ldesc = "Happy Birthday!", desc = "Food", iname = "minecraft:cake", idamage = 0}
- }
- }
- --Retreive item data in table format ex: price, amnt, desc
- function selectShopItem(Item)
- local foundItem = {""}
- --looping through categories and item tables
- for category, itmTbl in pairs(shopItems) do
- --looping through items and finding attribute table
- for itmName, attrTbl in pairs(itmTbl) do
- if Item == itmName then
- foundItem = attrTbl
- end
- end
- end
- if foundItem[1] ~= "" then
- return foundItem
- else
- --return false
- end
- end
- --Retreive item data in table format ex: price, amnt, desc
- function selectCat(Cat)
- local foundCat = {""}
- --looping through categories and item tables
- for category, itmTbl in pairs(shopItems) do
- if category == Cat then
- foundCat = itmTbl
- end
- end
- if foundCat[1] ~= "" then
- return foundCat
- else
- --return false
- end
- end
- --Select a specific attribute
- function selectShopItemAtt(Item, attri)
- local foundItem = {""}
- --looping through categories and item tables
- for category, itmTbl in pairs(shopItems) do
- --looping through items and finding attribute table
- for itmName, attrTbl in pairs(itmTbl) do
- if Item == itmName then
- for attrIndex, attrVal in pairs(attrTbl) do
- if attrVal == attri then
- foundItem = attrVal
- end
- end
- end
- end
- end
- if foundItem[1] ~= "" then
- return foundItem
- else
- --return false
- end
- end
- --drawing all Function buttons
- function drawButtons()
- btview:add("-",nil,8,11,8,11,colors.red,colors.red) --subtract quantity
- btview:add("+",nil,11,11,11,11,colors.lime,colors.lime)
- btview:add("Paid",nil,45,9,50,10,colors.lime,colors.lime)
- btview:add("Free",nil,45,12,50,13,colors.lightBlue,colors.lightBlue)
- btview:add("Special",nil,45,15,50,17,colors.purple,colors.purple)
- btview:add("Check",nil,45,19,50,21,colors.red,colors.red)
- btview:add(kristStart.."K",nil,7,17,11,18,colors.gray,colors.gray) --Krist Amount
- btview:add(multiplierItem.."x",nil,7,15,11,15,colors.gray,colors.gray) --Multiplier Amount
- btview:add("Selected Item: "..curSelProd,nil,15,6,40,6,colors.gray,colors.gray)--Selected Product
- end
- function writeHere(msg,x,y,bcolor,tcolor)
- local turtlemon = term.redirect(mview)
- term.setBackgroundColor(bcolor)
- term.setTextColor(tcolor)
- term.setCursorPos(x,y)
- write(msg)
- term.redirect(turtlemon)
- end
- function drawItemMenu(catMenu)
- local buffer = {}
- local added = false
- local inline = 9
- for k,v in pairs(selectCat(catMenu)) do
- for s,t in pairs(buffer) do
- if t == v then
- added = true
- end
- end
- if not added then
- inline = inline +1
- btview:add(k,nil,18,inline,40,inline,colors.gray,colors.lime)
- table.insert(buffer,v)
- added = false
- end
- end
- btview:draw()
- end
- --draw selected file
- function drawThis(thispiece,x,y)
- local turtlemon = term.redirect(mview)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- local stp = paintutils.loadImage("img/"..thispiece)
- paintutils.drawImage(stp,x,y)
- term.redirect(turtlemon)
- end
- --DrawingMain Menu
- function drawMainMenu()
- local turtlemon = term.redirect(mview)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1,1)
- local image = paintutils.loadImage("img/bck.nfp")
- paintutils.drawImage(image, 5, 4)
- term.redirect(turtlemon)
- end
- function rightItem(itm,cnt)
- local foundItem = false
- local inameoffload = ""
- local idamageoffload = 0
- for i = 1, 15 do
- --turtle.suckDown()
- for k,v in pairs(selectShopItem(itm)) do
- if k == "iname" then
- inameoffload = v
- elseif k == "idamage" then
- idamageoffload = v
- end
- end
- local j = turtle.getItemDetail(i)
- if j ~= nil then
- if j.name == inameoffload and j.damage == idamageoffload then
- turtle.select(i)
- turtle.transferTo(16)
- foundItem = true
- end
- end
- end
- for i = 1, 15 do
- turtle.select(i)
- turtle.dropDown()
- end
- if cnt > 0 then
- turtle.select(16)
- if cnt ~= 1 then
- turtle.dropDown(turtle.getItemCount()-cnt)
- else
- turtle.dropDown(turtle.getItemCount()-1)
- end
- end
- if foundItem then return true
- else return false end
- end
- function itemPull(itm)
- local itemReady = false
- local complete = false
- rednet.send(sid,itm,"pull")
- while true do
- local id, msg, cat = rednet.receive(15)
- if id == sid then
- if msg ~= "1" then
- rednet.send(sid,itm,"pull")
- print("PULLING DEBUG")
- else
- while not itemReady do
- local ir, msr, car = rednet.receive()
- if ir == sid then
- if msr == "2" then
- print("Passing stage 2")
- for i = 1, 15 do turtle.select(i) turtle.suckDown() end
- --find proper item and move to slot 16
- if rightItem(itm,multiplierItem) then
- print("passing")
- itemReady = true
- complete = true
- else
- --No items available
- end
- elseif msr == "404" then
- print("Error 404")
- complete = true
- break
- end
- end
- end
- --print("Pass stage 2 loop")
- end
- end
- if complete then
- print("breaking operation")
- break
- end
- end
- if itemReady then return true
- else return false end
- end
- function waitForKristOrTouch()
- local skip = false
- local inwallet = false
- while not skip do
- --getting last transactions
- local transactionRequest = http.get("http://krist.ceriat.net/addresses/"..kaddress.."/transactions").readAll()
- local obj = json.decode(transactionRequest)
- for k,v in pairs(obj.transactions) do
- print(v)
- end
- print(obj.count)
- os.startTimer(3)
- local event, a1,a2,a3,a4 = os.pullEvent()
- if event == "monitor_touch" then
- skip = true
- end
- if kristReceived then
- skip = true
- inwallet = true
- end
- end
- if inwallet then return true else return false end
- end
- while true do
- btview = touch.new(mName)
- drawMainMenu()
- drawButtons()
- drawItemMenu(curCat)
- local event, p1 = btview:handleEvents(os.pullEvent())
- if event == "button_click" then
- if p1 == "+" then
- if multiplierItem < 64 then
- multiplierItem = multiplierItem + 1
- kristStart = kristStartVal * multiplierItem
- end
- elseif p1 == "-" then
- if multiplierItem > 0 then
- multiplierItem = multiplierItem - 1
- kristStart = kristStartVal * multiplierItem
- end
- elseif p1 == "Paid" then
- curCat = "paid"
- elseif p1 == "Free" then
- curCat = "free"
- elseif p1 == "Special" then
- curCat = "special"
- elseif p1 == "Check" then
- --CHECK IF I EVEN HAVE THE ITEM IN MY INV BEFORE MOVING ON
- if itemPull(curSelProd) then
- if kristStart > 0 then
- drawThis("checkout.nfp",7,7)
- writeHere(multiplierItem.."x",11,9,colors.lightBlue,colors.yellow)
- writeHere(curSelProd,11,10,colors.cyan,colors.yellow)
- writeHere("for",16,9,colors.red,colors.white)
- writeHere(kristStart.."k",20,9,colors.yellow,colors.green)
- writeHere(kaddress,25,9,colors.green,colors.white)
- writeHere("Awaiting confirmation",13,13,colors.yellow,colors.white)
- writeHere("Click anywhere to cancel..",10,18,colors.black,colors.white)
- waitForKristOrTouch()
- end
- else
- drawThis("warn.nfp",7,7)
- sleep(5)
- end
- else
- --Item Selection
- for itemNameCat, itemTbl in pairs(selectCat(curCat)) do
- if itemNameCat == p1 then
- curSelProd = p1
- if itemTbl.price ~= nil then
- kristStartVal = itemTbl.price
- kristStart = kristStartVal * multiplierItem
- else
- kristStartVal = 0
- kristStart = kristStartVal * multiplierItem
- end
- print(itemNameCat)
- print("test")
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement