Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local api = {}
- local function openRednet()
- local side
- peripheral.find("modem", function(name, modem)
- if modem.isWireless() then
- side = name
- end
- end)
- if not rednet.isOpen(side) then
- rednet.open(side)
- end
- end
- api.broadcastRednet = {
- pars = { 1, 2 },
- fct = function(message, protocol)
- openRednet()
- rednet.broadcast(getTableSaveText({ data = message }), protocol)
- end
- }
- api.sendRednet = {
- pars = { 2, 3 },
- fct = function(recipient, message, protocol)
- openRednet()
- return rednet.send(recipient, getTableSaveText({ data = message }), protocol)
- end
- }
- api.receiveRednet = {
- pars = { 0, 2 },
- fct = function(protocol, timeout)
- openRednet()
- local id, message = rednet.receive(protocol, timeout)
- if id == nil then
- return { nil, nil }
- end
- return { id, getTableFromSaveText(message).data }
- end
- }
- return {
- name = "rednet",
- api = api
- }
Advertisement
Advertisement