Advertisement
Guest User

ShopColor

a guest
May 28th, 2015
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.27 KB | None | 0 0
  1. os.loadAPI("tpex")
  2.  
  3. mon = peripheral.find("monitor")
  4.  
  5. chest = peripheral.wrap("container_chest_4")
  6. chest1 = peripheral.wrap("container_chest_0")
  7. chest2 = peripheral.wrap("container_chest_5")
  8. chest3 = peripheral.wrap("container_chest_6")
  9. chest4 = peripheral.wrap("container_chest_7")
  10. chest5 = peripheral.wrap("container_chest_8")
  11. chest6 = peripheral.wrap("container_chest_9")
  12.  
  13. act1 = peripheral.wrap("tile_thermalexpansion_device_activator_name_0")
  14. act2 = peripheral.wrap("tile_thermalexpansion_device_activator_name_1")
  15. act3 = peripheral.wrap("tile_thermalexpansion_device_activator_name_2")
  16. act4 = peripheral.wrap("tile_thermalexpansion_device_activator_name_3")
  17.  
  18. local mont = "monitor_23"
  19. local price = 2
  20. local credit = 0
  21. local token = "Yellorium Ingot"
  22. local paid = false
  23. local mode = 1
  24. local transcolor1 = colors.white
  25. local transcolor2 = colors.blue
  26. local screen1 = tpex.new("monitor_23") --Main Screen
  27. local screen2 = tpex.new("monitor_23") --White Frequency
  28. local screen3 = tpex.new("monitor_23") --Blue Frequency
  29. local set1 = {}
  30. local colorword = {}
  31. set1[colors.white] = 1
  32. set1[colors.black] = 2
  33. set1[colors.red] = 3
  34. set1[colors.green] = 4
  35. set1[colors.brown] = 5
  36. set1[colors.blue] = 6
  37. set1[colors.purple] = 7
  38. set1[colors.cyan] = 8
  39. set1[colors.lightGray] = 9
  40. set1[colors.gray] = 10
  41. set1[colors.pink] = 11
  42. set1[colors.lime] = 12
  43. set1[colors.yellow] = 13
  44. set1[colors.lightBlue] = 14
  45. set1[colors.magenta] = 15
  46. set1[colors.orange] = 16
  47.  
  48. colorword[colors.white] = "White"
  49. colorword[colors.black] = "Black"
  50. colorword[colors.red] = "Red"
  51. colorword[colors.green] = "Green"
  52. colorword[colors.brown] = "Brown"
  53. colorword[colors.blue] = "Blue"
  54. colorword[colors.purple] = "Purple"
  55. colorword[colors.cyan] = "Cyan"
  56. colorword[colors.lightGray] = "Light Gray"
  57. colorword[colors.gray] = "Gray"
  58. colorword[colors.pink] = "Pink"
  59. colorword[colors.lime] = "Lime"
  60. colorword[colors.yellow] = "Yellow"
  61. colorword[colors.lightBlue] = "Light Blue"
  62. colorword[colors.magenta] = "Magenta"
  63. colorword[colors.orange] = "Orange"
  64.  
  65. --clear activators
  66. chest2.pullItem("down",1)
  67. chest3.pullItem("down",1)
  68.  
  69.  
  70. --Setup button screens
  71. function ButtonCreate()
  72. screen1:add("Color1",Cs1,"",7,8,14,12,colors.white,colors.lime,colors.blue)
  73. screen1:add("Color2",Cs2,"",26,8,33,12,colors.blue,colors.lime)
  74. screen1:add("Return",Rtn,"",28,3,35,5,colors.red,colors.lightGray)
  75. screen1:add("Apply Changes and Watch",apply,"",1,15,39,19,colors.green,colors.lightGray)
  76. screen1:add("1",setWhite,"",36,1,37,2,colors.gray,colors.gray,colors.gray,colors.lightGray)
  77.  
  78. screen2:add("Return",goBack,"",29,2,38,4,colors.yellow,colors.yellow)
  79. screen2:add("1+", C,"white"    ,6 ,6 ,9 ,8 ,colors.white    ,colors.lightGray,colors.white,colors.lightGray)
  80. screen2:add("2+", C,"orange"   ,11,6 ,14,8 ,colors.orange   ,colors.white    ,colors.orange)
  81. screen2:add("3+", C,"magenta"  ,16,6 ,19,8 ,colors.magenta  ,colors.white    ,colors.magenta)
  82. screen2:add("4+", C,"lightBlue",21,6 ,24,8 ,colors.lightBlue,colors.white    ,colors.lightBlue)
  83. screen2:add("5+", C,"yellow"   ,26,6 ,29,8 ,colors.yellow   ,colors.white    ,colors.yellow)
  84. screen2:add("6+", C,"lime"     ,31,6 ,34,8 ,colors.lime     ,colors.white    ,colors.lime)
  85. screen2:add("7+", C,"pink"     ,6 ,11,9 ,13,colors.pink     ,colors.white    ,colors.pink)
  86. screen2:add("8+", C,"gray"     ,11,11,14,13,colors.gray     ,colors.white    ,colors.gray)
  87. screen2:add("9+", C,"lightGray",16,11,19,13,colors.lightGray,colors.white    ,colors.lightGray)
  88. screen2:add("10", C,"cyan"     ,21,11,24,13,colors.cyan     ,colors.white    ,colors.cyan)
  89. screen2:add("11", C,"purple"   ,26,11,29,13,colors.purple   ,colors.white    ,colors.purple)
  90. screen2:add("12", C,"blue"     ,31,11,34,13,colors.blue     ,colors.white    ,colors.blue)
  91. screen2:add("13", C,"brown"    ,11,16,14,18,colors.brown    ,colors.white    ,colors.brown)
  92. screen2:add("14", C,"green"    ,16,16,19,18,colors.green    ,colors.white    ,colors.green)
  93. screen2:add("15", C,"red"      ,21,16,24,18,colors.red      ,colors.white    ,colors.red)
  94. screen2:add("16", C,"black"    ,26,16,29,18,colors.black    ,colors.white    ,colors.black)
  95.  
  96. screen3:add("Return",goBack,"",29,2,38,4,colors.yellow,colors.yellow)
  97. screen3:add("1+", C2,"white"    ,6 ,6 ,9 ,8 ,colors.white    ,colors.blue     ,colors.white    ,colors.blue)
  98. screen3:add("2+", C2,"orange"   ,11,6 ,14,8 ,colors.orange   ,colors.blue     ,colors.orange   ,colors.blue)
  99. screen3:add("3+", C2,"magenta"  ,16,6 ,19,8 ,colors.magenta  ,colors.blue     ,colors.magenta  ,colors.blue)
  100. screen3:add("4+", C2,"lightBlue",21,6 ,24,8 ,colors.lightBlue,colors.blue     ,colors.lightBlue,colors.blue)
  101. screen3:add("5+", C2,"yellow"   ,26,6 ,29,8 ,colors.yellow   ,colors.blue     ,colors.yellow   ,colors.blue)
  102. screen3:add("6+", C2,"lime"     ,31,6 ,34,8 ,colors.lime     ,colors.blue     ,colors.lime     ,colors.blue)
  103. screen3:add("7+", C2,"pink"     ,6 ,11,9 ,13,colors.pink     ,colors.blue     ,colors.pink     ,colors.blue)
  104. screen3:add("8+", C2,"gray"     ,11,11,14,13,colors.gray     ,colors.blue     ,colors.gray     ,colors.blue)
  105. screen3:add("9+", C2,"lightGray",16,11,19,13,colors.lightGray,colors.blue     ,colors.lightGray,colors.blue)
  106. screen3:add("10", C2,"cyan"     ,21,11,24,13,colors.cyan     ,colors.blue     ,colors.cyan     ,colors.blue)
  107. screen3:add("11", C2,"purple"   ,26,11,29,13,colors.purple   ,colors.blue     ,colors.purple   ,colors.blue)
  108. screen3:add("12", C2,"blue"     ,31,11,34,13,colors.blue     ,colors.lightBlue,colors.blue     ,colors.lightBlue)
  109. screen3:add("13", C2,"brown"    ,11,16,14,18,colors.brown    ,colors.blue     ,colors.brown    ,colors.blue)
  110. screen3:add("14", C2,"green"    ,16,16,19,18,colors.green    ,colors.blue     ,colors.green    ,colors.blue)
  111. screen3:add("15", C2,"red"      ,21,16,24,18,colors.red      ,colors.blue     ,colors.red      ,colors.blue)
  112. screen3:add("16", C2,"black"    ,26,16,29,18,colors.black    ,colors.blue     ,colors.black    ,colors.blue)
  113. end
  114.  
  115. function setWhite()
  116.   transcolor1 = colors.white
  117.   transcolor2 = colors.white
  118.   setColor()
  119. end
  120.  
  121. function C (color)
  122.     transcolor1 = colors[color]
  123. end
  124.  
  125. function C2 (color)
  126.     transcolor2 = colors[color]
  127. end
  128.  
  129. function Cs1()
  130.   mode = 2
  131. end
  132.  
  133. function Cs2()
  134.   mode = 3
  135. end
  136.  
  137. function goBack()
  138.   mode = 1
  139. end
  140.  
  141. function Rtn()
  142.   for i = 1,27 do
  143.     chest.pushItem("down",i)
  144.   end
  145.   Credit = 0
  146. end
  147.  
  148. function fillin(x,y,color)
  149.   mon.setCursorPos(x,y)
  150.   mon.setBackgroundColor(color)
  151.   mon.setTextColor(color)
  152.   for i = 1,5 do
  153.     for j = 1,6 do
  154.       mon.write(" ")
  155.     end
  156.     mon.setCursorPos(x,y+i)
  157.   end
  158. end
  159.  
  160. function ReadChest()
  161.     credit = 0
  162.     inv = chest.getAllStacks()
  163.     if #inv > 0 then
  164.       for i = 1,#inv do
  165.         slot = chest.getStackInSlot(i)
  166.         if (slot.display_name == token) then
  167.             credit = credit + slot.qty
  168.         else
  169.             chest.pushItem("down",i)
  170.         end
  171.       end
  172.     end
  173.  end
  174.  
  175.  function setColor()
  176.         chest1.pushItem("south",set1[transcolor1],1,1)
  177.         chest1.pushItem("north",set1[transcolor2],1,1)
  178.         chest4.pushItem("south",set1[transcolor1],1,1)
  179.         chest4.pushItem("north",set1[transcolor2],1,1)
  180.         SetColors(colors.green,colors.lightGray)
  181.         for i = 1,30 do
  182.             mon.setCursorPos(10,10)
  183.             if (i%2 == 0) then
  184.                 mon.write("Applying Changes...\\")
  185.             else
  186.                 mon.write("Applying Changes.../")
  187.             end
  188.             os.sleep(1)
  189.         end
  190.         chest2.pullItem("down",1)
  191.         chest3.pullItem("down",1)
  192.         chest5.pullItem("down",1)
  193.         chest6.pullItem("down",1)            
  194. end
  195.    
  196.  
  197.  function apply()
  198.     if (credit >= price) then
  199.         chest.condenseItems()
  200.         chest.pushItem("north",1,4)
  201.         chest.pushItem("down",1)
  202.         credit = 0
  203.         setColor()
  204.         mode = 1
  205.     else
  206.         SetColors(colors.red,colors.yellow)
  207.         mon.setCursorPos(11,3)
  208.         mon.write("Insufficent Credit")
  209.         mon.setCursorPos(11,4)
  210.         mon.write("Please insert more")
  211.         mon.setCursorPos(20-(#token/2),5)
  212.         mon.write(token)
  213.         os.sleep(5)
  214.         mode = 1
  215.     end
  216. end
  217.        
  218. function ReadButtons()
  219.     timerCode = os.startTimer(1)
  220.     local event, side, x, y
  221.     repeat
  222.         event, side, x, y = os.pullEvent()
  223.         print(event)
  224.         if event == "timer" then
  225.             print(timerCode..":"..side)
  226.             if timerCode ~= side then
  227.                 print("Wrong Code")
  228.             else
  229.                 print("Right Code")
  230.             end
  231.         end
  232.     until event~= "timer" or timerCode == side
  233.     if event == "monitor_touch" then
  234.         print(side.." "..x..":"..y)
  235.         if side == mont then
  236.             if (mode == 1) then
  237.                 screen1:runOnce(x,y)
  238.             elseif (mode == 2) then
  239.                 screen2:runOnce(x,y)
  240.             elseif (mode == 3) then
  241.                 screen3:runOnce(x,y)
  242.             end
  243.         end
  244.     end
  245. end
  246.  
  247. function SetColors(forground,backbround)
  248. mon.clear()
  249. mon.setBackgroundColor(backbround)
  250. mon.setTextColor(forground)
  251. mon.setCursorPos(1,1)
  252.   for i = 1,19 do
  253.     mon.setCursorPos(1,i)
  254.     for j = 1,39 do
  255.       mon.write(" ")
  256.     end
  257.   end
  258. end
  259.  
  260. function MainScr()
  261. SetColors(colors.green,colors.gray)
  262. mon.setCursorPos(12,1)
  263. mon.write("Shop Color Changer")
  264. mon.setCursorPos(7,3)
  265. mon.write("Credit: "..credit.. "/" .. price)
  266. mon.setCursorPos(1,4)
  267. mon.write("Tokens are "..token.."s")
  268. screen1:draw()
  269. end
  270.  
  271. function Color1Screen ()
  272.     SetColors(colors.green,colors.white)
  273.     mon.setCursorPos(12,1)
  274.     mon.write("Shop Color Changer")
  275.     mon.setCursorPos(4,3)
  276.     mon.write("Color Selector")
  277.     mon.setCursorPos(4,4)
  278.     mon.write("Current Color: "..colorword[transcolor1])
  279.     fillin(5,5,colors.lightGray)
  280.     screen2:draw()
  281. end
  282.  
  283. function Color2Screen ()
  284.     mon.clear()
  285.     SetColors(colors.green,colors.blue)
  286.     mon.setCursorPos(12,1)
  287.     mon.write("Shop Color Changer")
  288.     mon.setCursorPos(4,3)
  289.     mon.write("Color Selector")
  290.     mon.setCursorPos(4,4)
  291.     mon.write("Current Color: "..colorword[transcolor2])
  292.     fillin(30,10,colors.lightBlue)
  293.     screen2:draw()
  294. end
  295.  
  296.  
  297. ButtonCreate()
  298.  
  299. while true do
  300.   if mode == 1 then
  301.     MainScr()
  302.   elseif mode == 2 then
  303.     Color1Screen ()
  304.   elseif mode == 3 then
  305.     Color2Screen ()
  306.   end
  307.   ReadChest()
  308.   ReadButtons()
  309. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement