Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- p = peripheral.wrap("top")
- m = peripheral.wrap("right")
- m.open(33880)
- 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
- lastPos = pos
- if nb == maxNb then
- break
- end
- end
- if nb ~= maxNb then
- result[nb + 1] = string.sub(str,lastPos)
- 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()
- 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 selection screen
- hit()
- end
- function 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 selecting to add a 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
- 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
- sent = 0
- input = 0
- amount = tonumber(amount)
- if amount >= 64 then
- sent = amount / 64
- sent = math.floor(sent)
- for i = 1, sent do
- m.transmit(49794, 33880, thing..":64")
- print("64")
- end
- sent = sent * 64
- input = amount - sent
- input = tostring(input)
- m.transmit(49794, 33880, thing..":"..input)
- print(input)
- print (thing..":"..amount)
- else
- amount = tostring(amount)
- m.transmit(49794, 33880, thing..":"..amount)
- print (thing..":"..amount)
- end
- end
- function checkxy1(x, y)
- 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])
- data["func"]() --line 46
- end
- end
- end
- end
- function checkxy2(x, y)
- 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
- 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
- function hi()
- print("working")
- end
- function1 = function()
- button={}
- line = 2
- item = 1
- p.clear()
- for i=1, 68 do
- m.transmit(32036, 33880, i..":XgFzwMe0")
- local timerID1=os.startTimer(0.05)
- event, side, senderChannel, replyChannel, message, senderDistance = os.pullEvent()
- if message == nil then
- print("nothing to display")
- elseif line <=21 then
- length = string.len(message) + 3
- setTable(message, hit, 3, length, line, line) --line 36
- screen()
- elseif line <= 41 then
- l = line - 20
- length = string.len(message) + 3
- setTable(message, hi, 20, length, l, l) --line 36
- screen()
- else
- l = line - 40
- length = string.len(message) + 3
- setTable(message, hit, 33, length, l, l) --line 36
- screen()
- end
- line = line + 1
- sleep(0.05)
- end
- setTable("reset", hit, 44, 49, 22, 22)
- screen()
- local timerID = os.startTimer(300)
- while true do
- event, side, x, y = os.pullEvent()
- if event == "monitor_touch" then
- print(x..", "..y)
- checkxy1(x,y) --line 161
- break
- elseif event=="timer" and side==timerID then
- print("Refreshing")
- break
- end
- end
- end
- while true do
- sleep(1)
- function1() -- line 235
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement