-
Notifications
You must be signed in to change notification settings - Fork 0
/
music_player.txt
903 lines (706 loc) · 22.2 KB
/
music_player.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
--@name Music Player
--@author legokidlogan
--@shared
--@include lkl/music_player_songs.txt
--@include lkl/easy_bass.txt
--@include lkl/chat_cmds_multi.txt
--[[
- Songs and playlists are defined in lkl/music_player_songs.txt
- Chat commands are prefixed with /music
- Commands: play, stop, skip, restart, playlist, volume, loop, shuffle
- Wire inputs can also be used to control the music player.
- If this is being require()'d in another script:
- Before running require():
- Be sure to do musicPlayer = musicPlayer or {}
- You can override each config setting by doing musicPlayer.SettingName = value
- You can change projectNameID and ccmdPrefix if you want to use different print names and chat command prefixes.
- Most of the basic functions are exposed in the musicPlayer table, shown later in this file.
- They aren't thoroughly documented due to their simplicty, just follow the variable names.
- These functions are server-only.
- A short delay after the client realm is ready, wire inputs will update and server will hook.run( "LKL_MusicPlayer_Initialized" )
- After this point, you can be assured that both relams are synced up and ready to go.
--]]
musicPlayer = musicPlayer or {}
-- CONFIG:
musicPlayer.DEFAULTS = {
VOLUME_DEFAULT = 0.5, -- Default volume setting.
LOOP_DEFAULT = true, -- Default loop setting.
SHUFFLE_DEFAULT = true, -- Default shuffle setting.
PLAYLIST_DEFAULT = false, -- Playlist to automatically select on startup. Set to false to disable.
SONG_DEFAULT = "TestSong1", -- Song to automatically play on startup. Can be the name of a defined song, or a custom URL. Set to false to disable.
FADE_START = 700,
FADE_END = 1500,
STALE_THRESHOLD = 100, -- Amount of ticks before a song is considered stale and is destroyed. May cause problems for songs with long periods of silence.
PLAY_ON_CHIP = false, -- false: play sound on the owner, true: play sound on the chip.
USE_CHAT_COMMANDS = true, -- false: only wire inputs can change settings, true: chat commands and wire inputs can both change settings.
}
-- END CONFIG
do
for setting, value in pairs( musicPlayer.DEFAULTS ) do
local curValue = musicPlayer[setting]
if curValue == nil then
musicPlayer[setting] = value
else
musicPlayer[setting] = curValue
end
end
end
local ccmdPrefix = ccmdPrefix or "/music"
local ccmdName = "MusicPlayer"
projectNameID = projectNameID or ccmdName
require( "lkl/chat_cmds_multi.txt" )
local loopEnabled = musicPlayer.LOOP_DEFAULT
local curVolume = musicPlayer.VOLUME_DEFAULT
local curSongURL = nil
if CLIENT then
require( "lkl/easy_bass.txt" )
local curSongBass = nil
local songIsPlaying = false
local startSong
function musicPlayer.getSongBassObject()
return curSongBass
end
function musicPlayer.isSongPlaying()
return songIsPlaying
end
function musicPlayer.getVolume()
return curVolume
end
local function destroyCurSong()
hook.remove( "think", "LKL_MusicPlayer_TrackSongDeath" )
if isValid( curSongBass ) then
curSongBass:pause()
curSongBass:stop()
end
curSongBass = nil
songIsPlaying = false
hook.run( "LKL_MusicPlayer_SongBassObjectChanged", nil )
end
local function notifySongEnd()
if player() ~= owner() then return end
net.start( "LKL_MusicPlayer_SongEnded" )
net.send()
end
local function trackSongDeath()
if player() ~= owner() then return end
hook.add( "think", "LKL_MusicPlayer_TrackSongDeath", function()
if isValid( curSongBass ) then return end
if loopEnabled then
startSong()
else
destroyCurSong()
notifySongEnd()
end
end )
end
startSong = function( url )
destroyCurSong()
curSongURL = url or curSongURL
easyBass.loadURL(
curSongURL,
{
Flags = "3d stereo noblock noplay",
Volume = curVolume,
Pitch = 1,
FadeStart = musicPlayer.FADE_START,
FadeEnd = musicPlayer.FADE_END,
FadeIn = 0,
FadeOut = 0,
Duration = nil,
Target = musicPlayer.PLAY_ON_CHIP and chip() or owner(),
Loop = loopEnabled,
DestroyWhenDone = true,
StaleThreshold = musicPlayer.STALE_THRESHOLD,
},
function( bassObj )
curSongBass = bassObj
songIsPlaying = true
trackSongDeath()
hook.run( "LKL_MusicPlayer_SongBassObjectChanged", bassObj )
end
)
end
net.receive( "LKL_MusicPlayer_StartSong", function()
local url = net.readString()
startSong( url )
end )
net.receive( "LKL_MusicPlayer_StopSong", function()
destroyCurSong()
end )
net.receive( "LKL_MusicPlayer_SetVolume", function()
curVolume = net.readFloat()
if isValid( curSongBass ) then
curSongBass:setVolume( curVolume )
end
hook.run( "LKL_MusicPlayer_VolumeChanged", curVolume )
end )
net.receive( "LKL_MusicPlayer_SetLoop", function()
loopEnabled = net.readBool()
if isValid( curSongBass ) then
curSongBass:setLooping( loopEnabled )
end
end )
if player() == owner() then
net.start( "LKL_MusicPlayer_ClientInit" )
net.send()
end
return
end
local SONGS, PLAYLISTS = unpack( require( "lkl/music_player_songs.txt" ) )
local SONG_COUNT = #SONGS
local shuffleEnabled = musicPlayer.SHUFFLE_DEFAULT
local curSongIsCustom = false
local curSongInd = 1
local curPlaylistInd = 0
local curPlaylistSubInd = 1
local songsAreStopped = true
local chipLink = chip():getWirelink()
local songLookup = {}
local playlistLookup = {}
local deselectWords = {
none = true,
nothing = true,
off = true,
deselect = true,
}
inputNames = inputNames or {}
inputTypes = inputTypes or {}
table.insert( inputNames, "PlaySongIndex" )
table.insert( inputTypes, "NUMBER" )
table.insert( inputNames, "PlaySongNameOrURL" )
table.insert( inputTypes, "STRING" )
table.insert( inputNames, "SkipSong" )
table.insert( inputTypes, "NUMBER" )
table.insert( inputNames, "RestartSong" )
table.insert( inputTypes, "NUMBER" )
table.insert( inputNames, "SelectPlaylistIndex" )
table.insert( inputTypes, "NUMBER" )
table.insert( inputNames, "SelectPlaylistName" )
table.insert( inputTypes, "STRING" )
table.insert( inputNames, "SetVolume" )
table.insert( inputTypes, "NUMBER" )
table.insert( inputNames, "SetLoop" )
table.insert( inputTypes, "NUMBER" )
table.insert( inputNames, "SetShuffle" )
table.insert( inputTypes, "NUMBER" )
outputNames = outputNames or {}
outputTypes = outputTypes or {}
table.insert( outputNames, "IsPlaying" )
table.insert( outputTypes, "NUMBER" )
table.insert( outputNames, "SongIndex" )
table.insert( outputTypes, "NUMBER" )
table.insert( outputNames, "SongName" )
table.insert( outputTypes, "STRING" )
table.insert( outputNames, "PlaylistIndex" )
table.insert( outputTypes, "NUMBER" )
table.insert( outputNames, "PlaylistName" )
table.insert( outputTypes, "STRING" )
local function getSongName( songInd )
if not songInd then return "" end
return SONGS[songInd].Name or ""
end
local function getSongIndex( songName )
if not songName then return 0 end
return songLookup[songName:lower()] or 0
end
local function getPlaylistIndex( playlistName )
if not playlistName then return 0 end
return playlistLookup[playlistName:lower()] or 0
end
local function getPlaylistSubIndex( songInd )
if curPlaylistInd == 0 then return 1 end
local playlist = PLAYLISTS[curPlaylistInd]
return table.keyFromValue( playlist.Songs, getSongName( songInd ) ) or 1
end
local function getCurPlaylistName()
if curPlaylistInd == 0 then return "" end
return PLAYLISTS[curPlaylistInd].Name
end
local function getRandomIndex( cur, count )
if count == 1 then return 1 end
local ind = cur
local attempts = 0
while ind == cur do
if attempts >= 5 then
return ( cur % count ) + 1
end
ind = math.random( 1, count )
attempts = attempts + 1
end
return ind
end
local function getNextSongIndex()
if curPlaylistInd == 0 then
if shuffleEnabled then return getRandomIndex( curSongInd, SONG_COUNT ) end
return ( curSongInd % SONG_COUNT ) + 1
end
local playlist = PLAYLISTS[curPlaylistInd]
local songNames = playlist.Songs
local playlistSongCount = #songNames
local subInd
if shuffleEnabled then
subInd = getRandomIndex( curPlaylistSubInd, playlistSongCount )
else
subInd = ( curPlaylistSubInd % playlistSongCount ) + 1
end
return getSongIndex( songNames[subInd] )
end
local function getSongIndexOrURL( indexOrNameOrURL )
local ind = tonumber( indexOrNameOrURL )
if ind == 0 then return 0 end
ind = ind or getSongIndex( indexOrNameOrURL )
if ind == 0 then return indexOrNameOrURL end -- Custom URL
return ind
end
local function isSongValid( indexOrURL )
if type( indexOrURL ) == "string" then return true end
return SONGS[indexOrURL] ~= nil
end
local function playSong( indexOrNameOrURL )
songsAreStopped = false
local printTbl = easyPrint.chipNamePrefix( ccmdScheme )
local indexOrURL = getSongIndexOrURL( indexOrNameOrURL or curSongInd )
local ind = type( indexOrURL ) == "number" and indexOrURL
local url
if ind then
local song = SONGS[ind]
local songName = song.Name
url = song.URL
curSongInd = ind
curPlaylistSubInd = getPlaylistSubIndex( ind )
curSongIsCustom = false
wire.ports.SongIndex = ind
wire.ports.SongName = songName
table.add( printTbl, {
ccmdScheme:getColor( "Text" ), "Now playing ",
ccmdScheme:getColor( "Highlight" ), songName,
ccmdScheme:getColor( "Text" ), ".",
} )
else
url = indexOrURL
curSongIsCustom = true
wire.ports.SongIndex = 0
wire.ports.SongName = ""
table.add( printTbl, {
ccmdScheme:getColor( "Text" ), "Now playing custom URL ",
ccmdScheme:getColor( "HighlightWeak" ), url,
} )
end
print( unpack( printTbl ) )
curSongURL = url
wire.ports.IsPlaying = 1
net.start( "LKL_MusicPlayer_StartSong" )
net.writeString( url )
net.send()
end
local function restartSong()
if curSongIsCustom then
playSong( curSongURL )
else
playSong( curSongInd )
end
end
local function stopSongs()
local printTbl = easyPrint.chipNamePrefix( ccmdScheme )
table.add( printTbl, {
ccmdScheme:getColor( "Text" ), "Song playback has been ",
ccmdScheme:getColor( "false" ), "stopped",
ccmdScheme:getColor( "Text" ), ".",
} )
print( unpack( printTbl ) )
songsAreStopped = true
wire.ports.IsPlaying = 0
net.start( "LKL_MusicPlayer_StopSong" )
net.send()
end
local function isPlaylistValid( indexOrName )
if type( indexOrName ) == "string" then return isPlaylistValid( getPlaylistIndex( indexOrName ) ) end
return PLAYLISTS[indexOrName] ~= nil
end
local function selectPlaylist( indexOrName )
local printTbl = easyPrint.chipNamePrefix( ccmdScheme )
local ind = tonumber( indexOrName ) or getPlaylistIndex( indexOrName )
curPlaylistInd = ind
wire.ports.PlaylistIndex = curPlaylistInd
if curPlaylistInd == 0 then
curPlaylistSubInd = 1
wire.ports.PlaylistName = ""
table.add( printTbl, {
ccmdScheme:getColor( "Text" ), "The current playlist has been ",
ccmdScheme:getColor( "false" ), "deselected",
ccmdScheme:getColor( "Text" ), ".",
} )
else
local playlist = PLAYLISTS[ind]
local playlistName = playlist.Name
curPlaylistSubInd = getPlaylistSubIndex( curSongInd )
wire.ports.PlaylistName = playlistName
table.add( printTbl, {
ccmdScheme:getColor( "Text" ), "Selected playlist ",
ccmdScheme:getColor( "true" ), playlistName,
ccmdScheme:getColor( "Text" ), ".",
} )
end
print( unpack( printTbl ) )
end
local function setVolume( vol )
curVolume = math.clamp( vol, 0, 1 )
net.start( "LKL_MusicPlayer_SetVolume" )
net.writeFloat( curVolume )
net.send()
end
local function setLoop( state )
loopEnabled = state
net.start( "LKL_MusicPlayer_SetLoop" )
net.writeBool( loopEnabled )
net.send()
end
local function setShuffle( state )
shuffleEnabled = state
end
function musicPlayer.getSongName( songInd )
return getSongName( songInd )
end
function musicPlayer.getSongIndex( songName )
return getSongIndex( songName )
end
function musicPlayer.getPlaylistIndex( playlistName )
return getPlaylistIndex( playlistName )
end
function musicPlayer.getCurPlaylistName()
return getCurPlaylistName()
end
function musicPlayer.isSongValid( indexOrURL )
return isSongValid( indexOrURL )
end
function musicPlayer.isPlaylistValid( indexOrName )
return isPlaylistValid( indexOrName )
end
function musicPlayer.playSong( indexOrNameOrURL )
playSong( indexOrNameOrURL )
end
function musicPlayer.stopSongs()
stopSongs()
end
function musicPlayer.restartSong()
restartSong()
end
function musicPlayer.skipSong()
playSong( getNextSongIndex() )
end
function musicPlayer.selectPlaylist( indexOrName )
selectPlaylist( indexOrName )
end
function musicPlayer.setVolume( vol )
setVolume( vol )
end
function musicPlayer.setLoop( state )
setLoop( state )
end
function musicPlayer.setShuffle( state )
setShuffle( state )
end
local function wireInput( name, value )
if not chipLink:isWired( name ) then return end
if name == "PlaySongIndex" then
if value == 0 then
stopSongs()
end
if not isSongValid( value ) then return end
playSong( value )
elseif name == "PlaySongNameOrURL" then
if value == "" then
stopSongs()
end
local indexOrURL = getSongIndexOrURL( value )
if not isSongValid( indexOrURL ) then return end
playSong( indexOrURL )
elseif name == "SkipSong" then
playSong( getNextSongIndex() )
elseif name == "RestartSong" then
restartSong()
elseif name == "SelectPlaylistIndex" then
if value == 0 then
selectPlaylist( 0 )
end
if not isPlaylistValid( value ) then return end
selectPlaylist( value )
elseif name == "SelectPlaylistName" then
if value == "" then
selectPlaylist( 0 )
end
if deselectWords[value] then
selectPlaylist( 0 )
else
selectPlaylist( value )
end
elseif name == "SetVolume" then
setVolume( value )
elseif name == "SetLoop" then
setLoop( value ~= 0 )
elseif name == "SetShuffle" then
setShuffle( value ~= 0 )
end
end
hook.add( "input", "LKL_MusicPlayer_WireInput", wireInput )
net.receive( "LKL_MusicPlayer_SongEnded", function( _, ply )
if ply ~= owner() then return end
if songsAreStopped then return end
playSong( getNextSongIndex() )
end )
net.receive( "LKL_MusicPlayer_ClientInit", function( _, ply )
if ply ~= owner() then return end
-- Still use a timer in case clients other than the owner need a bit more time.
if musicPlayer.SONG_DEFAULT then
timer.simple( 1, function()
playSong( musicPlayer.SONG_DEFAULT )
end )
end
timer.simple( 1.1, function()
for _, inputName in ipairs( inputNames ) do
wireInput( inputName, wire.ports[inputName] )
end
hook.run( "LKL_MusicPlayer_Initialized" )
end )
end )
do
for i, song in ipairs( SONGS ) do
local name = song.Name
if not name or name == "" then
error( "Song " .. i .. " has no name" )
end
if tonumber( name ) then
error( "Song " .. name .. " has an invalid name" )
end
if string.find( name, "%s" ) then
error( "Song \"" .. name .. "\" has whitespace in its name" )
end
if type( song.URL ) ~= "string" then
error( "Song " .. name .. " has no URL" )
end
name = string.lower( name )
if songLookup[name] then
error( "Duplicate song name: " .. name )
end
songLookup[name] = i
end
for i, playlist in ipairs( PLAYLISTS ) do
local name = playlist.Name
if not name or name == "" then
error( "Playlist " .. i .. " has no name" )
end
if tonumber( name ) then
error( "Playlist " .. name .. " has an invalid name" )
end
if string.find( name, "%s" ) then
error( "Playlist \"" .. name .. "\" has whitespace in its name" )
end
local nameOriginal = name
name = string.lower( name )
if playlistLookup[name] then
error( "Duplicate playlist name: " .. name )
end
if deselectWords[name] then
error( "Playlist name " .. name .. " is a reserved word" )
end
playlistLookup[name] = i
local songNames = playlist.Songs
if type( songNames ) ~= "table" then
error( "Playlist " .. nameOriginal .. " has no songs" )
end
for _, songName in ipairs( songNames ) do
if not songLookup[songName:lower()] then
error( "Playlist " .. nameOriginal .. " contains an undefined song name: " .. songName )
end
end
end
curPlaylistInd = getPlaylistIndex( musicPlayer.PLAYLIST_DEFAULT )
timer.simple( 0, function()
wire.adjustInputs( inputNames, inputTypes )
wire.adjustOutputs( outputNames, outputTypes )
end )
end
if not musicPlayer.USE_CHAT_COMMANDS then return end
ccmdMulti.registerProject( ccmdPrefix, ccmdName, nil )
ccmdMulti.setTargets( ccmdPrefix, owner(), false )
ccmdMulti.createCommand(
ccmdPrefix,
{
"play",
"p",
},
function( _, _, _, _, songNameOrURL )
playSong( songNameOrURL )
end,
function( _, _, _, _, songNameOrURL )
local indexOrURL = getSongIndexOrURL( songNameOrURL )
if not isSongValid( indexOrURL ) then
return "Invalid song name or URL.", 1
end
end,
{
ReqCount = 1,
OptCount = 0,
[1] = {
Name = "songNameOrURL",
Description = "The name of a pre-defined song, or a custom URL.",
},
},
"Plays a song.",
owner(),
false
)
ccmdMulti.createCommand(
ccmdPrefix,
"stop",
function()
stopSongs()
end,
nil,
nil,
"Stops songs from playing.",
owner(),
false
)
ccmdMulti.createCommand(
ccmdPrefix,
"skip",
function()
playSong( getNextSongIndex() )
end,
nil,
nil,
"Skips to the next song.",
owner(),
false
)
ccmdMulti.createCommand(
ccmdPrefix,
{
"restart",
"r",
},
function()
restartSong()
end,
nil,
nil,
"Restarts the current song.",
owner(),
false
)
ccmdMulti.createCommand(
ccmdPrefix,
{
"playlist",
"pl",
},
function( _, _, _, _, playlistName )
if not playlistName or playlistName == "" then
local curPlaylistName = getCurPlaylistName()
if curPlaylistName == "" then
return "No playlist has been selected."
end
return {
ccmdScheme:getColor( "Text" ), "The current playlist is ",
ccmdScheme:getColor( "Highlight" ), curPlaylistName,
ccmdScheme:getColor( "Text" ), ".",
}
end
if deselectWords[playlistName] then
selectPlaylist( 0 )
else
selectPlaylist( playlistName )
end
end,
function( _, _, _, _, playlistName )
if not playlistName or playlistName == "" then return end
if deselectWords[playlistName] then return end
local ind = getPlaylistIndex( playlistName )
if not isPlaylistValid( ind ) then
return "Invalid playlist name.", 1
end
end,
{
ReqCount = 0,
OptCount = 1,
[1] = {
Name = "playlistName",
Description = "The name of playlist, or a deselection keyword.",
},
},
{
"(De)selects a playlist.",
table.add(
{
ccmdScheme:getColor( "Text" ), "These will deselect the playlist: ",
},
easyPrint.simpleList( ccmdScheme, table.getKeys( deselectWords ), ccmdScheme:getColor( "Highlight" ) )
),
"Provide no arguments to show the current playlist.",
},
owner(),
false
)
ccmdMulti.createCommand(
ccmdPrefix,
{
"volume",
"vol",
"v",
},
function( _, _, _, _, volume )
setVolume( tonumber( volume ) )
return {
ccmdScheme:getColor( "Text" ), "Volume set to ",
ccmdScheme:getColor( "Highlight" ), tostring( curVolume ),
ccmdScheme:getColor( "Text" ), ".",
}
end,
function( _, _, _, _, volume )
if not tonumber( volume ) then
return "Expected volume to be a number.", 1
end
end,
{
ReqCount = 1,
OptCount = 0,
[1] = {
Name = "volume",
Description = "The volume to set, from 0 to 1.",
},
},
"Changes the volume of the music player.",
owner(),
false
)
ccmdMulti.createToggleCommand(
ccmdPrefix,
{
"loop",
"l",
},
function( _, newState )
setLoop( newState )
end,
"Song looping",
"song looping",
loopEnabled,
owner(),
false
)
ccmdMulti.createToggleCommand(
ccmdPrefix,
{
"shuffle",
"sh",
},
function( _, newState )
setShuffle( newState )
end,
"Song shuffling",
"song shuffling",
shuffleEnabled,
owner(),
false
)