Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local monitor = peripheral.wrap("top")
- local wired = peripheral.wrap("back")
- local stand
- local pim
- for k,v in pairs(wired.getNamesRemote()) do
- local type = wired.getTypeRemote(v)
- if type == "me_fuzzy_storage_bus" then
- stand = peripheral.wrap(v)
- elseif type == "pim" then
- pim = peripheral.wrap(v)
- end
- end
- if pim == nil then error("No PIM") end
- if stand == nil then error("No storage bus") end
- local standdir = "north"
- local rsside = "bottom"
- local high = 10
- local low = 0
- local wait = 3
- local w,h = monitor.getSize()
- local armorMenu, menu
- local armor = {}
- armor[1] = colors.orange
- armor[2] = colors.magenta
- armor[3] = colors.lightBlue
- armor[4] = colors.yellow
- local lights = {}
- lights[1] = colors.lime
- lights[2] = colors.pink
- lights[3] = colors.gray
- lights[4] = colors.lightGray
- local inUse = {}
- inUse[1] = false
- inUse[2] = false
- inUse[3] = false
- inUse[4] = false
- --[[
- local lightSum = function()
- local sum = 0
- for i = 1,4 do
- if not inUse[i] then sum = sum + lights[i] end
- end
- return sum
- end
- ]]--
- local cutNetwork = function(n)
- local current = rs.getBundledOutput(rsside)
- rs.setBundledOutput(rsside,current-armor[n])
- end
- local powerNetwork = function(n)
- local current = rs.getBundledOutput(rsside)
- rs.setBundledOutput(rsside,current+armor[n])
- end
- local cutLights = function(n)
- local current = rs.getBundledOutput(rsside)
- rs.setBundledOutput(rsside,current-lights[n])
- end
- local powerLights = function(n)
- local current = rs.getBundledOutput(rsside)
- rs.setBundledOutput(rsside,current+lights[n])
- end
- local armorToStand = function(n)
- if stand.getPriority() == high then
- error("Stand not empty.")
- return
- end
- stand.setPriority(high)
- powerNetwork(n)
- sleep(wait)
- cutNetwork(n)
- cutLights(n)
- end
- local clearStand = function()
- stand.setPriority(low)
- for i=1,4 do powerNetwork(i) end
- sleep(wait)
- for i=1,4 do cutNetwork(i) end
- end
- local equipArmor = function()
- local inv = pim.getInvName()
- if inv == "EmptyInventory" then return end
- for i=39,36,-1 do
- local data = pim.getStackInSlot(i)
- if data ~= nil then
- term.clear()
- term.setTextColor(colors.red)
- term.setCursorPos(math.floor((w-41)/2),math.floor(h/2))
- term.write("Already wearing armor. Touch to continue.")
- os.pullEvent("monitor_touch")
- clearStand()
- return false
- end
- end
- pim.pullIntoSlot(standdir,0,1,39)
- sleep(0.33)
- pim.pullIntoSlot(standdir,1,1,38)
- sleep(0.33)
- pim.pullIntoSlot(standdir,2,1,37)
- sleep(0.33)
- pim.pullIntoSlot(standdir,3,1,36)
- stand.setPriority(low)
- return true
- end
- local unequipArmor = function()
- local inv = pim.getInvName()
- if inv == "EmptyInventory" then return end
- pim.pushIntoSlot(standdir,39,1,0)
- sleep(0.33)
- pim.pushIntoSlot(standdir,38,1,1)
- sleep(0.33)
- pim.pushIntoSlot(standdir,37,1,2)
- sleep(0.33)
- pim.pushIntoSlot(standdir,36,1,3)
- stand.setPriority(high)
- end
- local activateSuit = function(suit,n)
- if inUse[n] then
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(math.floor((w-44)/2),math.floor(h/2))
- term.write("Please stand on the suit pad to remove suit.")
- while pim.getInvName() == "EmptyInventory" do
- sleep(1)
- end
- unequipArmor()
- sleep(1)
- clearStand()
- powerLights(n)
- armorMenu[suit].color = colors.lime
- inUse[n] = false
- else
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(math.floor((w-43)/2),math.floor(h/2))
- term.write("Please stand on the suit pad to equip suit.")
- armorToStand(n)
- while pim.getInvName() == "EmptyInventory" do
- sleep(1)
- end
- if equipArmor() then
- armorMenu[suit].color = colors.red
- inUse[n] = true
- else
- powerLights(n)
- end
- end
- end
- local printButton = function(button,color)
- term.setBackgroundColor(color)
- for j = 1,button.sizeY do
- term.setCursorPos(button.X,button.Y+j-1)
- term.write(string.rep(" ",button.sizeX))
- end
- if type(button.text) == "table" then
- local n = #button.text
- for i = 1,n do
- term.setCursorPos(button.X+math.floor((button.sizeX-button.text[i]:len())/2),button.Y+math.floor((button.sizeY-n)/2)+i-1)
- term.write(button.text[i])
- end
- else
- term.setCursorPos(button.X+math.floor((button.sizeX-button.text:len())/2),button.Y+math.floor(button.sizeY/2))
- term.write(button.text)
- end
- end
- local printButtons = function(buttons)
- for k,v in pairs(buttons) do
- printButton(v,v.color)
- end
- end
- local flashButton = function(button)
- printButton(button, button.colorFlash)
- sleep(0.2)
- printButton(button, button.color)
- sleep(0.1)
- end
- local waitForButton = function(buttons)
- local button
- while button == nil do
- local e, side, X, Y = os.pullEvent("monitor_touch")
- for k,v in pairs(buttons) do
- if X >= v.X and X <= v.X+v.sizeX and Y >= v.Y and Y <= v.Y+v.sizeY then
- button = k
- break
- end
- end
- end
- return button
- end
- armorMenu =
- {
- ["powersuit"] = {},
- ["thaumium"] = {},
- ["quantum"] = {},
- ["nano"] = {},
- }
- armorMenu["powersuit"].text = {"Power","Suit"}
- armorMenu["powersuit"].X = 2
- armorMenu["powersuit"].Y = math.floor((h-6)/2)
- armorMenu["powersuit"].sizeX = 11
- armorMenu["powersuit"].sizeY = 6
- armorMenu["powersuit"].color = colors.lime
- armorMenu["powersuit"].colorFlash= colors.red
- armorMenu["powersuit"].func = function () activateSuit("powersuit",1) end
- armorMenu["thaumium"].text = {"Thaumium", "Armor"}
- armorMenu["thaumium"].X = 14
- armorMenu["thaumium"].Y = math.floor((h-6)/2)
- armorMenu["thaumium"].sizeX = 11
- armorMenu["thaumium"].sizeY = 6
- armorMenu["thaumium"].color = colors.lime
- armorMenu["thaumium"].colorFlash= colors.red
- armorMenu["thaumium"].func = function () activateSuit("thaumium",2) end
- armorMenu["quantum"].text = {"Quantum", "Armor"}
- armorMenu["quantum"].X = 26
- armorMenu["quantum"].Y = math.floor((h-6)/2)
- armorMenu["quantum"].sizeX = 11
- armorMenu["quantum"].sizeY = 6
- armorMenu["quantum"].color = colors.lime
- armorMenu["quantum"].colorFlash= colors.red
- armorMenu["quantum"].func = function () activateSuit("quantum",3) end
- armorMenu["nano"].text = {"Nano", "Armor"}
- armorMenu["nano"].X = 38
- armorMenu["nano"].Y = math.floor((h-6)/2)
- armorMenu["nano"].sizeX = 11
- armorMenu["nano"].sizeY = 6
- armorMenu["nano"].color = colors.lime
- armorMenu["nano"].colorFlash= colors.red
- armorMenu["nano"].func = function () activateSuit("nano",4) end
- term.redirect(monitor)
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setTextColor(colors.red)
- term.setCursorPos(math.floor((w-15)/2),math.floor(h/2))
- term.write("Touch to start.")
- os.pullEvent("monitor_touch")
- term.clear()
- sleep(0.3)
- term.setCursorPos(math.floor((w-15)/2),math.floor(h/2))
- textutils.slowWrite("Initializing...",15)
- for i=1,4 do powerLights(i) sleep(0.3) end
- clearStand()
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setTextColor(colors.yellow)
- term.setCursorPos(math.floor((w-27)/2),3)
- term.write("Armor Selection System v1.0")
- term.setTextColor(colors.white)
- menu = armorMenu
- while true do
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setTextColor(colors.yellow)
- term.setCursorPos(math.floor((w-27)/2),3)
- term.write("Armor Selection System v1.0")
- term.setTextColor(colors.white)
- printButtons(menu)
- local b = waitForButton(armorMenu)
- menu[b].func()
- end
Advertisement
Add Comment
Please, Sign In to add comment