• I need a little help.
    15 replies, posted
So after many hours of watching Code Blues GMOD Lua tutorials and reading the GMOD Wiki on how to code this, I have made a File Browser that plays music when you select the file! Alls I need help with is making this gui https://files.facepunch.com/forum/upload/113510/6888e57d-dc7c-4c1e-92ad-872f37f68335/Screenshot_24.png open with a Chat command, and to be able to open with the chat command without putting lua_openscript_cl test3.lua in the console! This is the code that makes this work! local frame = vgui.Create( "DFrame" ) frame:SetSize( 750, 500 ) frame:SetSizable( true ) frame:Center() frame:MakePopup() frame:SetTitle( "Plexy's DJ Menu" ) local browser = vgui.Create( "DFileBrowser", frame ) browser:Dock( FILL ) browser:SetPath( "MOD" ) browser:SetBaseFolder( "sound" ) browser:SetOpen( true ) browser:SetCurrentFolder( "persist" ) local DermaButton = vgui.Create( "DButton", frame ) DermaButton:SetText( "Stop Music" )                  DermaButton:SetPos( 30, 450 )                    DermaButton:SetSize( 100, 30 )                   DermaButton.DoClick = function() RunConsoleCommand( "stopsound" ) end function browser:OnSelect( path, pnl )     sound.PlayFile( path, "", function( station ) if ( IsValid( station ) ) then station:Play() end end ) end I am still very new to making things like this, so any help will be greatly helpful and appreciated! so far the files I have are the test3.lua where the code is stored! Then I have a sound folder for all the music that the browser can play! I am having troubles making it open with a chat/console command and run without typng lua_openscript_cl test3.lua first. thankyou all for your help in advance!
concommand.Add
local frame = vgui.Create( "DFrame" ) frame:SetSize( 750, 500 ) frame:SetSizable( true ) frame:Center() frame:MakePopup() frame:SetTitle( "Plexy's DJ Menu" ) local browser = vgui.Create( "DFileBrowser", frame ) browser:Dock( FILL ) browser:SetPath( "MOD" ) browser:SetBaseFolder( "sound" ) browser:SetOpen( true ) browser:SetCurrentFolder( "persist" ) local DermaButton = vgui.Create( "DButton", frame ) DermaButton:SetText( "Stop Music" )                  DermaButton:SetPos( 30, 450 )                    DermaButton:SetSize( 100, 30 )                   DermaButton.DoClick = function() RunConsoleCommand( "stopsound" ) end function browser:OnSelect( path, pnl )     sound.PlayFile( path, "", function( station ) if ( IsValid( station ) ) then station:Play() end end ) end concommand.Add( "openDJ", function( ply, cmd, args )     ply:Kill()     print( "Opening Plexy's DJ Browser!" ) end ) vgui.Register("frame", frame, "DFrame") hook.Add("OnPlayerChat", "checkMessage", function(_, text) if (text == "!openDJ") then vgui.Create("frame") end end) vgui.Create("frame") what would i replace ply:Kill() in the concommand.Add( "openDJ", function( ply, cmd, args )     ply:Kill()     print( "Opening Plexy's DJ Browser!" ) end )
You can't open scripts by lua. Read how functions in Lua works. And wrap your derma to function.
the only thing i see in that is this dofile 'a.lua' <--> dofile ('a.lua') thats the only thing i see in that that even references opening a .lua file! and everything else in that book doesn't help me add a console command to open the gui thats all i need! I just want users to be able to type !openDJ in game chat and bam it pops up!
Chat command or console? Can you decide?
I have the chat command already vgui.Register("frame", frame, "DFrame") hook.Add("OnPlayerChat", "checkMessage", function(_, text)if (text == "!openDJ") then vgui.Create("frame") endend) vgui.Create("frame") the gui doesnt open when i type it and i need help figuring out how to fix that, sorry
You can use local Cmds = {"!openDJ","!DJ","/openDJ","/DJ"} hook.Add("OnPlayerChat", "PlayerChat", function(Ply, ChatText)  for k,v in pairs(Cmds) do  if string.sub(ChatText, 0, #v) == v and Ply == LocalPlayer() then  vgui.Create("frame") end end end)
So the code would look like local frame = vgui.Create( "DFrame" ) frame:SetSize( 750, 500 ) frame:SetSizable( true ) frame:Center() frame:MakePopup() frame:SetTitle( "Plexy's DJ Menu" ) local browser = vgui.Create( "DFileBrowser", frame ) browser:Dock( FILL ) browser:SetPath( "MOD" ) browser:SetBaseFolder( "sound" ) browser:SetOpen( true ) browser:SetCurrentFolder( "persist" ) local DermaButton = vgui.Create( "DButton", frame ) DermaButton:SetText( "Stop Music" )                  DermaButton:SetPos( 30, 450 )                    DermaButton:SetSize( 100, 30 )                   DermaButton.DoClick = function() RunConsoleCommand( "stopsound" ) end function browser:OnSelect( path, pnl )     sound.PlayFile( path, "", function( station ) if ( IsValid( station ) ) then station:Play() end end ) end local Cmds = {"!openDJ","!DJ","/openDJ","/DJ"} hook.Add("OnPlayerChat", "PlayerChat", function(Ply, ChatText)for k,v inpairs(Cmds) doifstring.sub(ChatText, 0, #v) == v and Ply == LocalPlayer() then             vgui.Create("frame") end end end) instead of local frame = vgui.Create( "DFrame" ) frame:SetSize( 750, 500 ) frame:SetSizable( true ) frame:Center() frame:MakePopup() frame:SetTitle( "Plexy's DJ Menu" ) local browser = vgui.Create( "DFileBrowser", frame ) browser:Dock( FILL ) browser:SetPath( "MOD" ) browser:SetBaseFolder( "sound" ) browser:SetOpen( true ) browser:SetCurrentFolder( "persist" ) local DermaButton = vgui.Create( "DButton", frame ) DermaButton:SetText( "Stop Music" ) DermaButton:SetPos( 30, 450 ) DermaButton:SetSize( 100, 30 ) DermaButton.DoClick = function() RunConsoleCommand( "stopsound" ) endfunction browser:OnSelect( path, pnl ) sound.PlayFile( path, "", function( station )if ( IsValid( station ) ) then station:Play() endend ) end vgui.Register("frame", frame, "DFrame") hook.Add("OnPlayerChat", "checkMessage", function(_, text)if (text == "!openDJ") then vgui.Create("frame") endend) vgui.Create("frame") right?
I would recommend you to put the hooks in the server/networking file and send a networking string to the client sided code
So I would take local Cmds = {"!openDJ","!DJ","/openDJ","/DJ"} hook.Add("OnPlayerChat", "PlayerChat", function(Ply, ChatText)for k,v in pairs(Cmds) do if string.sub(ChatText, 0, #v) == v and Ply == LocalPlayer() then vgui.Create("frame") vgui.Create("browser") end end end) and put it into a init.lua right? and then make this local frame = vgui.Create( "DFrame" ) frame:SetSize( 750, 500 ) frame:SetSizable( true ) frame:Center() frame:MakePopup() frame:SetTitle( "Plexy's DJ Menu" ) local browser = vgui.Create( "DFileBrowser", frame ) browser:Dock( FILL ) browser:SetPath( "MOD" ) browser:SetBaseFolder( "sound" ) browser:SetOpen( true ) browser:SetCurrentFolder( "persist" ) local DermaButton = vgui.Create( "DButton", frame ) DermaButton:SetText( "Stop Music" )                  DermaButton:SetPos( 30, 450 )                    DermaButton:SetSize( 100, 30 )                   DermaButton.DoClick = function() RunConsoleCommand( "stopsound" ) end function browser:OnSelect( path, pnl )     sound.PlayFile( path, "", function( station ) if ( IsValid( station ) ) then station:Play() end end ) end into a cl_init.lua but add the Add AddCSLuaFile( "cl_init.lua" ) into the init.lua and AddCSLuaFile( "init.lua" ) to my cl_init.lua and i would need to make a shared.lua file correct?
Instead of creating the frame on server-sided code you should networking (net.Start, etc. on server-side and net.Receive, etc. on the client-sided code) and create the frame and so on, on the client-sided code.
Thankyou so much! I will do that asap!
so after watching the tutorial I recodded it like he did! But when I got to in game first test like he did I get this error [ERROR] addons/musical_gui/lua/autorun/client/cl_musicalgu.lua:45: 'end' expected (to close 'function' at line 4) near '<eof>'   1. unknown - addons/musical_gui/lua/autorun/client/cl_musicalgu.lua:0 my code looks exactly like his on the hook.add local isOpen = false function OpenChat() local frame = vgui.Create( "DFrame" ) frame:SetSize( 750, 500 ) frame:SetSizable( true ) frame:Center() frame:MakePopup() frame:SetTitle( "Plexy's DJ Menu" ) frame.OnClose = function(s) isOpen = false s:Remove() end local browser = vgui.Create( "DFileBrowser", frame ) browser:Dock( FILL ) browser:SetPath( "MOD" ) browser:SetBaseFolder( "sound" ) browser:SetOpen( true ) browser:SetCurrentFolder( "persist" ) local DermaButton = vgui.Create( "DButton", frame ) DermaButton:SetText( "Stop Music" )                  DermaButton:SetPos( 30, 450 )                    DermaButton:SetSize( 100, 30 )                   DermaButton.DoClick = function() RunConsoleCommand( "stopsound" ) end function browser:OnSelect( path, pnl )      sound.PlayFile( path, "", function( station ) if ( IsValid( station ) ) then station:Play() end end ) end hook.Add("OnPlayerChat" , "OpenDJMenu" , function(ply,text) if ply == LocalPlayer() then if string.lower(text) == "!dj" then OpenChat() end end end)
well, as the error says it, you missed an end there. check out your     function browser:OnSelect( path, pnl )          sound.PlayFile( path, "", function( station )         if ( IsValid( station ) ) then station:Play() end     end ) function. you miss an end for the function itself because the end you put there is sound.PlayFile function's end. so how it should look like is this;     function browser:OnSelect(path, pnl)         sound.PlayFile(path, "", function(station)             if (IsValid(station)) then                 station:Play()             end         end)     end
THANK YOU THANK YOU THANKYOU!!!!!!! finally works after weeks of trying different things i could find! Your the best!
Sorry, you need to Log In to post a reply to this thread.