Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ TABLES
- targets[Position offset from sensor]
- obj[RawName, Damagevalue, Name, Position, Slots, InventoryPercentFull, TotalSpace, ItemCount]
- ]]--
- local mySensor = peripheral.find('sensor')
- local modem = peripheral.find('modem')
- local monitor = peripheral.find('monitor')
- local targets = mySensor.getTargets()
- local dataset = {}
- local reactor_pos
- local reactor_detail
- local isUpdated = true
- local chnl = 7200
- local chnl_re = 7201
- if monitor ~= nil then
- term.redirect(monitor)
- monitor.setTextScale(0.5)
- end
- function FindReactor()
- print('Finding Reactor...')
- for k, v in pairs(targets) do
- local obj = mySensor.getTargetDetails(k)
- if string.find(obj.Name, 'Reactor') then
- print('Reactor Found: ' .. obj.Name)
- dataset['Reactor_Data'] = obj
- local reactor_posTbl = dataset.Reactor_Data.Position
- reactor_pos = (tostring(reactor_posTbl.X) .. ',' .. tostring(reactor_posTbl.Y) .. ',' .. tostring(reactor_posTbl.Z))
- return dataset
- end
- end
- if dataset.Reactor_Data == nil then print('No reactor found.') end
- end
- function UpdateData()
- print('Finding Fuel Rod...')
- os.sleep(1)
- dataset['Reactor_Data'].Slots = mySensor.getTargetDetails(reactor_pos).Slots
- for k, v in pairs(dataset.Reactor_Data.Slots) do
- if string.find(v.Name, 'Fuel Rod') then
- print('Fuel Rod Found: ' .. v.Name)
- dataset['Rod_Data'] = v
- print('Rod data assigned')
- return dataset
- end
- end
- if dataset.Rod_Data == nil then print('No rod found.') end
- end
- function PushData()
- local timer = os.startTimer(30)
- print('Wating for PullEvent...')
- local evt = {os.pullEvent()}
- local isReactor_Powered = redstone.testBundledInput('back', colors.lightBlue)
- dataset['Reactor_State'] = isReactor_Powered
- if evt[1] == 'peripheral_detach' then
- isUpdated = true
- modem.transmit(chnl_re, chnl, dataset)
- elseif evt[1] == 'timer' then
- isUpdated = true
- modem.transmit(chnl_re, chnl, dataset)
- else isUpdated = false end
- print(evt[1])
- os.cancelTimer(timer)
- end
- FindReactor()
- while true do
- while isUpdated do
- UpdateData()
- isUpdated = false
- end
- PushData()
- if monitor == nil then
- term.setCursorPos(1,1)
- term.clear()
- end
- end
Add Comment
Please, Sign In to add comment