Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Set the time for noon (Minecraft hours)
- local noonHour = 12
- local speakerSides = {
- "top", -- Top speaker
- "left", -- Left speaker
- "bottom", -- Bottom speaker
- "right" -- Right speaker
- }
- -- Define the notes and duration of the jingle
- local notes = {
- {pitch = 5}, -- Start with a lower note
- {pitch = 7}, -- Move up to the next note
- {pitch = 9}, -- Continue ascending
- {pitch = 7}, -- Return to the previous note
- {pitch = 5}, -- Finish with the starting note
- {pitch = 9}, -- Add a higher note for variation
- {pitch = 12}, -- Ascend to a higher note
- {pitch = 9}, -- Return to a previous higher note
- {pitch = 7}, -- Go back down
- {pitch = 5} -- Finish the melody
- }
- -- Function to play the jingle on the speakers
- local function playJingle()
- -- Wrap the speakers
- local speakers = {}
- for _, side in ipairs(speakerSides) do
- speakers[side] = peripheral.wrap(side)
- end
- -- Play the jingle
- for _, noteData in ipairs(notes) do
- for _, side in ipairs(speakerSides) do
- local speaker = speakers[side]
- speaker.playNote("bell", 1, noteData.pitch)
- end
- os.sleep(0.5)
- end
- end
- -- Function to check the time and redstone signal, and play the jingle
- local function checkTimeAndPlayJingle()
- while true do
- -- Get the current Minecraft hour
- local currentHour = os.date("*t").hour -- Assuming os.date is used to get the hour in Minecraft time format
- -- Check if it's around noon or if there's a redstone signal on the front side
- local isNoon = math.abs(currentHour - noonHour) < 0.1
- local hasRedstoneSignal = redstone.getInput("front") -- Check redstone signal on the front side
- if isNoon or hasRedstoneSignal then
- playJingle()
- -- Print to indicate the jingle is playing
- print("Playing jingle with bells")
- -- Wait for a bit before checking again to avoid repeated triggers
- os.sleep(7) -- Check every minute
- end
- -- Yield to avoid excessive CPU usage
- os.sleep(1) -- Yield every second to reduce CPU load
- end
- end
- -- Run the function
- checkTimeAndPlayJingle()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement