Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- CONFIGURATION --
- local redstoneSide = "bottom" -- Side where redstone is connected
- local listenChannel = 128 -- Wireless modem listen channel
- local inverted = false -- Invert redstone
- -- Function to request and store the spawner ID
- local function askForID()
- local idFile = "id_spawner.txt"
- -- Check if the ID file already exists
- if fs.exists(idFile) then
- local file = fs.open(idFile, "r")
- local id = tonumber(file.readAll())
- file.close()
- return id
- else
- write("Enter the spawner ID: ")
- local id = tonumber(read())
- local file = fs.open(idFile, "w")
- file.write(tostring(id))
- file.close()
- return id
- end
- end
- -- Ask for the spawner ID (and save it if first launch)
- local SPAWNER_ID = askForID()
- local modem = peripheral.find("modem")
- if not modem then
- error("No modem detected")
- end
- modem.open(listenChannel) -- Open listening channel
- redstone.setOutput(redstoneSide, false) -- Disable redstone by default
- -- Function to get the current time in HH:mm:ss_DD/MM format
- local function getTimestamp()
- local t = os.date("*t")
- return string.format("%02d:%02d:%02d_%02d/%02d", t.hour, t.min, t.sec, t.day, t.month)
- end
- print("Waiting for commands for spawner ID: " .. SPAWNER_ID)
- while true do
- local event, side, senderChannel, replyChannel, message = os.pullEvent("modem_message")
- if type(message) == "table" and message.id == SPAWNER_ID then
- local state = message.state
- -- Apply inverted mode
- if inverted then
- state = not state
- end
- redstone.setOutput(redstoneSide, state)
- local timestamp = getTimestamp()
- print("[" .. timestamp .. "] Spawner " .. SPAWNER_ID .. " " ..
- ((state and not inverted) or (not state and inverted) and "activated" or "deactivated"))
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment