Hi guys, I wanted to run an MP3 player for in-game(So people can hear through the whole server & play) but the issue is the only one I saw was on garrysmod.org (But yet is broken). The last time I attempted to fix the LUA coding on this, I was at most capable of getting the "Play" and "Stop" buttons to show but other than that, the only problem that lies in my way is the MP3 files being found and showing.. All help would be appreciated but here is the code ->
[CODE]function Playermenu()
DermaPanel1 = vgui.Create( "DFrame" )
DermaPanel1:SetPos( 50,25 )
DermaPanel1:SetSize( 300, 450 )
DermaPanel1:SetTitle( "GMOD MP3 Player" )
DermaPanel1:SetVisible( true )
DermaPanel1:SetDraggable( true )
DermaPanel1:ShowCloseButton( true )
DermaPanel1:MakePopup()
local DermaListView = vgui.Create("DListView")
DermaListView:SetParent(DermaPanel1)
DermaListView:SetPos(12.5, 37.5)
DermaListView:SetSize(275, 362.5)
DermaListView:SetMultiSelect(false)
DermaListView:AddColumn("Name") // Add column
local list = file.Find("../sound/songs/*.mp3")
for k,v in pairs(list) do
DermaListView:AddLine(v)
end
local name
function DermaListView:OnRowSelected( LineID, Line )
name = Line:GetColumnText( 1 )
end
local DermaButton = vgui.Create( "DButton", DermaPanel1 )
DermaButton:SetText( "Play" )
DermaButton:SetPos( 12.5, 412.5 )
DermaButton:SetSize( 100, 25 )
DermaButton.DoClick = function()
surface.PlaySound( "ui/buttonclick.wav" )
RunConsoleCommand( "play", "songs/"..name )
end
local DermaButton = vgui.Create( "DButton", DermaPanel1 )
DermaButton:SetText( "Stop" )
DermaButton:SetPos( 187.5, 412.5 )
DermaButton:SetSize( 100, 25 )
DermaButton.DoClick = function()
surface.PlaySound( "ui/buttonclick.wav" )
RunConsoleCommand( "stopsounds" )
end
end
function Hidemenu()
if DermaPanel1:IsVisible() == true then
DermaPanel1:SetVisible(false)
end
end
concommand.Add("mp3", Playermenu)
concommand.Add("+mp3", Playermenu)
concommand.Add("-mp3", Hidemenu)[/CODE]
Before asking "Isn't this already released"? Yes
Before asking "Why do you want this to work"?
Because I personally myself like music in deathrun as it makes it more fun and motivative instead of boring.
Thanks :D!
I cant see what's wrong, but really I would recomend you use sound.PlayURL rather than making players wait ages to download all your music.
The problem is that the file.Read LUA is not working. So each time if I open the menu up, the songs don't show or give an error on it. Basically giving a string problem to the console.
Giving it a shot and I'll post back if all fails.
[editline]15th October 2014[/editline]
attempt to concatenate upvalue 'name' (a nil value)
RunConsoleCommand( "play", "songs/"..name )<- That's the error line
1. DoClick - lua/autorun/client/mp3_player.lua:35
[QUOTE]
local DermaButton = vgui.Create( "DButton", DermaPanel1 )
DermaButton:SetText( "Play" )
DermaButton:SetPos( 12.5, 412.5 )
DermaButton:SetSize( 100, 25 )
DermaButton.DoClick = function()
surface.PlaySound( "ui/buttonclick.wav" )
RunConsoleCommand( "play", "songs/"..name )
end
local DermaButton = vgui.Create( "DButton", DermaPanel1 )
DermaButton:SetText( "Stop" )
DermaButton:SetPos( 187.5, 412.5 )
DermaButton:SetSize( 100, 25 )
DermaButton.DoClick = function()
surface.PlaySound( "ui/buttonclick.wav" )
RunConsoleCommand( "stopsounds" )[/QUOTE]
[editline]15th October 2014[/editline]
Also songs still don't show, is it because they are mp3?
You aren't checking anywhere if name is actually defined.
[Lua]
if not name == nil then
RunConsoleCommand( "play", "songs/"..name )
end
[/lua]
[editline]15th October 2014[/editline]
Thinking about it, try calling GetValue instead of GetColumnText on Line:GetColumnText( 1 )
Okay, so I am going to attempt to play around with the code but I did however(Hopefully) find an alternative way, so if I figure it out, I will release it to the facepunch users and give credits to the original creator.
Okay well I found something that may or may not work: [url]https://code.google.com/p/egad/source/browse/trunk/+egad/lua/?r=9#lua%253Fstate%253Dclosed[/url] Once I try it out, I'm laughing my butt out since all I want is people to be able to play the music server side but of course coderhire can only do that and nobody can do it for free.
Here is an example I wrote for someone on converting Youtube videos to MP3 ( with helper-site provided by helpee ), grabbing the information about the generated mp3, then playing the mp3 using sound.PlayURL: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/sound/sound_playurl_test.lua.html[/url] -- but, sound.PlayURL is clientside:
[url]http://wiki.garrysmod.com/page/sound/PlayURL[/url]
You'd need to network the start command ( you can even network a table of data such as time_started, etc, so players that join can grab the same sound, and skip ahead to where everyone else is in the track to remain completely synced )
Sorry, you need to Log In to post a reply to this thread.