Advertisement
LazyShpee

inputCode: flexibleAPI Add-on

Mar 28th, 2013
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.21 KB | None | 0 0
  1. function inputCode(x, y, mask)
  2.     local num = ui.new() -- Creates
  3.     local numpad = num:addButton('numpad', 0, 1, {' 987 ',' 654',' 321',' X0V'})
  4.     local screen = num:addLabel('screen', 0,0, '     ')
  5.     numpad:setAction('input')
  6.     num:setCommonAttribute({name = ''},{cont = 'num_origin'})
  7.     numpad:setColors(colors.lime, colors.lightBlue)
  8.     screen:setColors(colors.white, colors.blue)
  9.     num:addPoint('num_origin', x, y)
  10.     local length = screen.text:len()
  11.     local current = ''
  12.     while true do
  13.         num:draw()
  14.         local _, m, x, y = os.pullEvent('mouse_click')
  15.         click = num:mouse({x,y})
  16.         if click then
  17.             if click[1][1] == 'input' then
  18.                 local text = num.ui[click[1][2]].text
  19.                 local xx, yy = unpack(click[1][3])
  20.                 local single = string.sub(text[yy],xx,xx)
  21.                 if single ~= 'V' and single ~= 'X' and single ~= ' ' and current:len() ~= length then
  22.                     current = current..single
  23.                     if not(mask) then
  24.                         screen.text = current..string.rep(' ', length - current:len())
  25.                     else
  26.                         screen.text = string.rep(mask:sub(1,1),current:len())..string.rep(' ', length - current:len())
  27.                     end
  28.  
  29.                 elseif single == 'V' then
  30.                     return current
  31.                 elseif single == 'X' then
  32.                     return nil
  33.                 end
  34.             end
  35.         end
  36.     end
  37. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement