Advertisement
sinkir

lua computer 2x2 transformer door

Sep 24th, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.10 KB | None | 0 0
  1. -- pastebin get Bq3kqiSa startup
  2. -- -------------------------------------------
  3. -- 2x2 transformer door -Sinkir-
  4. -- Version 1
  5. -- setup :
  6. -- Computer with 3 repater on 3 side
  7. -- and restone signal in front.
  8. -- 3 input rednet cable (3 colors)
  9. -- view from top
  10. -- r r r
  11. -- r R r
  12. -- rRCRr
  13. --   I
  14. -- r = rednet cable
  15. -- R = repeater
  16. -- C = Computer
  17. -- I = Input (redstone)
  18. -- -------------------------------------------
  19. --
  20. --    P
  21. --   S S
  22. --   ob oS
  23. --  S OOb P
  24. -- P bOO S
  25. --  So bo
  26. --    S S
  27. --     P
  28. -- 2x2 door
  29. -- S = Sticky piston
  30. -- P = Piston
  31. -- O = block of the door 1
  32. -- o = block of the door 2
  33. -- b = block of deco (like your walls)
  34. -- " " space are air block
  35.  
  36. function split(str, pat)
  37.     -- source of the function :
  38.     -- http://lua-users.org/wiki/SplitJoin
  39.     -- Compatibility: Lua-5.1
  40.     local t = {}  -- NOTE: use {n = 0} in Lua-5.0
  41.     local fpat = "(.-)" .. pat
  42.     local last_end = 1
  43.     local s, e, cap = str:find(fpat, 1)
  44.     while s do
  45.         if s ~= 1 or cap ~= "" then
  46.             table.insert(t,cap)
  47.         end
  48.         last_end = e+1
  49.         s, e, cap = str:find(fpat, last_end)
  50.     end
  51.     if last_end <= #str then
  52.         cap = str:sub(last_end)
  53.         table.insert(t, cap)
  54.     end
  55.     return t
  56. end
  57. function fileGet(path)
  58.         if(fs.exists(path))then
  59.                 tabFile = fs.open(path, "r")
  60.                 text = tabFile.readAll()
  61.                 tabFile.close()
  62.                 return text
  63.         else
  64.                 print("fileGet() File not found.")
  65.                 print(path)
  66.                 return false
  67.         end
  68. end
  69.  
  70. function fileSet(path, text)
  71.         if(fs.isReadOnly(path))then
  72.                 print("fileSet() File is read only.")
  73.                 print(path)
  74.                 return false
  75.         else
  76.                 tabFile = fs.open(path, "w")
  77.                 tabFile.write(text)
  78.                 tabFile.close()
  79.                 return true
  80.         end
  81. end
  82.  
  83. function savedata()
  84.     fileSet("data", a ..",".. b)
  85. end
  86.  
  87. function dealer()
  88.     redstone.setOutput("back", true)
  89.     sleep(0.1)
  90.     redstone.setOutput("back", false)
  91. end
  92.  
  93. function swaper()
  94.     redstone.setOutput("left", true)
  95.     sleep(0.1)
  96.     redstone.setOutput("left", false)
  97. end
  98. function pusher()
  99.     redstone.setOutput("right", true)
  100.     sleep(0.1)
  101.     redstone.setOutput("right", false)
  102. end
  103.  
  104.  
  105. if(fs.exists("data")==true)then
  106.     --Shaundi()
  107. else
  108.     fileSet("data", "0,0")
  109. end
  110. tab = split(fileGet("data"), ",")
  111. a = tostring(tab[1])
  112. b = tostring(tab[2])
  113. flag = false
  114. while(2)do
  115.     if(redstone.getInput("front") == true and flag == false)then
  116.         --
  117.         if(a == "0")then
  118.             dealer()
  119.             a = "1"
  120.         elseif(a == "1")then
  121.             if(b == "0")then
  122.                 dealer()
  123.                 sleep(0.1)
  124.                 swaper()
  125.                 sleep(0.1)
  126.                 dealer()
  127.                 sleep(0.1)
  128.                 dealer()
  129.                 sleep(0.1)
  130.  
  131.                 b = "1"
  132.             elseif(b == "1")then
  133.                 pusher()
  134.                 sleep(0.1)
  135.                 dealer()
  136.                 sleep(0.1)
  137.                 dealer()
  138.                 sleep(0.1)
  139.  
  140.                 b = "2"
  141.             elseif(b == "2")then
  142.                 pusher()
  143.                 sleep(0.1)
  144.                 swaper()
  145.                 sleep(0.1)
  146.    
  147.                 b = "0"
  148.             end
  149.             a = "0"
  150.         end
  151.         savedata()
  152.  
  153.  
  154.         flag = true  
  155.     end
  156.     if(redstone.getInput("front") == false)then
  157.         flag = false
  158.     end
  159.     sleep(0.2)
  160. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement