mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-01-10 01:10:30 +00:00
speaker sound
command (#1747)
This commit is contained in:
parent
c764981a40
commit
b9ba2534a4
@ -132,9 +132,47 @@ elseif cmd == "play" then
|
|||||||
end
|
end
|
||||||
|
|
||||||
handle.close()
|
handle.close()
|
||||||
|
elseif cmd == "sound" then
|
||||||
|
local _, sound, volume, pitch, name = ...
|
||||||
|
|
||||||
|
if not sound then
|
||||||
|
error("Usage: speaker sound <sound> [volume] [pitch] [speaker]", 0)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if volume then
|
||||||
|
volume = tonumber(volume)
|
||||||
|
if not volume then
|
||||||
|
error("Volume must be a number", 0)
|
||||||
|
end
|
||||||
|
if volume < 0 or volume > 3 then
|
||||||
|
error("Volume must be between 0 and 3", 0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if pitch then
|
||||||
|
pitch = tonumber(pitch)
|
||||||
|
if not pitch then
|
||||||
|
error("Pitch must be a number", 0)
|
||||||
|
end
|
||||||
|
if pitch < 0 or pitch > 2 then
|
||||||
|
error("Pitch must be between 0 and 2", 0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local speaker = get_speakers(name)[1]
|
||||||
|
|
||||||
|
if speaker.playSound(sound, volume, pitch) then
|
||||||
|
print(("Played sound %q on speaker %q with volume %s and pitch %s."):format(
|
||||||
|
sound, peripheral.getName(speaker), volume or 1, pitch or 1
|
||||||
|
))
|
||||||
|
else
|
||||||
|
error(("Could not play sound %q"):format(sound), 0)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
local programName = arg[0] or fs.getName(shell.getRunningProgram())
|
||||||
print("Usage:")
|
print("Usage:")
|
||||||
print(programName .. " play <file or url> [speaker]")
|
print(programName .. " play <file or url> [speaker]")
|
||||||
|
print(programName .. " sound <sound> [volume] [pitch] [speaker]")
|
||||||
print(programName .. " stop [speaker]")
|
print(programName .. " stop [speaker]")
|
||||||
end
|
end
|
||||||
|
@ -117,7 +117,7 @@ shell.setCompletionFunction("rom/programs/fun/dj.lua", completion.build(
|
|||||||
completion.peripheral
|
completion.peripheral
|
||||||
))
|
))
|
||||||
shell.setCompletionFunction("rom/programs/fun/speaker.lua", completion.build(
|
shell.setCompletionFunction("rom/programs/fun/speaker.lua", completion.build(
|
||||||
{ completion.choice, { "play ", "stop " } },
|
{ completion.choice, { "play ", "sound ", "stop " } },
|
||||||
function(shell, text, previous)
|
function(shell, text, previous)
|
||||||
if previous[2] == "play" then return completion.file(shell, text, previous, true)
|
if previous[2] == "play" then return completion.file(shell, text, previous, true)
|
||||||
elseif previous[2] == "stop" then return completion.peripheral(shell, text, previous, false)
|
elseif previous[2] == "stop" then return completion.peripheral(shell, text, previous, false)
|
||||||
|
Loading…
Reference in New Issue
Block a user