hbar

armors

Jun 29th, 2013
738
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.48 KB | None | 0 0
  1. local monitor = peripheral.wrap("top")
  2. local wired = peripheral.wrap("back")
  3. local stand
  4. local pim
  5. for k,v in pairs(wired.getNamesRemote()) do
  6.   local type = wired.getTypeRemote(v)
  7.   if type == "me_fuzzy_storage_bus" then
  8.     stand = peripheral.wrap(v)
  9.   elseif type == "pim" then
  10.     pim = peripheral.wrap(v)
  11.   end
  12. end
  13.  
  14.  
  15. if pim == nil then error("No PIM") end
  16. if stand == nil then error("No storage bus") end
  17.  
  18. local standdir = "north"
  19. local rsside = "bottom"
  20. local high = 10
  21. local low = 0
  22. local wait = 3
  23.  
  24. local w,h = monitor.getSize()
  25.  
  26. local armorMenu, menu
  27.  
  28. local armor = {}
  29. armor[1] = colors.orange
  30. armor[2] = colors.magenta
  31. armor[3] = colors.lightBlue
  32. armor[4] = colors.yellow
  33.  
  34. local lights = {}
  35. lights[1] = colors.lime
  36. lights[2] = colors.pink
  37. lights[3] = colors.gray
  38. lights[4] = colors.lightGray
  39.  
  40. local inUse = {}
  41. inUse[1] = false
  42. inUse[2] = false
  43. inUse[3] = false
  44. inUse[4] = false
  45.  
  46. --[[
  47. local lightSum = function()
  48.   local sum = 0
  49.   for i = 1,4 do
  50.     if not inUse[i] then sum = sum + lights[i] end
  51.   end
  52.   return sum
  53. end
  54. ]]--
  55.  
  56. local cutNetwork = function(n)
  57.   local current = rs.getBundledOutput(rsside)
  58.   rs.setBundledOutput(rsside,current-armor[n])
  59. end
  60.  
  61. local powerNetwork = function(n)
  62.   local current = rs.getBundledOutput(rsside)
  63.   rs.setBundledOutput(rsside,current+armor[n])
  64. end
  65.  
  66. local cutLights = function(n)
  67.   local current = rs.getBundledOutput(rsside)
  68.   rs.setBundledOutput(rsside,current-lights[n])
  69. end
  70.  
  71. local powerLights = function(n)
  72.   local current = rs.getBundledOutput(rsside)
  73.   rs.setBundledOutput(rsside,current+lights[n])
  74. end
  75.  
  76. local armorToStand = function(n)
  77.   if stand.getPriority() == high then
  78.     error("Stand not empty.")
  79.     return
  80.   end
  81.   stand.setPriority(high)
  82.   powerNetwork(n)
  83.   sleep(wait)
  84.   cutNetwork(n)
  85.   cutLights(n)
  86. end
  87.  
  88. local clearStand = function()
  89.   stand.setPriority(low)
  90.   for i=1,4 do powerNetwork(i) end
  91.   sleep(wait)
  92.   for i=1,4 do cutNetwork(i) end
  93. end
  94.  
  95. local equipArmor = function()
  96.   local inv = pim.getInvName()
  97.   if inv == "EmptyInventory" then return end
  98.   for i=39,36,-1 do
  99.     local data = pim.getStackInSlot(i)
  100.     if data ~= nil then
  101.       term.clear()
  102.       term.setTextColor(colors.red)
  103.       term.setCursorPos(math.floor((w-41)/2),math.floor(h/2))
  104.       term.write("Already wearing armor. Touch to continue.")
  105.       os.pullEvent("monitor_touch")
  106.       clearStand()
  107.       return false
  108.     end
  109.   end
  110.   pim.pullIntoSlot(standdir,0,1,39)
  111.   sleep(0.33)
  112.   pim.pullIntoSlot(standdir,1,1,38)
  113.   sleep(0.33)
  114.   pim.pullIntoSlot(standdir,2,1,37)
  115.   sleep(0.33)
  116.   pim.pullIntoSlot(standdir,3,1,36)
  117.   stand.setPriority(low)
  118.   return true
  119. end
  120.  
  121. local unequipArmor = function()
  122.   local inv = pim.getInvName()
  123.   if inv == "EmptyInventory" then return end
  124.   pim.pushIntoSlot(standdir,39,1,0)
  125.   sleep(0.33)
  126.   pim.pushIntoSlot(standdir,38,1,1)
  127.   sleep(0.33)
  128.   pim.pushIntoSlot(standdir,37,1,2)
  129.   sleep(0.33)
  130.   pim.pushIntoSlot(standdir,36,1,3)
  131.   stand.setPriority(high)
  132. end
  133.  
  134. local activateSuit = function(suit,n)
  135.   if inUse[n] then
  136.     term.setBackgroundColor(colors.black)
  137.     term.clear()
  138.     term.setCursorPos(math.floor((w-44)/2),math.floor(h/2))
  139.     term.write("Please stand on the suit pad to remove suit.")
  140.     while pim.getInvName() == "EmptyInventory" do
  141.       sleep(1)
  142.     end
  143.     unequipArmor()
  144.     sleep(1)
  145.     clearStand()
  146.     powerLights(n)
  147.     armorMenu[suit].color = colors.lime
  148.     inUse[n] = false
  149.   else
  150.     term.setBackgroundColor(colors.black)
  151.     term.clear()
  152.     term.setCursorPos(math.floor((w-43)/2),math.floor(h/2))
  153.     term.write("Please stand on the suit pad to equip suit.")
  154.     armorToStand(n)
  155.     while pim.getInvName() == "EmptyInventory" do
  156.       sleep(1)
  157.     end
  158.     if equipArmor() then
  159.       armorMenu[suit].color = colors.red
  160.       inUse[n] = true
  161.     else
  162.       powerLights(n)
  163.     end
  164.   end
  165. end
  166.  
  167. local printButton = function(button,color)
  168.   term.setBackgroundColor(color)
  169.   for j = 1,button.sizeY do
  170.       term.setCursorPos(button.X,button.Y+j-1)
  171.       term.write(string.rep(" ",button.sizeX))
  172.   end
  173.   if type(button.text) == "table" then
  174.     local n = #button.text
  175.     for i = 1,n do
  176.       term.setCursorPos(button.X+math.floor((button.sizeX-button.text[i]:len())/2),button.Y+math.floor((button.sizeY-n)/2)+i-1)
  177.       term.write(button.text[i])
  178.     end
  179.   else
  180.     term.setCursorPos(button.X+math.floor((button.sizeX-button.text:len())/2),button.Y+math.floor(button.sizeY/2))
  181.     term.write(button.text)
  182.   end
  183. end
  184.  
  185. local printButtons = function(buttons)
  186.   for k,v in pairs(buttons) do
  187.     printButton(v,v.color)
  188.   end
  189. end
  190.  
  191. local flashButton = function(button)
  192.   printButton(button, button.colorFlash)
  193.   sleep(0.2)
  194.   printButton(button, button.color)
  195.   sleep(0.1)
  196. end
  197.  
  198. local waitForButton = function(buttons)
  199.   local button
  200.   while button == nil do
  201.     local e, side, X, Y = os.pullEvent("monitor_touch")
  202.     for k,v in pairs(buttons) do
  203.         if X >= v.X and X <= v.X+v.sizeX and Y >= v.Y and Y <= v.Y+v.sizeY then
  204.           button = k
  205.           break
  206.         end
  207.     end
  208.   end
  209.   return button
  210. end
  211.  
  212. armorMenu =
  213. {
  214.   ["powersuit"] = {},
  215.   ["thaumium"] = {},
  216.   ["quantum"] = {},
  217.   ["nano"] = {},
  218. }
  219.  
  220. armorMenu["powersuit"].text = {"Power","Suit"}
  221. armorMenu["powersuit"].X = 2
  222. armorMenu["powersuit"].Y = math.floor((h-6)/2)
  223. armorMenu["powersuit"].sizeX = 11
  224. armorMenu["powersuit"].sizeY = 6
  225. armorMenu["powersuit"].color = colors.lime
  226. armorMenu["powersuit"].colorFlash= colors.red
  227. armorMenu["powersuit"].func = function () activateSuit("powersuit",1) end
  228.  
  229. armorMenu["thaumium"].text = {"Thaumium", "Armor"}
  230. armorMenu["thaumium"].X = 14
  231. armorMenu["thaumium"].Y = math.floor((h-6)/2)
  232. armorMenu["thaumium"].sizeX = 11
  233. armorMenu["thaumium"].sizeY = 6
  234. armorMenu["thaumium"].color = colors.lime
  235. armorMenu["thaumium"].colorFlash= colors.red
  236. armorMenu["thaumium"].func = function () activateSuit("thaumium",2) end
  237.  
  238. armorMenu["quantum"].text = {"Quantum", "Armor"}
  239. armorMenu["quantum"].X = 26
  240. armorMenu["quantum"].Y = math.floor((h-6)/2)
  241. armorMenu["quantum"].sizeX = 11
  242. armorMenu["quantum"].sizeY = 6
  243. armorMenu["quantum"].color = colors.lime
  244. armorMenu["quantum"].colorFlash= colors.red
  245. armorMenu["quantum"].func = function () activateSuit("quantum",3) end
  246.  
  247. armorMenu["nano"].text = {"Nano", "Armor"}
  248. armorMenu["nano"].X = 38
  249. armorMenu["nano"].Y = math.floor((h-6)/2)
  250. armorMenu["nano"].sizeX = 11
  251. armorMenu["nano"].sizeY = 6
  252. armorMenu["nano"].color = colors.lime
  253. armorMenu["nano"].colorFlash= colors.red
  254. armorMenu["nano"].func = function () activateSuit("nano",4) end
  255.  
  256.  
  257. term.redirect(monitor)
  258. term.setBackgroundColor(colors.black)
  259. term.clear()
  260. term.setTextColor(colors.red)
  261. term.setCursorPos(math.floor((w-15)/2),math.floor(h/2))
  262. term.write("Touch to start.")
  263. os.pullEvent("monitor_touch")
  264. term.clear()
  265. sleep(0.3)
  266.  
  267. term.setCursorPos(math.floor((w-15)/2),math.floor(h/2))
  268. textutils.slowWrite("Initializing...",15)
  269. for i=1,4 do powerLights(i) sleep(0.3) end
  270. clearStand()
  271.  
  272.  
  273. term.setBackgroundColor(colors.black)
  274. term.clear()
  275.  
  276. term.setTextColor(colors.yellow)
  277.  
  278. term.setCursorPos(math.floor((w-27)/2),3)
  279. term.write("Armor Selection System v1.0")
  280.  
  281. term.setTextColor(colors.white)
  282.  
  283. menu = armorMenu
  284.  
  285. while true do
  286.   term.setBackgroundColor(colors.black)
  287.   term.clear()
  288.   term.setTextColor(colors.yellow)
  289.   term.setCursorPos(math.floor((w-27)/2),3)
  290.   term.write("Armor Selection System v1.0")
  291.   term.setTextColor(colors.white)
  292.   printButtons(menu)
  293.   local b = waitForButton(armorMenu)
  294.   menu[b].func()
  295. end
Advertisement
Add Comment
Please, Sign In to add comment