Advertisement
Darking560

lvl0_Screen

Apr 1st, 2014
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.35 KB | None | 0 0
  1. mon = peripheral.wrap("left")
  2. rednet.open("bottom")
  3. mon.setTextScale(0.5)
  4.  
  5. local name
  6. local stair = 0
  7. local elevator = 8
  8. local masterd = 1
  9. local newstair = 0
  10. local screenoff = true
  11.  
  12. button = {
  13.   [1] = {x = 7; y = 5; active = false; name = "0"},
  14.   [2] = {x = 5; y = 5; active = true; name = "-1"},
  15.   [3] = {x = 11; y = 5; active = true; name = "-2"},
  16. }
  17.  
  18. function tuglescreen()
  19.    screenoff = not(screenoff)
  20.    if screenoff == true then
  21.       mon.clear()
  22.    else
  23.       screen()
  24.    end
  25. end
  26.  
  27. function waitClick()
  28.    event, a1, a2, a3 = os.pullEvent()
  29.    
  30.    if event == "rednet_message" then
  31.       newstair = tonumber(a2)
  32.       if newstair == stair then
  33.          for i = 2,3 do button[i].active = true
  34.             print(i.." : "..tostring(button[i].active))
  35.           end
  36.           button[1].active = false
  37.        else
  38.           for i = 2,3 do button[i].active = false
  39.              print(i.." : "..tostring(button[i].active))
  40.           end
  41.           button[1].active = true
  42.        end
  43.        screenoff = true
  44.        mon.clear()
  45.    elseif event == "player" then
  46.       print(a1)
  47.           name = a1
  48.           checkName()
  49.    elseif event == "monitor_touch" then
  50.         if screenoff == false then
  51.         local selectedButton = getButton(a2,a3)
  52.         if selectedButton == nil then
  53.            return
  54.         end
  55.         sleep(1.5)
  56.         rednet.send(elevator, button[selectedButton].name)
  57.         tuglescreen()
  58.         end
  59.    end
  60. end
  61.  
  62. function checkName()
  63.    file = io.open("perms", "r")
  64.    for line in file:lines() do
  65.       if name == line then
  66.          tuglescreen()
  67.       end
  68.    end
  69. end
  70.  
  71. function screen()
  72.    mon.clear()
  73.    mon.setCursorPos(5,1)
  74.    mon.write("Etage " .. newstair)
  75.    if newstair == stair then
  76.       mon.setCursorPos(1,2)
  77.       mon.write("~~~~~~~~~~~~~~~")
  78.           for i = 3,8 do
  79.              mon.setCursorPos(1,i)
  80.              mon.write("|")
  81.              mon.setCursorPos(15,i)
  82.              mon.write("|")
  83.           end
  84.           mon.setCursorPos(1,9)
  85.           mon.write("~~~~~~~~~~~~~~~")
  86.           mon.setBackgroundColor(colors.gray)
  87.           for i = 2,3 do  
  88.              mon.setCursorPos(button[i].x-2,button[i].y-1)
  89.              mon.write("     ")
  90.              mon.setCursorPos(button[i].x-2,button[i].y)
  91.              mon.write(" "..button[i].name.."  ")
  92.              mon.setCursorPos(button[i].x-2,button[i].y+1)
  93.              mon.write("     ")
  94.           end
  95.           mon.setBackgroundColor(colors.black)
  96.          
  97.         else
  98.           mon.setCursorPos(1,2)
  99.           mon.write("~~~~~~~~~~~~~~~")
  100.           for i = 3,8 do
  101.              mon.setCursorPos(1,i)
  102.              mon.write("|")
  103.              mon.setCursorPos(15,i)
  104.              mon.write("|")
  105.           end
  106.           mon.setCursorPos(1,9)
  107.       mon.write("~~~~~~~~~~~~~~~")
  108.           mon.setBackgroundColor(colors.red)
  109.           mon.setCursorPos(6,5)
  110.           mon.write(" Call")
  111.           mon.setBackgroundColor(colors.black)
  112.     end
  113. end
  114.  
  115. function getButton(xPos,yPos)
  116.   for i=1,3 do
  117.     if button[i].active == true then
  118.     bxPos = button[i].x
  119.     byPos = button[i].y
  120.     xMax = bxPos + 2
  121.     xMin = bxPos - 2
  122.     yMax = byPos + 1
  123.     yMin = byPos - 1
  124.     if xPos >= xMin and xPos <= xMax and yPos >= yMin and yPos <= yMax then
  125.       return i
  126.     end
  127.     end
  128.   end
  129. end
  130.  
  131. while true do
  132.   name = ""
  133.   waitClick()
  134. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement