Advertisement
Guest User

BuildCraft Tank LvL controler

a guest
Apr 6th, 2012
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.50 KB | None | 0 0
  1. term.clear()
  2. term.setCursorPos(0,1)
  3.  
  4. rsInput = rs.getBundledInput("back")
  5.  
  6.  
  7. -- colors for check if good spelling
  8. c1 = "white"
  9. c2 = "orange"
  10. c3 = "magenta"
  11. c4 = "lightBlue"
  12. c5 = "yellow"
  13. c6 = "lime"
  14. c7 = "pink"
  15. c8 = "gray"
  16. c9 = "lightGray"
  17. c10 = "cyan"
  18. c11 = "purple"
  19. c12 = "blue"
  20. c13 = "brown"
  21. c14 = "green"
  22. c15 = "red"
  23. c16 = "black"
  24.  
  25. function convertValue1()  -- change the color type by user into the color id.
  26. if value1 == "white" then value1 = 1
  27. elseif value1 == "orange" then value1 = 2
  28. elseif value1 == "magenta" then value1 = 4
  29. elseif value1 == "lightBlue" then value1 = 8
  30. elseif value1 == "yellow" then value1 = 16
  31. elseif value1 == "lime" then value1 = 32
  32. elseif value1 == "pink" then value1 = 64
  33. elseif value1 == "gray" then value1 = 128
  34. elseif value1 == "lightGray" then value1 = 256
  35. elseif value1 == "cyan" then value1 = 512
  36. elseif value1 == "purple" then value1 = 1024
  37. elseif value1 == "blue" then value1 = 2048
  38. elseif value1 == "brown" then value1 = 4096
  39. elseif value1 == "green" then value1 = 8192
  40. elseif value1 == "red" then value1 = 16384
  41. elseif value1 == "black" then value1 = 32768
  42. end
  43. end
  44.  
  45.  
  46. function printConfig()
  47. term.clear()
  48. term.setCursorPos(1,1)
  49. print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
  50. print("X             Première utilisation              X")  -- First use
  51. print("X                                               X")
  52. print("X       Veuillez faire la configuration         X") -- Please make the configuration of the color of your detectors.
  53. print("X       des couleur de vos détecteurs.          X")
  54. print("X                                               X")
  55. print("X                                               X")
  56. print("X                                               X")
  57. print("X                                               X")
  58. print("X  Pour les couleurs en deux mots, écrivez les  X")  -- For color with 2 word, write them with a capital letter to the second. ex : lightBlue
  59. print("X avec une majuscule au second. ex : lightBlue  X")
  60. print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
  61. end
  62.  
  63. function checkConf()  -- checking the configuration file
  64.   while true do
  65.     if fs.exists("tankConf.ini") == true then -- if the config file exist
  66.     conf = fs.open("tankConf.ini", "r")  -- open the file tankConf.ini in read-only mode
  67.     water1 = tonumber(conf.readLine())  --read the first line and put it in var water1
  68.         if water1 == nil then -- check if the var water1 is nil (if its nil then the conf file is "corrupted")
  69.         conf.close() -- close reading of the file
  70.         enterValue()
  71.         else
  72.         water2 = tonumber(conf.readLine())  -- read all line and put them on variables.
  73.         water3 = tonumber(conf.readLine())
  74.         lava1 = tonumber(conf.readLine())
  75.         lava2 = tonumber(conf.readLine())
  76.         lava3 = tonumber(conf.readLine())
  77.         oil1 = tonumber(conf.readLine())
  78.         oil2 = tonumber(conf.readLine())
  79.         oil3 = tonumber(conf.readLine())
  80.         fuel1 = tonumber(conf.readLine())
  81.         fuel2 = tonumber(conf.readLine())
  82.         fuel3 = tonumber(conf.readLine())
  83.         conf.close() -- close reading file
  84.         break
  85.         end
  86.     break
  87.     else
  88.     enterValue()
  89.     end
  90.   end
  91. end
  92.  
  93. function enterValue()
  94. colorCount = 1
  95.     conf = fs.open("tankConf.ini", "w") --open the config file or create it on write mode
  96.     printConfig()
  97.     value = "d'eau vide:      "  -- water tank empty
  98.     writeColor()
  99.     value = "d'eau ok:        "  -- water tank ok
  100.     writeColor()
  101.     value = "d'eau plein:     "  -- water tank full
  102.     writeColor()
  103.     value = "de lave vide:    "  -- lava tank empty
  104.     writeColor()
  105.     value = "de lave ok:      "  -- lava tank ok
  106.     writeColor()
  107.     value = "de lave plein:   "  -- lava tank full
  108.     writeColor()
  109.     value = "de pétrole vide: "  -- oil tank empty
  110.     writeColor()
  111.     value = "de pétrole ok:   "  -- oil tank ok
  112.     writeColor()
  113.     value = "de pétrole plein:"  -- oil tank full
  114.     writeColor()
  115.     value = "de fuel vide:    "  -- fuel tank empty
  116.     writeColor()
  117.     value = "de fuel ok:      "  -- fuel tank ok
  118.     writeColor()
  119.     value = "de fuel plein:   "  -- fuel tank full
  120.     writeColor()
  121.     conf.close()
  122.    
  123. end
  124.    
  125. function writeColor()
  126.     while true do
  127.         if colorCount ~= 13 then -- counting each colors given for break the loop
  128.         term.setCursorPos(1,7)
  129.         term.clearLine()
  130.         print("X       Couleur pour reservoir "..value.."X") -- Color for "..value.."
  131.         term.setCursorPos(1,8)
  132.         term.clearLine()
  133.         write("X     ->")
  134.         value1 = io.read()  -- below it check if the color is spelled correctly
  135.             if value1 == c1 or value1 == c2 or value1 == c3 or value1 == c4 or value1 == c5 or value1 == c6 or value1 == c7 or value1 == c8 or value1 == c9 or value1 == c10 or value1 == c11 or value1 == c12 or value1 == c13 or value1 == c14 or value1 == c15 or value1 == c16 then
  136.             convertValue1()  -- send to the fonction vonvertValue1() for converting the variable into id of this color
  137.             conf.writeLine(value1) -- write the id of the color given in the file
  138.             colorCount = colorCount + 1 -- increment counter
  139.             term.setCursorPos(1,9)
  140.             term.clearLine()
  141.             print("X                                               X")
  142.             break
  143.             else
  144.             term.setCursorPos(1,9)
  145.             term.clearLine()
  146.             print("X  "..value1.." n'est pas une bonne couleur!")  -- ..value.. is not a color
  147.             end
  148.         else
  149.         conf.close()
  150.         end
  151.      end
  152. end
  153.  
  154. function verifTank()
  155. rsInput = rs.getBundledInput("back")
  156.  
  157.   --Water check
  158.  
  159.   if colors.test(rsInput, water1) == true then
  160.   term.setCursorPos(1,6)
  161.   term.clearLine()
  162.   print("X    - Le réservoire d'eau est      : Vide      X")  -- The water tank is : empty
  163.   end
  164.  
  165.   if colors.test(rsInput, water3) == true then
  166.   term.setCursorPos(1,6)
  167.   term.clearLine()
  168.   print("X    - Le réservoire d'eau est      : Plein     X")  -- The water tank is : full
  169.   end
  170.  
  171.   if colors.test(rsInput, water2) == true and colors.test(rsInput, water1) == false then
  172.   term.setCursorPos(1,6)
  173.   term.clearLine()
  174.   print("X    - Le réservoire d'eau est      : Ok        X")  -- The water tank is : ok
  175.   end
  176.  
  177.   if colors.test(rsInput, water1) == false and colors.test(rsInput, water2) == false and colors.test(rsInput, water3) == false  then
  178.   term.setCursorPos(1,6)
  179.   term.clearLine()
  180.   print("X    - Le réservoire d'eau est      : ERREUR    X")  -- The water tank is : ERROR
  181.   end
  182.  
  183.   -- end of water check
  184.   sleep(1)
  185.   -- Lava check
  186.  
  187.   if colors.test(rsInput, lava1) == true then
  188.   term.setCursorPos(1,7)
  189.   term.clearLine()
  190.   print("X    - Le reservoire de lave est    : Vide      X") -- The lava tank is : empty
  191.   end
  192.  
  193.   if colors.test(rsInput, lava3) == true then
  194.   term.setCursorPos(1,7)
  195.   term.clearLine()
  196.   print("X    - Le reservoire de lave est    : Plein     X")  -- The lava tank is : full
  197.   end
  198.  
  199.   if colors.test(rsInput, lava2) == true and colors.test(rsInput, lava1) == false then
  200.   term.setCursorPos(1,7)
  201.   term.clearLine()
  202.   print("X    - Le reservoire de lave est    : Ok        X")  -- The lava tank is : ok
  203.   end
  204.  
  205.   if colors.test(rsInput, lava1) == false and colors.test(rsInput, lava2) == false and colors.test(rsInput, lava3) == false  then
  206.   term.setCursorPos(1,7)
  207.   term.clearLine()
  208.   print("X    - Le reservoire de lave est    : ERREUR    X")  -- The lava tank is : ERROR
  209.   end
  210.  
  211.   -- end of lava check
  212.   sleep(1)
  213.   -- Oil check
  214.  
  215.   if colors.test(rsInput, oil1) == true then
  216.   term.setCursorPos(1,8)
  217.   term.clearLine()
  218.   print("X    - Le reservoire de pétrole est : Vide      X")  -- The oil tank is : empty
  219.   end
  220.  
  221.   if colors.test(rsInput, oil3) == true then
  222.   term.setCursorPos(1,8)
  223.   term.clearLine()
  224.   print("X    - Le reservoire de pétrole est : Plein     X")  -- The oil tank is : full
  225.   end
  226.  
  227.   if colors.test(rsInput, oil2) == true and colors.test(rsInput, oil1) == false then
  228.   term.setCursorPos(1,8)
  229.   term.clearLine()
  230.   print("X    - Le reservoire de pétrole est : Ok        X")  -- The oil tank is : ok
  231.   end
  232.  
  233.   if colors.test(rsInput, oil1) == false and colors.test(rsInput, oil2) == false and colors.test(rsInput, oil3) == false  then
  234.   term.setCursorPos(1,8)
  235.   term.clearLine()
  236.   print("X    - Le reservoire de pétrole est : ERREUR    X")  -- The oil tank is : ERROR
  237.   end
  238.  
  239.   -- en of oil check
  240.   sleep(1)
  241.   -- fuel check
  242.  
  243.   if colors.test(rsInput, fuel1) == true then
  244.   term.setCursorPos(1,9)
  245.   term.clearLine()
  246.   print("X    - Le reservoire de fuel est    : Vide      X")  -- The fuel tank is : empty
  247.   end
  248.  
  249.   if colors.test(rsInput, fuel3) == true then
  250.   term.setCursorPos(1,9)
  251.   term.clearLine()
  252.   print("X    - Le reservoire de fuel est    : Plein     X")  -- The fuel tank is : full
  253.   end
  254.  
  255.   if colors.test(rsInput, fuel2) == true and colors.test(rsInput, colors.pink) == false then
  256.   term.setCursorPos(1,9)
  257.   term.clearLine()
  258.   print("X    - Le reservoire de fuel est    : Ok        X")  -- The fuel tank is : ok
  259.   end
  260.  
  261.   if colors.test(rsInput, fuel1) == false and colors.test(rsInput, fuel2) == false and colors.test(rsInput, fuel3) == false then
  262.   term.setCursorPos(1,9)
  263.   term.clearLine()
  264.   print("X    - Le reservoire de fuel est    : ERREUR    X")  -- The fuel tank is : ERROR
  265.   end  
  266.  
  267.   -- end of fuel check
  268.   loop()
  269. end
  270.  
  271. function loop()
  272. while true do
  273. event = os.pullEvent()
  274.   if event == "redstone" then  -- if there is some change in redstone it go to verify all the tanks
  275.   verifTank()
  276.   end
  277. end
  278. end
  279.  
  280. term.clear()
  281. term.setCursorPos(1,1)
  282. checkConf()
  283. term.clear()
  284. term.setCursorPos(1,1)
  285. print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
  286. print("X                                               X")
  287. print("X            Controle des niveaux               X")  -- Tank control
  288. print("X                                               X")
  289. print("X                                               X")
  290. print("X    - Le réservoire d'eau est      :           X")  -- The water tank is :
  291. print("X    - Le reservoire de lave est    :           X")  -- The lava tank is :
  292. print("X    - Le reservoire de pétrole est :           X")  -- The oil tank is :
  293. print("X    - Le reservoire de fuel est    :           X")  -- The fuel tank is :
  294. print("X                                               X")
  295. print("X                                               X")
  296. print("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
  297. sleep(2)
  298. verifTank()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement