Hello. I was adding music to my fast download to get it to play at the end of every round. The downloads work fine but you can not hear the music play.
Heres my Code.
[CODE]--///////////////////////////////////////// ----FEATURE LIST---- ///////////////////////////////////////////--
--//// ////--
--//// No need to manually resource.AddFile ////--
--//// ////--
--//// Three tables to add the different sounds to the different type of wins. ////--
--//// ////--
--//// No need to add "sound/" in the tables, if you do, you'll actually be screwing up the resource.addfile ////--
--//// ////--
--//// Sounds are randomly chosen inside the table matching the proper win method ////--
--//// ////--
--//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////--
--///////////////////////////////////////// ----WARNINGS AND TIPS---- ///////////////////////////////////////////--
--//// ////--
--//// Remember that you can only use "/" and not "\" ////--
--//// ////--
--//// Remember to keep a table actually not fully empty to avoid code breaking. You can even just leave a wrong path in it ////--
--//// ////--
--//// For a guide on how to add new sounds, check the workshop page ////--
--//// ////--
--//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////--
-- Sounds played when the innocent win
local InnocentWinSounds = {
"harlem.wav",
"friday.wav",
"whiteguy.wav",
}
-- Sounds played when the traitors win
local TraitorWinSounds = {
"Death.wav",
"dance.wav",
"hell.wav",
}
-- Sounds played when time is up
local OutOfTimeSounds = {
"derp.wav",
}
for k, v in pairs (InnocentWinSounds) do
resource.AddFile("sound/"..v)
util.PrecacheSound("sound/"..v)
end
for k, v in pairs (TraitorWinSounds) do
resource.AddFile("sound/"..v)
util.PrecacheSound("sound/"..v)
end
for k, v in pairs (OutOfTimeSounds) do
resource.AddFile("sound/"..v)
util.PrecacheSound("sound/"..v)
end
local function PlaySoundClip(win)
if win == WIN_INNOCENT then
BroadcastLua('surface.PlaySound("'..InnocentWinSounds[math.random(1, #InnocentWinSounds)]..'")')
elseif win == WIN_TRAITOR then
BroadcastLua('surface.PlaySound("'..TraitorWinSounds[math.random(1, #TraitorWinSounds)]..'")')
elseif win == WIN_TIMELIMIT then
BroadcastLua('surface.PlaySound("'..OutOfTimeSounds[math.random(1, #OutOfTimeSounds)]..'")')
end
end
hook.Add("TTTEndRound", "SoundClipEndRound", PlaySoundClip)[/CODE]
This looks like exactly like the one i'm using, theres no reason it shouldn't work, have you changed anything since you downloaded it?
I'm pretty sure there's an option in the multiplayer settings to download custom files or something along those lines, I'm pretty sure that box has to be checked. Hope that helps :)
Edit: it could have also been something like play custom sounds.
-snip-
[editline]6/16/13 @11:50 PST[/editline]
Oh it's serverside.
well you could try adding random little print("DEBUG 1")'s everywhere to see how far the code gets. I would check the console to see whether the sound file is TRYING to play or not.
Here is a much better way of doing this:
[lua]
if SERVER then
AddCSLuaFile()
util.AddNetworkString("TTTERMusic")
end
hook.Add("Initialize", "CheckGamemodesEnums", function()
if !WIN_NONE then return end
if SERVER then
game.ConsoleCommand("ttt_cl_soundcues 0\n")
end
local TTTERMusic = {}
function AddEndRoundMusic(wintype, path)
local shouldIns = TTTERMusic[wintype]
if shouldIns then
table.insert(TTTERMusic[wintype], Sound(path))
else
TTTERMusic[wintype] = {Sound(path)}
end
if SERVER then
resource.AddFile("sound/"..path)
end
end
-- WIN_NONE = 1
-- WIN_TRAITOR = 2
-- WIN_INNOCENT = 3
-- WIN_TIMELIMIT = 4
--These are examples of how to add your sounds to the win type:
AddEndRoundMusic(WIN_INNOCENT, "garrysmod/save_load1.wav")
AddEndRoundMusic(WIN_TRAITOR, "garrysmod/save_load2.wav")
AddEndRoundMusic(WIN_TIMELIMIT, "garrysmod/save_load3.wav")
AddEndRoundMusic(WIN_NONE, "garrysmod/balloon_pop_cute.wav")
if SERVER then
hook.Add("TTTEndRound", "TTTEndRoundMusicc", function(wintype)
net.Start("TTTERMusic")
net.WriteInt(wintype, 16)
net.Broadcast()
end)
else
net.Receive("TTTERMusic", function(len)
local wintype = net.ReadInt(16)
local soundPlay = TTTERMusic[wintype]
if soundPlay then
surface.PlaySound(table.Random(soundPlay))
end
end)
end
end)
[/lua]
This goes into a shared file or into "lua/autorun".
The point i was trying to make was that if the script he posted is the one thats available for download on [url]http://www.garrysmod.org/downloads/[/url] then theres nothing wrong with it, and if hes setup the sounds to download then it's probably a client side thing, when i set this up on my server i wasn't hearing sounds untill i changed something in my own gmod settings, so giving him differnt scripts that all do the same thing gets up nowhere. Although it may be that he doesn't have the file in the correct place.("lua/autorun" is correct.)
[QUOTE=Skillz;41069093]The point i was trying to make was that if the script he posted is the one thats available for download on [url]http://www.garrysmod.org/downloads/[/url] then theres nothing wrong with it, and if hes setup the sounds to download then it's probably a client side thing, when i set this up on my server i wasn't hearing sounds untill i changed something in my own gmod settings, so giving him differnt scripts that all do the same thing gets up nowhere. Although it may be that he doesn't have the file in the correct place.("lua/autorun" is correct.)[/QUOTE]
It doesn't matter, the script I posted is better and more efficient than what he posted, so use it.
Still Doesn't Work.
[QUOTE=xXGhostieXx;41074499]Still Doesn't Work.[/QUOTE]
Yes it does.
Since I'm the author of that script, I guess it's my job to help you getting it to work.
Hit me up on steam [url]http://steamcommunity.com/id/_kurochi/[/url]
For now, here's a code that should work better (uses client for playing sounds, while it uses shared for resource.addfile and util.precachesound)
You have to put this into lua/autorun (Remove the old file)
[lua]--///////////////////////////////////////// ----FEATURE LIST---- ///////////////////////////////////////////--
--//// ////--
--//// No need to manually resource.AddFile ////--
--//// ////--
--//// Three tables to add the different sounds to the different type of wins. ////--
--//// ////--
--//// No need to add "sound/" in the tables, if you do, you'll actually be screwing up the resource.addfile ////--
--//// ////--
--//// Sounds are randomly chosen inside the table matching the proper win method ////--
--//// ////--
--//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////--
--///////////////////////////////////////// ----WARNINGS AND TIPS---- ///////////////////////////////////////////--
--//// ////--
--//// Remember that you can only use "/" and not "\" ////--
--//// ////--
--//// Remember to keep a table actually not fully empty to avoid code breaking. You can even just leave a wrong path in it ////--
--//// ////--
--//// For a guide on how to add new sounds, check the workshop page ////--
--//// ////--
--//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////--
-- Sounds played when the innocent win
local InnocentWinSounds = {
"harlem.wav",
"friday.wav",
"whiteguy.wav",
}
-- Sounds played when the traitors win
local TraitorWinSounds = {
"Death.wav",
"dance.wav",
"hell.wav",
}
-- Sounds played when time is up
local OutOfTimeSounds = {
"derp.wav",
}
for k, v in pairs (InnocentWinSounds) do
resource.AddFile("sound/"..v)
util.PrecacheSound("sound/"..v)
end
for k, v in pairs (TraitorWinSounds) do
resource.AddFile("sound/"..v)
util.PrecacheSound("sound/"..v)
end
for k, v in pairs (OutOfTimeSounds) do
resource.AddFile("sound/"..v)
util.PrecacheSound("sound/"..v)
end
if CLIENT then
local function PlaySoundClip(win)
if win == WIN_INNOCENT then
surface.PlaySound(table.Random(InnocentWinSounds))
elseif win == WIN_TRAITOR then
surface.PlaySound(table.Random(TraitorWinSounds))
elseif win == WIN_TIMELIMIT then
surface.PlaySound(table.Random(OutOfTimeSounds))
end
end
hook.Add("TTTEndRound", "SoundClipEndRound", PlaySoundClip)
end[/lua]
[QUOTE=~Razor~;41074868]-Don't use this-[/QUOTE]
Your post shows that you don't know how TTT works at all.
You're trying to call a hook clientside when it's serverside.
You want proof? Go ahead and run this in a shared file:
[lua]
hook.Add("TTTEndRound", "I am SERVERSIDE", function(wintype)
print("I AM SERVERSIDE")
end)
[/lua]
As for the OP, it's obvious you're installing it wrong because I know my script works.
Save it as a ".lua" extension file inside "lua/autorun/" and it will be good to go.
Well I tried both of your scripts and neither played music.
[QUOTE=brandonj4;41075115]AGRRAGGGAAGHHHA TTTEndRound IS SERVERSIDE ARGRGAHRAGRA[/QUOTE]
[IMG]http://gyazo.com/5787d4a4a6d3b632d02dc835f8ba2dfd.png[/IMG]
Which just made me realize I have to network it somehow. (Although it might happen the hook is ran before the networking effectively happens. So I sticked with just sending a message to the client)
Anyway I believe the dude added me on steam. I'll help him over there if that's the case.
[lua]-- Sounds played when the innocent win
local InnocentWinSounds = {
"harlem.wav",
"friday.wav",
"whiteguy.wav",
}
-- Sounds played when the traitors win
local TraitorWinSounds = {
"Death.wav",
"dance.wav",
"hell.wav",
}
-- Sounds played when time is up
local OutOfTimeSounds = {
"derp.wav",
}
for k, v in pairs (InnocentWinSounds) do
resource.AddFile("sound/"..v)
util.PrecacheSound("sound/"..v)
end
for k, v in pairs (TraitorWinSounds) do
resource.AddFile("sound/"..v)
util.PrecacheSound("sound/"..v)
end
for k, v in pairs (OutOfTimeSounds) do
resource.AddFile("sound/"..v)
util.PrecacheSound("sound/"..v)
end
if SERVER then
util.AddNetworkString("TTTWin")
hook.Add("TTTEndRound", "SoundClipEndRound", function(winType)
local winSound
if winType == WIN_INNOCENT then
winSound = table.Random(InnocentWinSounds)
elseif winType == WIN_TRAITOR then
winSound = table.Random(TraitorWinSounds)
elseif winType == WIN_TIMELIMIT then
winSound = table.Random(OutOfTimeSounds)
end
net.Start("TTTWin")
net.WriteString(winSound)
net.Broadcast()
end)
end
if CLIENT then
net.Receive("TTTWin", function()
surface.PlaySound(net.ReadString())
end)
end[/lua]
Who gives a fuck about efficiency, it's just going to play music once every time a round ends. TTT rounds don't last one tenth of a second as far as I know. BroadcastLua might not be an efficient solution but it is perfectly legit in those situations since it cannot be exploited.
Hey, how about you guys actually try to figure out why his code isn't working instead of coming up with crazy overcomplicated alternatives?
Starting with this:
[lua]local function PlaySoundClip(win)
if win == WIN_INNOCENT then
BroadcastLua('function">surface.PlaySound("'..InnocentWinSounds[math.random(1, #InnocentWinSounds)]..'")')
elseif win == WIN_TRAITOR then
BroadcastLua('surface.PlaySound("'..TraitorWinSounds[math.random(1, #TraitorWinSounds)]..'")')
elseif win == WIN_TIMELIMIT then
BroadcastLua('surface.PlaySound("'..OutOfTimeSounds[math.random(1, #OutOfTimeSounds)]..'")')
end
end[/lua]
The first call to BroadcastLua is wrong. The function"> part shouldn't be there, maybe you accidentally left that in while copy-pasting?
[lua] BroadcastLua('surface.PlaySound("'..InnocentWinSounds[math.random(1, #InnocentWinSounds)]..'")')[/lua]
This is the fixed code.
If the only thing you did while testing was making innocents win, that might just be the reason why this code doesn't work. It would have sent a line of broken code to all clients, who would try to run it and get an error.
If this still doesn't work, open up the developer console and watch for red errors that mention missing sound files. Maybe you didn't put the sound files at the right place.
When in doubt, add prints. Something as simple as print("hello") inside a function can tell you if that function is being called or not, simply by looking at the console.
[QUOTE]Failed to load sound "whiteguy.wav", file probably missing from disk/repository[/QUOTE]
This prints in my console. Every sound does that.
[editline]18th June 2013[/editline]
Nvm I got this working.
Apparently he had another sound script installed that was blocking mine.
Hey guys do you know if this code is only limited to three songs per win? as it works but it seems to only play 3 of the four i have put in! thankyou
[QUOTE=Mooseham;47698940]Hey guys do you know if this code is only limited to three songs per win? as it works but it seems to only play 3 of the four i have put in! thankyou[/QUOTE]
It isn't.
[QUOTE=brandonj4;41075115]Your post shows that you don't know how TTT works at all.
You're trying to call a hook clientside when it's serverside.
You want proof? Go ahead and run this in a shared file:
[lua]
hook.Add("TTTEndRound", "I am SERVERSIDE", function(wintype)
print("I AM SERVERSIDE")
end)
[/lua]
As for the OP, it's obvious you're installing it wrong because I know my script works.
Save it as a ".lua" extension file inside "lua/autorun/" and it will be good to go.[/QUOTE]
Woah cowboy, calm down. Stop being so arrogant.
Sorry, you need to Log In to post a reply to this thread.