Advertisement
Zekrommaster110

[LUA | CC1.4.7] Remote Control Panel SERVER

Nov 5th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.88 KB | None | 0 0
  1. ------- CUSTOM VARIABLES ------
  2. modemSide = "top"
  3. clientIDs = {5, 6, 7}
  4. entryNames = {"NUCLEAR REACTOR", "LAVA PUMP", "MASSFABRICATOR"}
  5. --- END OF CUSTOM VARIABLES ---
  6.  
  7.  
  8. ------- FILE HANDLER -------
  9. function writeFile(filename, table)
  10.     file = fs.open(filename, "w")
  11.     file.write(textutils.serialize(table))
  12.     file.close()
  13. end
  14.  
  15. function doIfFileDoesNotExist()
  16.     print("file does not exist")
  17. end
  18.  
  19. function testIfFileExists(filename)
  20.     file = fs.open(filename,"r")
  21.     if file ~= nil then
  22.         file.close()
  23.         return true
  24.     else
  25.         return false
  26.     end
  27. end
  28.  
  29. function deleteFile(filename)
  30.     fs.delete(filename)
  31. end
  32.  
  33. function readFile(filename)
  34.     file = fs.open(filename, "r")
  35.     if file ~= nil then
  36.         table = textutils.unserialize(file.readAll())
  37.         file.close()
  38.     else
  39.         doIfFileDoesNotExist()
  40.     end
  41.     return table
  42. end
  43. -- END OF FILE HANDLER --
  44.  
  45.  
  46.  
  47. if testIfFileExists("entrysTable") == false then
  48.    
  49.     tableDefault = {
  50.         [1] = false,
  51.         [2] = true,
  52.         [3] = false,
  53.     }
  54.    
  55.     writeFile("entrysTable", tableDefault)
  56.    
  57. end
  58.    
  59.    
  60. entrys = readFile("entrysTable")
  61.  
  62. entry1 = entrys[1]
  63. entry2 = entrys[2]
  64. entry3 = entrys[3]
  65.  
  66. function saveAllEntrys()
  67.     saveTable = {
  68.         [1] = entry1,
  69.         [2] = entry2,
  70.         [3] = entry3,
  71.     }
  72.    
  73.     writeFile("entrysTable", saveTable)
  74. end
  75.  
  76. function sendEntry1()
  77.     rednet.send(clientIDs[1], entry1)
  78.     saveAllEntrys()
  79. end
  80.  
  81. function sendEntry2()
  82.     rednet.send(clientIDs[2], entry2)
  83.     saveAllEntrys()
  84. end
  85.  
  86. function sendEntry3()
  87.     rednet.send(clientIDs[3], entry3)
  88.     saveAllEntrys()
  89. end
  90.  
  91. rednet.open(modemSide)
  92.  
  93. while true do
  94.    
  95.     term.setBackgroundColor(colors.black)
  96.     shell.run("clear")
  97.    
  98.     -- ENTRY 1 --
  99.     term.setBackgroundColor(colors.black)
  100.     term.setCursorPos(2,2)
  101.     print(entryNames[1])
  102.    
  103.     if entry1 == false then
  104.         term.setBackgroundColor(colors.red)
  105.         term.setCursorPos(2,3)
  106.         print("[ DISABLED ]")
  107.         sendEntry1()
  108.     else
  109.         term.setBackgroundColor(colors.green)
  110.         term.setCursorPos(2,3)
  111.         print("[ ENABLED ]")
  112.         sendEntry1()
  113.     end
  114.    
  115.     -- ENTRY 2 --
  116.     term.setBackgroundColor(colors.black)
  117.     term.setCursorPos(2,5)
  118.     print(entryNames[2])
  119.        
  120.     if entry2 == false then
  121.         term.setBackgroundColor(colors.red)
  122.         term.setCursorPos(2,6)
  123.         print("[ DISABLED ]")
  124.         sendEntry2()
  125.     else
  126.         term.setBackgroundColor(colors.green)
  127.         term.setCursorPos(2,6)
  128.         print("[ ENABLED ]")
  129.         sendEntry2()
  130.     end
  131.    
  132.     -- ENTRY 3 --
  133.     term.setBackgroundColor(colors.black)
  134.     term.setCursorPos(2,8)
  135.     print(entryNames[3])
  136.        
  137.     if entry3 == false then
  138.         term.setBackgroundColor(colors.red)
  139.         term.setCursorPos(2,9)
  140.         print("[ DISABLED ]")
  141.         sendEntry3()
  142.     else
  143.         term.setBackgroundColor(colors.green)
  144.         term.setCursorPos(2,9)
  145.         print("[ ENABLED ]")
  146.         sendEntry3()
  147.     end
  148.    
  149.    
  150.    
  151.    
  152.     event,side,x,y = os.pullEvent()
  153.     if event == "monitor_touch" then
  154.        
  155.         -- TOUCH RESPONSE ENTRY 1
  156.         if y == 3 and x >= 2 and x <= 13 then
  157.             if entry1 == false then
  158.                 entry1 = true
  159.             else
  160.                 entry1 = false
  161.             end
  162.         end
  163.        
  164.         -- TOUCH RESPONSE ENTRY 2
  165.         if y == 6 and x >= 2 and x <= 13 then
  166.             if entry2 == false then
  167.                 entry2 = true
  168.             else
  169.                 entry2 = false
  170.             end
  171.         end
  172.        
  173.         -- TOUCH RESPONSE ENTRY 3
  174.         if y == 9 and x >= 2 and x <= 13 then
  175.             if entry3 == false then
  176.                 entry3 = true
  177.             else
  178.                 entry3 = false
  179.             end
  180.         end
  181.        
  182.     end
  183. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement