Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- p = peripheral.wrap("back")
- rednet.open("right")
- p.setTextScale(1.5)
- p.setBackgroundColor(colors.black)
- p.setTextColor(colors.white)
- button={}
- amount = 0
- function split(str, delim, maxNb)
- if string.find(str, delim) == nil then
- return { str }
- end
- if maxNb == nil or maxNb < 1 then
- maxNb = 0
- end
- local result = {}
- local pat = "(.-)" ..delim.. "()"
- local nb = 0
- local lastPos
- for part, pos in string.gmatch(str, pat) do
- nb = nb + 1
- result[nb] = part
- if nb == maxNb then
- break
- end
- end
- return result
- end
- function setTable(name, func, xmin, xmax, ymin, ymax)
- button[name] = {}
- button[name]["func"] = func
- button[name]["active"] = false
- button[name]["xmin"] = xmin
- button[name]["ymin"] = ymin
- button[name]["xmax"] = xmax
- button[name]["ymax"] = ymax
- end
- function hit()
- print("hit()")
- amount = 0
- p.setBackgroundColor(colors.blue)
- p.clear()
- button={}
- setTable("1", save, 4, 10, 3, 7)
- setTable("2", save, 12, 18, 3, 7)
- setTable("3", save, 20, 26, 3, 7)
- setTable("4", save, 4, 10, 9, 13)
- setTable("5", save, 12, 18, 9, 13)
- setTable("6", save, 20, 26, 9, 13)
- setTable("7", save, 4, 10, 15, 19)
- setTable("8", save, 12, 18, 15, 19)
- setTable("9", save, 20, 26, 15, 19)
- setTable("0", save, 28, 34, 9, 13)
- setTable("Get Items", send, 28, 42, 15, 19)
- setTable("Stack", stack, 28, 42, 3, 7)
- setTable("reset", reset, 43, 48, 22, 22)
- screenNum() --line 214
- herp_der_derp() --line 76
- event, side, x, y = os.pullEvent("monitor_touch")
- checkxy2(x,y) --line 176
- end
- function reset() --a reset button for the seletion screen
- print("reset")
- hit()
- end
- function herp_der_derp()
- print("herp_der_derp()")
- amount = tonumber(amount)
- amount = tostring(amount)
- p.setBackgroundColor(colors.lime)
- p.setTextColor(colors.blue)
- size = math.floor((42 - 36 - string.len(amount)) /2) + 1
- place = math.floor(41 - string.len(amount) - 36) /2
- p.setCursorPos(36,9)
- for i=1, 7 do
- p.write(" ")
- end
- p.setCursorPos(36,10)
- for i=1, 7 do
- p.write(" ")
- end
- p.setCursorPos(36,11)
- for i=1, size do
- p.write(" ")
- end
- p.write(amount)
- p.write(" ")
- for i=1, place do
- p.write(" ")
- end
- p.setCursorPos(36,12)
- for i=1, 7 do
- p.write(" ")
- end
- p.setCursorPos(36,13)
- for i=1, 7 do
- p.write(" ")
- end
- p.setBackgroundColor(colors.black)
- p.setTextColor(colors.white)
- end
- function stack() -- button for selectiong to add a stack
- print("stack()")
- amountStack = 0
- amount = tonumber(amount)
- amountStack = hey
- amountStack = 63
- amount = amount + amountStack + 1
- amount = tostring(amount)
- herp_der_derp()
- event, side, x, y = os.pullEvent("monitor_touch")
- checkxy2(x,y)
- end
- function save() -- a function to save the amount that has been entered
- print("save()")
- hey = tonumber(hey)
- amount = amount..hey
- amount = tostring(amount)
- herp_der_derp()
- event, side, x, y = os.pullEvent("monitor_touch")
- checkxy2(x,y)
- end
- function send() -- the requesting function
- print("send()")
- send = 0
- input = 0
- amount = tonumber(amount)
- if amount >= 64 then
- send = amount / 64
- send = math.floor(send)
- for i = 1, send do
- rednet.broadcast(thing..":64")
- end
- send = send * 64
- input = amount - send
- input = tostring(input)
- if input == not 0 then
- rednet.broadcast(thing..":"..input)
- end
- print (thing..":"..amount)
- else
- amount = tostring(amount)
- rednet.broadcast(thing..":"..amount)
- print (thing..":"..amount)
- end
- end
- function checkxy1(x, y)
- print("checkxy1()")
- for name, data in pairs(button) do
- if y >=data["ymin"] and y <= data["ymax"] then
- if x >=data["xmin"] and x <= data["xmax"] then
- mess = {}
- mess = split(name, ":") --line 9 just splits it on the : and returns the first half
- thing = tostring(mess[1])
- print (thing)
- data["func"]() --line 46
- end
- end
- end
- end
- function checkxy2(x, y)
- print("checkxy2()")
- for name, data in pairs(button) do
- if y >=data["ymin"] and y <= data["ymax"] then
- if x >=data["xmin"] and x <= data["xmax"] then
- hey = name
- print(data["func"])
- data["func"]()
- end
- end
- end
- end
- function fillNum(text, color, bData)
- p.setBackgroundColor(colors.lime)
- p.setTextColor(colors.blue)
- local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
- local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
- for j = bData["ymin"], bData["ymax"] do
- p.setCursorPos(bData["xmin"], j)
- if j == yspot then
- for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
- if k == xspot then
- p.write(text)
- else
- p.write(" ")
- end
- end
- else
- for i = bData["xmin"], bData["xmax"] do
- p.write(" ")
- end
- end
- end
- p.setBackgroundColor(colors.black)
- p.setTextColor(colors.white)
- end
- function screenNum()
- local currColor
- for name,data in pairs(button) do
- currColor = colors.lime
- fillNum(name, currColor, data) --line 189
- end
- end
- function fill(text, color, bData)
- p.setCursorPos(bData["xmin"], bData["ymin"])
- p.write(text)
- end
- function screen()
- for name,data in pairs(button) do
- fill(name, currColor, data) --line 222
- end
- end
- run = 1
- function1 = function()
- button={}
- message = "cobble: 1000"
- line = 2
- item = 95
- p.clear()
- for i=1, 1 do
- rednet.send(item, "update")
- --id, message = rednet.receive(0.05)
- if message == nil then
- elseif line <=20 then
- length = string.len(message) + 3
- setTable(message, hit, 3, length, line, line) --line 36
- screen() --line 227
- elseif line > 15 and line <= 30 then
- l = line - 14
- length = string.len(message) + 3
- setTable(message, hit, 16, length, l, l) --line 36
- screen() --line 227
- else
- l = line - 29
- length = string.len(message) + 3
- setTable(message, hit, 29, length, l, l) --line 36
- screen() --line 227
- end
- line = line + 1
- item = item + 1
- end
- local timerID=os.startTimer(10)
- while true do
- event, side, x, y = os.pullEvent()
- if event == "monitor_touch" then
- checkxy1(x,y) --line 161
- break
- elseif event=="timer" and side==timerID then
- break
- end
- end
- end
- while true do
- function1() -- line 235
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement