After Hours and hours of googling, scanning the Gmod wiki, and watching tons of youtube videos I have made a GUI! It plays music when you click a DButton but there are still major problems I need to sort out with it! I need to figure out how to not allow the songs to overlap, so if you press another button it stops the past song and plays a new one! I also need help figuring out how to make it play in a radius and not just locally, I want to make sure if servers use this that all players within a certain radius are able to hear it!
local frame = vgui.Create( "DFrame" )
frame:SetSize( 300, 250 )
frame:SetMinHeight( 200, 200 )
frame:SetMinWidth(200, 200 )
frame:SetSizable(true)
frame:SetDraggable( true )
frame:SetTitle( "Musical DJ Menu" )
frame:Center ()
frame:SetVisible( true )
frame:MakePopup()
frame:ShowCloseButton( true )
frame:SetDeleteOnClose( true )
local DermaButton = vgui.Create( "DButton", frame )
DermaButton:SetText( "Tseries Diss Track" )
DermaButton:SetPos( 25, 50 )
DermaButton:SetSize( 250, 30 )
DermaButton.DoClick = function()
EmitSound( Sound( "weapons/songs/tseries.mp3" ), Entity( 1 ):GetPos(), 1, CHAN_AUTO, 1, 75, 0, 100 )
end
here's what the GUI looks like in game!
https://files.facepunch.com/forum/upload/113510/ee3ff53a-f0b0-4ba3-acd7-4f536e249582/Screenshot_12.png
This is a very crude version of what I want to make! I basically am trying to make a DJ addon that has a ton of preloaded songs, I want it to also function when a player type a command to open this gui! Thanks for any help yall give me in advanced!
hey good job making this.
just run the stopsound command then run the EmitSound function after 1 ms (0.1 seconds)
DermaButton.DoClick = function()
RunConsoleCommand("stopsound") -- https://wiki.garrysmod.com/page/Global/RunConsoleCommand
timer.Simple(0.1, function() -- https://wiki.garrysmod.com/page/timer/Simple
EmitSound( Sound("weapons/songs/tseries.mp3"), LocalPlayer():GetPos(), 1, CHAN_AUTO, 1, 75, 0, 100 )
end)
end
Thank you! I will tots do that, but one last question. for very sound i want it to play I have to add a new
I updated my post with better code since people didn't like it (it was ghetto) and no, you do self:createSongButton("Your song name here", "SongFile.mp3")
like you see on line 15 and 16
AH ok thank you
Yours says "weapons/songs/tseries.mp3" and you put only put "tseries.mp3", if you want it to just be "tseries.mp3" put the mp3 file into \steamapps\common\GarrysMod\garrysmod\sound and restart gmod
10-4 thank you
no problem, good luck
Now the gui wont open! I have the GUI lua file in this path C:\Program Files (x86)\Steam\steamapps\common\GarrysMod\garrysmod\addons\gui_version\lua
Heres the code in case i screwed anyhting up but alls i changed ways the file path to the song!
local DJMenu = { -- https://www.youtube.com/watch?v=9o49wKTHYZ4 I recommend this tutorial series for derma's and for everything glua
Init = function(self)
self.CurrentSound = CreateSound( LocalPlayer(), "physics/body/body_medium_break2.wav") -- https://wiki.garrysmod.com/page/Global/CreateSound
self.CurrentSound:SetSoundLevel( 100 )
self:SetTitle( "Musical DJ Menu" )
self:MakePopup()
self:SetSize( 300, 250 )
self:SetMinHeight( 200, 200 )
self:SetMinWidth(200, 200 )
self:Center()
self:SetSizable(true)
self:SetDraggable( true )
-- Create song button
self:createSongButton("song1", "weapons/songs/tseries.mp3")
self:createSongButton("song2", "test2.mp3")
end,
createSongButton = function(self, buttonText, songPath)
local songButton = vgui.Create("DButton", self)
songButton:SetText(buttonText)
songButton:SetSize(250, 30)
songButton:Dock(TOP) -- https://wiki.garrysmod.com/page/Panel/Dock
songButton:DockMargin(0,0,0,5) -- https://wiki.garrysmod.com/page/Panel/DockMargin
songButton.DoClick = function()
self.CurrentSound:Stop()
self.CurrentSound = CreateSound( LocalPlayer(), songPath)
self.CurrentSound:Play()
end
end
}
vgui.Register("DJMenu", DJMenu, "DFrame") -- https://wiki.garrysmod.com/page/vgui/Register
hook.Add("OnPlayerChat", "checkMessage", function(_, text) -- https://wiki.garrysmod.com/page/GM/OnPlayerChat
if (text == "!openDJ") then
vgui.Create("DJMenu")
end
end)
vgui.Create("DJMenu")
After Scanning around and getting a little outside help I have managed to fix the GUI not showing but now have a new problem!
The GUI Opens and works
https://files.facepunch.com/forum/upload/113510/b26eb9a6-9043-4817-a1c3-7780f45400d9/Screenshot_18.png
This appears in my console when I try to play a song off the DJ radio!
https://files.facepunch.com/forum/upload/113510/fdc89d9c-aded-433a-8992-fcbd75c2c7ee/Screenshot_19.png
I have the songs in the correct path as show in this screenshot
https://files.facepunch.com/forum/upload/113510/eb2bdb86-9ce3-4230-a45c-a4d0b39ef7b7/Screenshot_20.png
Here is the cl_init.lua code
include('shared.lua')
function ENT:Draw()
self:DrawModel()
end
net.Receive("OpenDJMenu", function()
local selfEnt = Entity(net.ReadUInt(16))
local activeSong = net.ReadUInt(4)
local SongNames = {
[0] = "Nothing",
[1] = "guitar_1",
[2] = "guitar_2",
[3] = "guitar_3",
[4] = "guitar_4",
[5] = "guitar_5",
[6] = "guitar_6",
[7] = "guitar_7",
[8] = "guitar_8",
[9] = "guitar_9",
[10] = "guitar_10",
[11] = "guitar_11",
[12] = "guitar_12",
[13] = "guitar_13",
[14] = "guitar_14",
[15] = "guitar_15",
[16] = "guitar_16"
}
local Tuner = vgui.Create( "DFrame" )
Tuner:SetPos( 5, 5 )
Tuner:SetSize( 300, 300 )
Tuner:SetTitle( "Plexy's DJ Radio " .. SongNames[math.Round(activeSong)] )
Tuner:SetVisible( true )
Tuner:SetDraggable( false )
Tuner:ShowCloseButton( true )
Tuner:MakePopup()
Tuner:Center()
Tuner.Paint = function( self, w, h )
draw.RoundedBox( 0, 0, 0, w, h, Color( 111, 87, 63, 255 ) )
end
local SongSlider = vgui.Create( "DNumSlider", Tuner )
SongSlider:SetPos(-50,28)
--SongSlider:Dock(TOP)
SongSlider:SetSize( 300, 150 )
SongSlider:SetMin(0)
SongSlider:SetMax(16)
SongSlider:SetDecimals(0)
SongSlider:SetValue(activeSong)
SongSlider.OnValueChanged = function(pan, val)
Tuner:SetTitle( "▶ " .. SongNames[math.Round(val)] )
net.Start("PlayDJSong")
net.WriteEntity(selfEnt)
net.WriteUInt( math.Round(val), 4 )
net.SendToServer()
end
end)
Here is the init.lua code
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include('shared.lua')
ENT.Songs = {
[0] = "ambient/_period.wav",
[1] = "sound/music/guitar_1.wav",
[2] = "sound/music/guitar_2.wav",
[3] = "sound/music/guitar_3.wav",
[4] = "sound/music/guitar_4.wav",
[5] = "sound/music/guitar_5.wav",
[6] = "sound/music/guitar_6.wav",
[7] = "sound/music/guitar_7.wav",
[8] = "sound/music/guitar_8.wav",
[9] = "sound/music/guitar_9.wav",
[10] = "sound/music/guitar_10.wav",
[11] = "sound/music/guitar_11.wav",
[12] = "sound/music/guitar_12.wav",
[13] = "sound/music/guitar_13.wav",
[14] = "sound/music/guitar_14.wav",
[15] = "sound/music/guitar_15.wav",
[16] = "sound/music/guitar_16.wav"
}
ENT.ActiveSong = 0
function ENT:Initialize()
util.AddNetworkString("OpenDJMenu")
util.AddNetworkString("PlayDJSong")
self:SetModel( "models/props_lab/citizenradio.mdl" )
self:PhysicsInit( SOLID_VPHYSICS )
self:SetMoveType( MOVETYPE_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )
local phys = self:GetPhysicsObject()
if (phys:IsValid()) then
phys:Wake()
end
self:SetUseType(SIMPLE_USE)
end
function ENT:Use(activator, caller)
net.Start("OpenDJMenu")
net.WriteUInt(self:EntIndex(), 16)
net.WriteUInt(self.ActiveSong, 4)
net.Send(caller)
end
net.Receive("PlayDJSong", function()
local selfEnt = net.ReadEntity()
local songIndex = net.ReadUInt(4)
selfEnt:EmitSound( selfEnt.Songs[math.Round(songIndex)], 75, 100, 1, CHAN_ITEM )
selfEnt.ActiveSong = math.Round(songIndex)
end)
function ENT:OnRemove()
self:EmitSound("ambient/_period.wav", 75, 100, 1, CHAN_ITEM)
end
function ENT:OnTakeDamage()
local rand = math.random(1,16)
self:EmitSound("ambient/energy/spark" .. math.random(1,6) .. ".wav")
self:EmitSound( self.Songs[rand], 75, 100, 1, CHAN_ITEM )
self.ActiveSong = rand
end
Any and all help would be very helpful on a fix to this issue!
First of all, using UInt(4) you can't have a [16], 4 bits covers the range 0-15.
Second, you don't need the "sound" part, just the "music/guitar_n.wav" is fine
so are you saying change
local selfEnt = Entity(net.ReadUInt(16))
to
local selfEnt = Entity(net.ReadUInt(4))
?
There is no reason to use UInt to network the entities ID, just use net.WriteEntity and net.ReadEntity, and no, I mean't the songIndex variable.
The argument you put into a UInt is the bit size of the message, the range can be calculated as 0-(2^n) where n is the bit size, so
1 = 0-1
2 = 0-3
3 = 0-7
4 = 0-15
5 = 0-31
etc...
So in the cl_init.lua change
local selfEnt = Entity(net.ReadUInt(16))
local activeSong = net.ReadUInt(4)
to
local selfEnt = Entity(net.ReadEntity(5))
local activeSong = net.ReadEntity(5)
and in the init.lua do i change
local selfEnt = net.ReadEntity()
local songIndex = net.ReadUInt(4)
to
local selfEnt = net.ReadEntity()
local songIndex = net.ReadEntity(5)
Tiy don't need Entity(net.ReadEntity(5)), you can just write net.ReadEntity().
Also set activeSong to net.ReadUInt(5), not ReadEntity().
I no longer get the missing file error now i am only receiving this
https://files.facepunch.com/forum/upload/113510/e425aef3-f8d8-4077-95ec-5b247c9fcac7/Screenshot_22.png
Which is saying somethings wrong with this line of code!
selfEnt:EmitSound( selfEnt.Songs[math.Round(songIndex)], 75, 100, 1, CHAN_ITEM )
here is the whole init.lua in case something else is causing this!
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include('shared.lua')
ENT.Songs = {
[0] = "ambient/_period.wav",
[1] = "music/guitar_1.wav",
[2] = "music/guitar_2.wav",
[3] = "music/guitar_3.wav",
[4] = "music/guitar_4.wav",
[5] = "music/guitar_5.wav",
[6] = "music/guitar_6.wav",
[7] = "music/guitar_7.wav",
[8] = "music/guitar_8.wav",
[9] = "music/guitar_9.wav",
[10] = "music/guitar_10.wav",
[11] = "music/guitar_11.wav",
[12] = "music/guitar_12.wav",
[13] = "music/guitar_13.wav",
[14] = "music/guitar_14.wav",
[15] = "music/guitar_15.wav",
[16] = "music/guitar_16.wav"
}
ENT.ActiveSong = 0
function ENT:Initialize()
util.AddNetworkString("OpenDJMenu")
util.AddNetworkString("PlayDJSong")
self:SetModel( "models/props_lab/citizenradio.mdl" )
self:PhysicsInit( SOLID_VPHYSICS )
self:SetMoveType( MOVETYPE_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )
local phys = self:GetPhysicsObject()
if (phys:IsValid()) then
phys:Wake()
end
self:SetUseType(SIMPLE_USE)
end
function ENT:Use(activator, caller)
net.Start("OpenDJMenu")
net.WriteUInt(self:EntIndex(), 16)
net.WriteUInt(self.ActiveSong, 5)
net.Send(caller)
end
net.Receive("PlayDJSong", function()
local selfEnt = net.ReadEntity()
local songIndex = net.ReadUInt(5)
selfEnt:EmitSound( selfEnt.Songs[math.Round(songIndex)], 75, 100, 1, CHAN_ITEM )
selfEnt.ActiveSong = math.Round(songIndex)
end)
function ENT:OnRemove()
self:EmitSound("ambient/_period.wav", 75, 100, 1, CHAN_ITEM)
end
function ENT:OnTakeDamage()
local rand = math.random(1,16)
self:EmitSound("ambient/energy/spark" .. math.random(1,6) .. ".wav")
self:EmitSound( self.Songs[rand], 75, 100, 1, CHAN_ITEM )
self.ActiveSong = rand
end
heres the cl_init. also for the same reason!
include('shared.lua')
function ENT:Draw()
self:DrawModel()
end
net.Receive("OpenDJMenu", function()
local selfEnt = net.ReadEntity()
local activeSong = net.ReadUInt(5)
local SongNames = {
[0] = "Nothing",
[1] = "guitar_1",
[2] = "guitar_2",
[3] = "guitar_3",
[4] = "guitar_4",
[5] = "guitar_5",
[6] = "guitar_6",
[7] = "guitar_7",
[8] = "guitar_8",
[9] = "guitar_9",
[10] = "guitar_10",
[11] = "guitar_11",
[12] = "guitar_12",
[13] = "guitar_13",
[14] = "guitar_14",
[15] = "guitar_15",
[16] = "guitar_16"
}
local Tuner = vgui.Create( "DFrame" )
Tuner:SetPos( 5, 5 )
Tuner:SetSize( 300, 300 )
Tuner:SetTitle( "Plexy's DJ Radio " .. SongNames[math.Round(activeSong)] )
Tuner:SetVisible( true )
Tuner:SetDraggable( false )
Tuner:ShowCloseButton( true )
Tuner:MakePopup()
Tuner:Center()
Tuner.Paint = function( self, w, h )
draw.RoundedBox( 0, 0, 0, w, h, Color( 111, 87, 63, 255 ) )
end
local SongSlider = vgui.Create( "DNumSlider", Tuner )
SongSlider:SetPos(-50,28)
--SongSlider:Dock(TOP)
SongSlider:SetSize( 300, 150 )
SongSlider:SetMin(0)
SongSlider:SetMax(16)
SongSlider:SetDecimals(0)
SongSlider:SetValue(activeSong)
SongSlider.OnValueChanged = function(pan, val)
Tuner:SetTitle( "▶ " .. SongNames[math.Round(val)] )
net.Start("PlayDJSong")
net.WriteEntity(selfEnt)
net.WriteUInt( math.Round(val), 4 )
net.SendToServer()
end
end)
In init.lua, don't do net.WriteUInt(self:GetIndex(), 16), just do net.WriteEntity(self)
Are you talking about
net.WriteUInt(self:EntIndex(), 16)
because I dont see a
net.WriteUInt(self:GetIndex(), 16)
any where?
Yeh, I meant EntIndex(), was typo
well i did that and i still receive this error!
[ERROR] addons/gui_radio2/lua/entities/plexys_dj_radio/init.lua:55: bad argument #1 to 'EmitSound' (string expected, got nil)
1. EmitSound - [C]:-1
2. func - addons/gui_radio2/lua/entities/plexys_dj_radio/init.lua:55
3. unknown - lua/includes/extensions/net.lua:32
make the net.WriteUInt have the same number of bits as the net.ReadUInt in "PlayDJSong"
Thank you! That fixed the error but now im having the missing file issue again now!
https://files.facepunch.com/forum/upload/113510/0062ef12-5b8b-4d0b-bf86-89d7108a6dcd/Screenshot_24.png
how are you sending the files to the client? (file.add, workshop, fastdl ??)
The .wav files are included in the files for the addon!
https://files.facepunch.com/forum/upload/113510/5a9836a1-f998-4bbb-aa29-0f6d7a724e55/Screenshot_26.png
https://files.facepunch.com/forum/upload/113510/037fd6ea-b47c-400d-90f5-747ad4e857e4/Screenshot_27.png
sorry i meant resource.AddFile in my earlier post. but either way, how are you getting clients to get the addon itself, because if you're not using the workshop or fastdl then you need to do resource.AddFile
Once everything is in working order I uplaod it to the workshop, so I would do resource.AddFile do I need to put the path or just resource.AddFile before all the code? And do I put it in the cl_ init or just the init.lua?
like you've been doing with playing it; resource.AddFile( "music/guitar_1.wav" ) ect.. but id do it through the workshop from the start. as edited in prev post i dont know how single player works if your using that to make this addon, there could be something im missing in the code youve sent..
basically im suggesting you have some way for the 'server' to send the files or tell the client where to get them because i dont know (/cant see) what else would cause it to show up with that error (wouldnt be surprised if trying this doesnt fix it).
That did not fix the issue i will try and upload the addon to my localy hosted server (dedicated) and se if it works serverside) Ill update this post with the results
Sorry, you need to Log In to post a reply to this thread.