Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- redstonePL-01.lua
- local modem = peripheral.find("modem") or error("No modem attached", 0)
- print("Input the controlChannel, default = 500")
- local controlChannel = io.read()
- if controlChannel == "" then
- controlChannel = 500
- end
- controlChannel = tonumber(controlChannel)
- -- Redstone sides for cannon, autocannon, and smoke grenades
- local cannonSide = "back"
- local autocannonSide = "right"
- local smokeGrenadeSide = "front"
- modem.open(controlChannel)
- print("Redstone controller started. Listening for fire controls.")
- local controls = {
- fireCannon = false,
- fireAutocannon = false,
- launchSmokeGrenade = false
- }
- local function executeControls()
- while true do
- -- Fire controls
- if controls.fireCannon then
- redstone.setOutput(cannonSide, true)
- else
- redstone.setOutput(cannonSide, false)
- end
- if controls.fireAutocannon then
- redstone.setOutput(autocannonSide, true)
- else
- redstone.setOutput(autocannonSide, false)
- end
- if controls.launchSmokeGrenade then
- redstone.setOutput(smokeGrenadeSide, true)
- sleep(0.1) -- Short delay to ensure activation
- redstone.setOutput(smokeGrenadeSide, false)
- controls.launchSmokeGrenade = false -- Reset the control after activation
- end
- sleep(0.05) -- Adjust the delay for control responsiveness
- end
- end
- -- Function to listen for modem messages and update controls
- local function modem_message()
- while true do
- local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
- if channel == controlChannel then
- controls = message
- print("Received controls:", textutils.serialize(controls))
- end
- end
- end
- -- Run the functions in parallel
- parallel.waitForAll(
- modem_message,
- executeControls
- )
Advertisement
Add Comment
Please, Sign In to add comment