Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Program created by Skip_21
- -- Require PeripheralsPlusOne
- -- Currently a W.I.P (Work In Progress)
- -- alpha 1.4 changelog :
- -- Added Thermal Expansion support of Energy Storage
- -- alpha 1.5 changelog :
- -- Added IC2 support of Energy Storage
- version = "alpha 1.5"
- fails = 0
- pblocks = {}
- knownperipherals = {"playerSensor", "oreDictionary", "environmentScanner",
- "speaker", "aiChatBox", "beeAnalyzer", "treeAnalyzer", "butterflyAnalyzer",
- "teleporter", "peripheralContainer", "meBridge", "timeSensor",
- "interactiveSorter", "playerInterface", "Induction Matrix",
- "BigReactors-Reactor", "BigReactors-Turbine", "thermalexpansion:storage_cell",
- "techreborn:interdimensional_su", "ic2:batbox", "ic2:oldmfe", "ic2:oldmfsu" }
- function searchlist(searchfor,list)
- for i=1,#list do
- if list[i]==searchfor then return true end
- end
- return false
- end
- function addperipheral(side)
- local result = false
- thistype = peripheral.getType(side)
- if searchlist(thistype,knownperipherals) then
- print("Attaching to the "..side.." ("..thistype..")")
- table.insert(pblocks,{peripheral.wrap(side), thistype, side})
- result = true
- end
- return result
- end
- function timedmessages()
- local sleepytime = 2
- -- Peripherals checking
- local i = 1
- while i <= #pblocks do
- local rtype = peripheral.getType(pblocks[i][3])
- if rtype == pblocks[i][2] then
- i = i + 1
- else
- print(pblocks[i][2].." on "..pblocks[i][3].."has gone missing: removing.")
- table.remove(pblocks,i)
- end
- end
- for i = 1, #pblocks do
- if pblocks[i][2] == "BigReactors-Reactor" then
- emax = peripheral.wrap(pblocks[i][3]).getEnergyCapacity()
- estor = peripheral.wrap(pblocks[i][3]).getEnergyStored()
- eout = peripheral.wrap(pblocks[i][3]).getEnergyProducedLastTick()
- heat = peripheral.wrap(pblocks[i][3]).getCasingTemperature()
- fuse = peripheral.wrap(pblocks[i][3]).getFuelConsumedLastTick()
- rin = peripheral.wrap(pblocks[i][3]).getControlRodLevel(1)
- percent = (estor/emax)*100
- peripheral.wrap(pblocks[i][3]).setAllControlRodLevels(percent)
- local message = {estor, emax, eout, heat, fuse, rin, percent}
- rednet.send(shserver, message, "reactor")
- elseif pblocks[i][2] == "Induction Matrix" then
- emax = peripheral.wrap(pblocks[i][3]).getMaxEnergy()
- estor = peripheral.wrap(pblocks[i][3]).getEnergy()
- ein = peripheral.wrap(pblocks[i][3]).getInput()
- eout = peripheral.wrap(pblocks[i][3]).getOutput()
- local message = {emax, estor, ein, eout}
- rednet.send(shserver, message, "matrix")
- elseif pblocks[i][2] == "techreborn:interdimensional_su" then
- emax = 100000000
- estor = emax - peripheral.wrap(pblocks[i][3]).getDemandedEnergy()
- local message = {emax, estor}
- rednet.send(shserver, message, "IDSU")
- elseif (pblocks[i][2] == "ic2:batbox") or (pblocks[i][2] == "ic2:oldmfe") or (pblocks[i][2] == "ic2:oldmfsu") then
- if pblocks[i][2] == "ic2:batbox" then
- emax = 40000
- estor = emax - peripheral.wrap(pblocks[i][3]).getDemandedEnergy()
- local message = {emax, estor}
- rednet.send(shserver, message, "ic2")
- elseif pblocks[i][2] == "ic2:oldmfe" then
- emax = 600000
- estor = emax - peripheral.wrap(pblocks[i][3]).getDemandedEnergy()
- local message = {emax, estor}
- rednet.send(shserver, message, "ic2")
- elseif pblocks[i][2] == "ic2:oldmfsu" then
- emax = 10000000
- estor = emax - peripheral.wrap(pblocks[i][3]).getDemandedEnergy()
- local message = {emax, estor}
- rednet.send(shserver, message, "ic2")
- end
- end
- end
- return sleepytime
- end
- function br(x)
- print("Yolo !")
- end
- function eventlistener()
- local event, p1, p2, p3 = os.pullEvent()
- if event == "rednet_message" and p3 == "shserver" then
- if p2[1] == "reboot" then print("Rebooting...") sleep(2) os.reboot() end
- if p2[1] == "br" then br(p2) end
- elseif event=="timer" and p1==timedmessage then
- timedmessage = os.startTimer(timedmessages())
- end
- end
- -- Init
- term.clear()
- term.setCursorPos(1,1)
- print("Skip_21's Smart Helmet "..version.." running !")
- sleep(2)
- if (os.getComputerLabel()==nil) then
- print("Setting computer label to 'SHClient'.")
- os.setComputerLabel("SHClient")
- end
- sides = peripheral.getNames()
- modemhere = false
- for i = 1, #sides do
- thistype = peripheral.getType(sides[i])
- if thistype == "modem" then
- print("Modem found on " .. sides[i] .. ", connecting...")
- rednet.open(sides[i])
- modemhere = true
- end
- end
- if not modemhere then error("Please connect a Wireless Modem") end
- shserver = rednet.lookup("shserver","shserver")
- while shserver == nil do
- fails = fails + 1
- print("Can't find SHserver. Waiting ... ("..fails..")")
- os.sleep(10)
- shserver = rednet.lookup("shserver","shserver")
- end
- print("Found SHServer! Sending handshake.")
- rednet.send(shserver,"hello","handshake")
- print("Running ...")
- -- peripherals Lookup
- local count = 0
- for i=1, #sides do
- if addperipheral(sides[i]) then count = count + 1 end
- end
- if count==0 then
- error("No recognised peripherals. Aborting.")
- else
- print("Attached to "..count.." recognised peripherals.")
- end
- -- main loop
- timedmessage = os.startTimer(5)
- while true do
- eventlistener()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement