Cavious

doorController

Jun 18th, 2014
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.03 KB | None | 0 0
  1. --[[
  2. FILENAME: doorController.lua(Startup.lua)
  3. AUTHOR: Donald R. Valverde (Cavious)
  4. VERSION: 1.0-BETA
  5. --]]
  6.  
  7. local side = "bottom" --REDSTONE SIDE
  8. rednet.open("right")
  9. databaseServer = 22 --CHANGE AS NEEDED FOR SERVER
  10.  
  11. term.clear()
  12.  
  13. function drawText(monitor, text, xPos, yPos, backgroundColor, fontColor)
  14.     monitor.setCursorPos(xPos, yPos)
  15.     monitor.setBackgroundColor(backgroundColor)
  16.     monitor.setTextColor(fontColor)
  17.     monitor.write(text)
  18. end
  19.  
  20. function drawImage(monitor, file, xPos, yPos)
  21.     term.redirect(monitor)
  22.     local image = paintutils.loadImage(file)
  23.     paintutils.drawImage(image, xPos, yPos)
  24.     term.native()
  25. end
  26.  
  27. function redNetReceive()
  28.     while(true) do
  29.         local id, message, protocol = rednet.receive()
  30.        
  31.         if(message == ".open") then
  32.             redstone.setOutput(side, true)
  33.             os.sleep(10)
  34.             if(redstone.getOutput(side) == true) then
  35.                 redstone.setOutput(side, false)
  36.             end
  37.         elseif(message == ".close") then
  38.             redstone.setOutput(side, false)
  39.         end
  40.     end
  41. end
  42.  
  43. function redNetSend()
  44.     local password = {r = 0, g = 0, b = 0}
  45.    
  46.     local monOne = peripheral.wrap("monitor_0")
  47.     local monTwo = peripheral.wrap("monitor_1")
  48.     local monThree = peripheral.wrap("monitor_2")
  49.     local monFour = peripheral.wrap("monitor_3")
  50.    
  51.     monOne.setTextScale(0.5)
  52.     monTwo.setTextScale(0.5)
  53.     monThree.setTextScale(0.5)
  54.     monFour.setTextScale(0.5)
  55.    
  56.     while(true) do
  57.         monOne.clear()
  58.         monTwo.clear()
  59.         monThree.clear()
  60.         monFour.clear()
  61.        
  62.         drawImage(monOne, ".background", 1, 1)
  63.         drawImage(monTwo, ".background", 1, 1)
  64.         drawImage(monThree, ".background", 1, 1)
  65.         drawImage(monFour, ".background", 1, 1)
  66.        
  67.         drawText(monOne, "SUBMIT", 5, 8, colors.orange, colors.white)
  68.         drawText(monTwo, "SUBMIT", 5, 8, colors.orange, colors.white)
  69.         drawText(monThree, "SUBMIT", 5, 8, colors.orange, colors.white)
  70.         drawText(monFour, "SUBMIT", 5, 8, colors.orange, colors.white)
  71.        
  72.         event, side, xPos, yPos = os.pullEvent("monitor_touch")
  73.        
  74.         if(yPos >= 3 and yPos < 6 and xPos == 3 or xPos == 4) then
  75.             password["r"] = "1"
  76.             --FUNCTION HERE
  77.         elseif(yPos >= 3 and yPos < 6 and xPos == 7 or xPos == 8) then
  78.             password["g"] = "1"
  79.             --FUNCTION HERE
  80.         elseif(yPos >= 3 and yPos < 6 and xPos == 11 or xPos == 12) then
  81.         password["b"] = "1"
  82.             --FUNCTION HERE
  83.         elseif(yPos == 8 and xPos >= 5 and xPos < 11) then
  84.             drawText(monOne, "SUBMIT", 5, 8, colors.yellow, colors.white)
  85.             drawText(monTwo, "SUBMIT", 5, 8, colors.yellow, colors.white)
  86.             drawText(monThree, "SUBMIT", 5, 8, colors.yellow, colors.white)
  87.             drawText(monFour, "SUBMIT", 5, 8, colors.yellow, colors.white)
  88.            
  89.             rednet.send(databaseServer, "id_door_topside::"..password[r]..password[g]..password[b])
  90.            
  91.             local id, message, protocol = rednet.receive()
  92.             if(message == ".successful") then
  93.                 redstone.setOutput(side, true)
  94.                 os.sleep(10)
  95.                 if(redstone.getOutput(side) == true) then
  96.                     redstone.setOutput(side, false)
  97.                 end
  98.             end
  99.            
  100.             os.sleep(1)
  101.             --FUNCTION HERE
  102.         end
  103.     end
  104. end
  105.  
  106. while(true) do
  107.     parallel.waitForAny(redNetReceive, redNetSend)
  108. end
Advertisement
Add Comment
Please, Sign In to add comment