Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Script: play_cogs_on_any_redstone_event.lua
- -- Description: Plays the "create:cogs" sound when any redstone signal is detected using event-based approach.
- local speaker = peripheral.wrap("left") -- Wraps the speaker on the left side
- -- Verify if the speaker peripheral exists
- if not speaker then
- print("Error: No speaker found on the left side!")
- return
- end
- print("Waiting for redstone signal on any side...")
- -- Function to check if any side has an active redstone signal
- local function isRedstoneOn()
- local sides = {"top", "bottom", "left", "right", "front", "back"}
- for _, side in ipairs(sides) do
- if redstone.getInput(side) then
- return true
- end
- end
- return false
- end
- while true do
- -- Wait for a redstone event (triggers only on redstone state change)
- os.pullEvent("redstone")
- -- Check if there’s an active redstone signal on any side
- if isRedstoneOn() then
- -- Play the 'create:cogs' sound at volume 1 and pitch 1
- speaker.playSound("create:cogs", 0.4, 2)
- print("Playing sound: create:cogs")
- -- Optional: Wait a bit before accepting new signals (e.g., 1 second)
- sleep(1)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement