Advertisement
Guest User

touchpad.lua

a guest
Sep 17th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.98 KB | None | 0 0
  1. --made by Cryodine with hours of frustrating pain
  2. local event = require("event")
  3. local component = require("component")
  4. local gpu = component.gpu
  5. local redstone = component.redstone
  6. local x = 1
  7. local y = 1
  8. local num = -1
  9. local numstring = ""
  10. function setbutt(x1,y1,mx,my,lbl)
  11.   gpu.setBackground(0x00ffff)
  12.   gpu.setForeground(0x333333)
  13.   xpos1 = ((w/mx)*(x1-1))+2
  14.   ypos1 = ((h/my)*(y1-1))+2
  15.   xpos2 = (w/mx)-1
  16.   ypos2 = (h/my)-1
  17.   midx = (xpos1 + (xpos2/2))-1
  18.   midy = (ypos1 + (ypos2/2))-1
  19.   gpu.fill(xpos1,ypos1,xpos2,ypos2," ")
  20.   gpu.set(midx,midy,lbl)
  21.   gpu.setBackground(0x333333)
  22.   gpu.setForeground(0x00ffff)
  23.   return {xpos1,ypos1,xpos1+xpos2,ypos1+ypos2}
  24. end
  25. function chkpress(a,tx,ty)
  26.   if tx >= a[1] and tx <= a[3] and ty >= a[2] and ty <= a[4] then
  27.     return true
  28.   else
  29.     return false
  30.   end
  31. end
  32. while true do
  33.   mw,mh = gpu.maxResolution()
  34.   square = math.min(mw,mh)
  35.   gpu.setResolution(square/2,square/4)
  36.   w,h = gpu.getResolution()
  37.   gpu.setForeground(0x00ffff)
  38.   gpu.setBackground(0x333333)
  39.   gpu.fill(1,1,w,h," ")
  40.   gpu.set(1,1,numstring)
  41.   --gpu.set(1,1,x..y)
  42.   --gpu.set(1,2,tostring(num))
  43.  -- gpu.set(1,4,numstring)
  44.   lbl = 1
  45.   coords = {}
  46.   for i = 1, 3, 1 do
  47.     for k = 1, 3, 1 do
  48.       table.insert(coords,lbl,setbutt(k,i,3,4,tostring(lbl)))
  49.       lbl = lbl + 1
  50.     end
  51.   end
  52.   table.insert(coords,10,setbutt(2,4,3,4,"0"))
  53.   table.insert(coords,11,setbutt(3,4,3,4,">"))
  54.   table.insert(coords,12,setbutt(1,4,3,4,"c"))
  55.   _,p,x,y = event.pull("touch")
  56.   for i = 1, 9, 1 do
  57.     if chkpress(coords[i],x,y) then
  58.       num = i
  59.       break
  60.     elseif chkpress(coords[10],x,y) then
  61.       num = 0
  62.       break
  63.     else
  64.       num = -1
  65.     end
  66.   end
  67.  
  68.   if chkpress(coords[12],x,y) then
  69.     numstring = ""
  70.   end
  71.   if num ~= -1 then
  72.     numstring = numstring .. tostring(num)
  73.   end
  74.   if chkpress(coords[11],x,y) then
  75.     if numstring == "6969" then --change passcode here
  76.       redstone.setOutput(1,16)
  77.       os.sleep(3)
  78.       redstone.setOutput(1,0)
  79.       numstring = ""
  80.     else
  81.       numstring = ""
  82.     end
  83.   end
  84. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement