• Server Random Begin Round & End Round Script Error
    19 replies, posted
I've been coding some LUA for a bit and managed to do a simple script which uses table.Random to play random songs on BeginRound and EndRound for my TTT server. Unfortunately, the sounds have problems. I'm quite experienced and have tried FastDL and making the script available to client as well as the sounds files, which seems to download normally. My script is as follow: [CODE]if SERVER then AddCSLuaFile( "RoundMusic.lua") end --Building arrays for applying to EmitSound later on traitorstartarr = {"sound/bungeemod/traitorstart1.ogg", "sound/bungeemod/traitorstart2.ogg", "sound/bungeemod/traitorstart3.ogg"} traitorwinarr = {"sound/bungeemod/traitorwin1.ogg", "sound/bungeemod/traitorwin2.ogg", "sound/bungeemod/traitorwin3.ogg"} innocentstartarr = {"sound/bungeemod/innocentstart1.ogg", "sound/bungeemod/innocentstart2.ogg", "sound/bungeemod/innocentstart3.ogg"} innocentwinarr = {"sound/bungeemod/innocentswin1.ogg", "sound/bungeemod/innocentwin2.ogg", "sound/bungeemod/innocentwin3.ogg"} detectivestartarr = {"sound/bungeemod/detectivestart1.ogg", "sound/bungeemod/detectivestart2.ogg", "sound/bungeemod/detectivestart3.ogg"} if SERVER then -- Add files to download resource.AddSingleFile("sound/bungeemod/traitorstart1.ogg") resource.AddSingleFile("sound/bungeemod/traitorstart2.ogg") resource.AddSingleFile("sound/bungeemod/traitorstart3.ogg") resource.AddSingleFile("sound/bungeemod/detectivestart1.ogg") resource.AddSingleFile("sound/bungeemod/detectivestart2.ogg") resource.AddSingleFile("sound/bungeemod/detectivestart3.ogg") resource.AddSingleFile("sound/bungeemod/innocentstart1.ogg") resource.AddSingleFile("sound/bungeemod/innocentstart2.ogg") resource.AddSingleFile("sound/bungeemod/innocentstart3.ogg") resource.AddSingleFile("sound/bungeemod/traitorwin1.ogg") resource.AddSingleFile("sound/bungeemod/traitorwin2.ogg") resource.AddSingleFile("sound/bungeemod/traitorwin3.ogg") resource.AddSingleFile("sound/bungeemod/innocentwin1.ogg") resource.AddSingleFile("sound/bungeemod/innocentwin2.ogg") resource.AddSingleFile("sound/bungeemod/innocentwin3.ogg") -- Precache the sounds after all entities are created. Because why not? hook.Add( "InitPostEntity", "delaySoundPrecache", function() util.PrecacheSound( "detectivestart1.ogg" ) util.PrecacheSound( "detectivestart2.ogg" ) util.PrecacheSound( "detectivestart3.ogg" ) util.PrecacheSound( "innocentstart1.ogg" ) util.PrecacheSound( "innocentstart2.ogg" ) util.PrecacheSound( "innocentstart3.ogg" ) util.PrecacheSound( "traitorstart1.ogg" ) util.PrecacheSound( "traitorstart2.ogg" ) util.PrecacheSound( "traitorstart3.ogg" ) util.PrecacheSound( "innocentwin1.ogg" ) util.PrecacheSound( "innocentwin2.ogg" ) util.PrecacheSound( "innocentwin3.ogg" ) util.PrecacheSound( "traitorwin1.ogg" ) util.PrecacheSound( "traitorwin2.ogg" ) util.PrecacheSound( "traitorwin3.ogg" ) end ) end if CLIENT then -- On the round start. Play the precached sounds to the right people. hook.Add( "TTTBeginRound", "sexyRoundMusic", function( ply ) if LocalPlayer():GetTraitor() then -- If traitor LocalPlayer():EmitSound( table.Random( traitorstartarr ) ) elseif LocalPlayer():GetDetective() then -- If Detective LocalPlayer():EmitSound( table.Random( detectivestartarr ) ) else -- Everything else LocalPlayer():EmitSound( table.Random( innocentstartarr ) ) end end ) -- On the round end, play music from arrays according to the players class, same principle as above but with the (wintype) function local function PlayMusic(wintype) if wintype == WIN_INNOCENT then LocalPlayer():EmitSound( table.Random( traitorwinarr ) ) elseif wintype == WIN_TRAITOR then LocalPlayer():EmitSound( table.Random( traitorwinarr ) ) elseif wintype == WIN_TIMELIMIT then LocalPlayer():EmitSound( table.Random( traitorwinarr ) ) end end hook.Add("TTTEndRound", "MyMusic", PlayMusic) end[/CODE] This file is placed in my garrysmod/lua/autorun folder (server-side of course). The files are placed to the correct paths and file corruption and typos have been triple-checked. In game, I do not receive any errors both from the server and the client until the script decides to make the sounds play. Also, as mentionned before, the sounds do not download to the cache directory for a reason I don't understand: [IMG]http://bungeetaco.com/public/images/2013-11-09_03-41-41.png[/IMG] Which then gives this: Create Stream Failed error 41 Failed to load sound "bungeemod\innocentstart2.ogg", file probably missing from disk/repository I am noticing that it is using backslashes instead... Any help would be greatly appreciated from anyone that may understand the problem further that I can... [B]As being my first post, which is asking help from a fine and distinguished community, I am hoping I won't get hated if I did any error. Otherwise, please excuse me and I'll direct myself to the right ressources. Thanks![/B]
Just so you know, how it presents the line (aka having the backslash instead of the frontslash) is just how it decides to show it and has no true bearing on the issue. As for the actual issue, it is because it is not downloading the files. Make sure that they are all set up properly on the server and the fast download (if one is set up.)
That's really odd, I am going to double check the FastDL and come write back on this exact post. [B]Result:[/B] With ULX, I can force a playsound and the sounds play with no problem, but when the round starts and it's supposed to play a sound, it comes back to the same... [QUOTE]You prevented the round from ending untill timeout. You played sound bungeemod/innocentstart1.ogg You are playing Trouble in Terrorist Town, version 2013-07-28. You are: TRAITOR TTT: The Traitors have been selected. Create Stream Failed error 41 Failed to load sound "sound\bungeemod\traitorstart1.ogg", file probably missing from disk/repository [/QUOTE] This is the FastDL and the server.cfg file: [IMG]http://bungeetaco.com/public/images/2013-11-09_04-08-40.png[/IMG] [IMG]http://bungeetaco.com/public/images/2013-11-09_04-10-05.png[/IMG]
Ah. Looking at it again makes me see this: [lua]traitorstartarr = {"sound/bungeemod/traitorstart1.ogg", "sound/bungeemod/traitorstart2.ogg", "sound/bungeemod/traitorstart3.ogg"} traitorwinarr = {"sound/bungeemod/traitorwin1.ogg", "sound/bungeemod/traitorwin2.ogg", "sound/bungeemod/traitorwin3.ogg"} innocentstartarr = {"sound/bungeemod/innocentstart1.ogg", "sound/bungeemod/innocentstart2.ogg", "sound/bungeemod/innocentstart3.ogg"} innocentwinarr = {"sound/bungeemod/innocentswin1.ogg", "sound/bungeemod/innocentwin2.ogg", "sound/bungeemod/innocentwin3.ogg"} detectivestartarr = {"sound/bungeemod/detectivestart1.ogg", "sound/bungeemod/detectivestart2.ogg", "sound/bungeemod/detectivestart3.ogg"}[/lua] Remove the sound/ from each of them and they should work like a charm. You never want to include sound/, resource/, materials/, models/ unless you're using the resource.AddFile as when you are setting it (either SetModel or sound.Play) it will automatically add it. Essentially you are having it call the following sound: sound/sound/bungeemod/innocentstart1.ogg [editline]9th November 2013[/editline] PS: You may want to remove the image of your RCON password and change it now.
Change your rcon password asap
[QUOTE]PS: You may want to remove the image of your RCON password and change it now.[/QUOTE] Heh, don't worry, I changed it before snapping a picture on my pc, but on FTP it's different. Gotta try it :P [IMG]http://bungeetaco.com/public/images/2013-11-09_04-14-39.png[/IMG] [B]Result:[/B] I still get the Create Stream Failed error 41 on trying to play, but now the sounds are available on the cache and plays at will with ULX, which is a nifty improvement. [QUOTE]Failed to load sound "bungeemod\traitorstart3.ogg",[/QUOTE] [IMG]http://bungeetaco.com/public/images/2013-11-09_04-22-02.png[/IMG]
Get a screenshot of your console please. I wanna see the error in its natural habitat
Use resource.addfile with "sound/" Remove the "sound/" when you're actually playing the sound sound/sound/bungeemod/music.ogg doesnt exist
Okidoki: [IMG]http://bungeetaco.com/public/images/2013-11-09_04-28-27.png[/IMG] As you can see, there is no console error on both sides. Simply missing out the files when it comes to it... [editline]9th November 2013[/editline] [QUOTE]Use resource.addfile with "sound/" Remove the "sound/" when you're actually playing the sound sound/sound/bungeemod/music.ogg doesnt exist[/QUOTE] I'm going to try that on top waiting for what KarmaLord has to say...
Could you also provide the current code as it stands after the edits?
[QUOTE=rejax;42807513]Use resource.addfile with "sound/" Remove the "sound/" when you're actually playing the sound sound/sound/bungeemod/music.ogg doesnt exist[/QUOTE] [IMG]http://bungeetaco.com/public/images/2013-11-09_04-32-20.png[/IMG] [editline]9th November 2013[/editline] [QUOTE=KarmaLord;42807532]Could you also provide the current code as it stands after the edits?[/QUOTE] Did you mean the one above or with your recommendations?
As it sits on your computer right now after doing the various things suggested by us few. AKA what is in the image you posted, but the actual code instead of an image of part of it
Any reason you're using resource.AddSingleFile () ?
Can Garry's Mod even run .oggs? I remember trying to do something with .oggs but no matter what I did, it did the exact error just with a different path.
Complete Code (Pasted): [CODE]if SERVER then AddCSLuaFile( "RoundMusic.lua") end --Building arrays for applying to EmitSound later on traitorstartarr = {"bungeemod/traitorstart1.ogg", "bungeemod/traitorstart2.ogg", "bungeemod/traitorstart3.ogg"} traitorwinarr = {"bungeemod/traitorwin1.ogg", "bungeemod/traitorwin2.ogg", "bungeemod/traitorwin3.ogg"} innocentstartarr = {"bungeemod/innocentstart1.ogg", "bungeemod/innocentstart2.ogg", "bungeemod/innocentstart3.ogg"} innocentwinarr = {"bungeemod/innocentswin1.ogg", "bungeemod/innocentwin2.ogg", "bungeemod/innocentwin3.ogg"} detectivestartarr = {"bungeemod/detectivestart1.ogg", "bungeemod/detectivestart2.ogg", "bungeemod/detectivestart3.ogg"} if SERVER then -- Add files to download resource.AddSingleFile("sound/bungeemod/traitorstart1.ogg") resource.AddSingleFile("sound/bungeemod/traitorstart2.ogg") resource.AddSingleFile("sound/bungeemod/traitorstart3.ogg") resource.AddSingleFile("sound/bungeemod/detectivestart1.ogg") resource.AddSingleFile("sound/bungeemod/detectivestart2.ogg") resource.AddSingleFile("sound/bungeemod/detectivestart3.ogg") resource.AddSingleFile("sound/bungeemod/innocentstart1.ogg") resource.AddSingleFile("sound/bungeemod/innocentstart2.ogg") resource.AddSingleFile("sound/bungeemod/innocentstart3.ogg") resource.AddSingleFile("sound/bungeemod/traitorwin1.ogg") resource.AddSingleFile("sound/bungeemod/traitorwin2.ogg") resource.AddSingleFile("sound/bungeemod/traitorwin3.ogg") resource.AddSingleFile("sound/bungeemod/innocentwin1.ogg") resource.AddSingleFile("sound/bungeemod/innocentwin2.ogg") resource.AddSingleFile("sound/bungeemod/innocentwin3.ogg") -- Precache the sounds after all entities are created. Because why not? hook.Add( "InitPostEntity", "delaySoundPrecache", function() util.PrecacheSound( "detectivestart1.ogg" ) util.PrecacheSound( "detectivestart2.ogg" ) util.PrecacheSound( "detectivestart3.ogg" ) util.PrecacheSound( "innocentstart1.ogg" ) util.PrecacheSound( "innocentstart2.ogg" ) util.PrecacheSound( "innocentstart3.ogg" ) util.PrecacheSound( "traitorstart1.ogg" ) util.PrecacheSound( "traitorstart2.ogg" ) util.PrecacheSound( "traitorstart3.ogg" ) util.PrecacheSound( "innocentwin1.ogg" ) util.PrecacheSound( "innocentwin2.ogg" ) util.PrecacheSound( "innocentwin3.ogg" ) util.PrecacheSound( "traitorwin1.ogg" ) util.PrecacheSound( "traitorwin2.ogg" ) util.PrecacheSound( "traitorwin3.ogg" ) end ) end if CLIENT then -- On the round start. Play the precached sounds to the right people. hook.Add( "TTTBeginRound", "sexyRoundMusic", function( ply ) if LocalPlayer():GetTraitor() then -- If traitor LocalPlayer():EmitSound( table.Random( traitorstartarr ) ) elseif LocalPlayer():GetDetective() then -- If Detective LocalPlayer():EmitSound( table.Random( detectivestartarr ) ) else -- Everything else LocalPlayer():EmitSound( table.Random( innocentstartarr ) ) end end ) -- On the round end, play music from arrays according to the players class, same principle as above but with the (wintype) function local function PlayMusic(wintype) if wintype == WIN_INNOCENT then LocalPlayer():EmitSound( table.Random( traitorwinarr ) ) elseif wintype == WIN_TRAITOR then LocalPlayer():EmitSound( table.Random( traitorwinarr ) ) elseif wintype == WIN_TIMELIMIT then LocalPlayer():EmitSound( table.Random( traitorwinarr ) ) end end hook.Add("TTTEndRound", "MyMusic", PlayMusic) end[/CODE] [editline]9th November 2013[/editline] [QUOTE=Sm63;42807550]Can Garry's Mod even run .oggs? I remember trying to do something with .oggs but no matter what I did, it did the exact error just with a different path.[/QUOTE] I had a hard time checking out if it did, but it supports alot of formats, notably .wav's and .ogg's pretty easily, otherwise the console would give a sample rate error or simply refuse it...
Any reason [lua] util.PrecacheSound( "detectivestart1.ogg" ) util.PrecacheSound( "detectivestart2.ogg" ) util.PrecacheSound( "detectivestart3.ogg" ) util.PrecacheSound( "innocentstart1.ogg" ) util.PrecacheSound( "innocentstart2.ogg" ) util.PrecacheSound( "innocentstart3.ogg" ) util.PrecacheSound( "traitorstart1.ogg" ) util.PrecacheSound( "traitorstart2.ogg" ) util.PrecacheSound( "traitorstart3.ogg" ) util.PrecacheSound( "innocentwin1.ogg" ) util.PrecacheSound( "innocentwin2.ogg" ) util.PrecacheSound( "innocentwin3.ogg" ) util.PrecacheSound( "traitorwin1.ogg" ) util.PrecacheSound( "traitorwin2.ogg" ) util.PrecacheSound( "traitorwin3.ogg" )[/lua] Doesn't follow the proper precache methods? You still need the path there, relative to the sound directory (I think, may be including the sound/.) Plus, why are you using EmitSound? Still looking at the code, just curious for that [editline]9th November 2013[/editline] Also, as you may or may not have seen (I'm in your server) it is currently giving a nopath issue on win (Failed to load sound "", file probably missing from disk/repository)
You may be familiar with GMod Tower? Welp, the main lua scripter fixed some things with my single file play version, which was okay. I used BroadcastLua with play.Sound, I did not precache the files before that and it still worked. It simply makes them ready [QUOTE]Any reason you're using resource.AddSingleFile () ?[/QUOTE] One or either doesn't change anything with sound files... It's mainly useful if you have models using the same names and instead of downloading them individually, it takes the files with the same name, whatever the extension may be...
Oh, and your win sounds are all traitorwinarr I'd just remove the precache as it is unneeded really and it's wrong so yeah
[QUOTE]Also, as you may or may not have seen (I'm in your server) it is currently giving a nopath issue on win (Failed to load sound "", file probably missing from disk/repository)[/QUOTE] That's weird, it didn't print anything in console nor play a sound on my side, taking in consideration that my sounds have been cached on my side before I made changes to the script and that I may have changed something after... [editline]9th November 2013[/editline] [QUOTE=KarmaLord;42807594]Oh, and your win sounds are all traitorwinarr I'd just remove the precache as it is unneeded really and it's wrong so yeah[/QUOTE] Fixed for this: [CODE]if SERVER then AddCSLuaFile( "RoundMusic.lua") end --Building arrays for applying to EmitSound later on traitorstartarr = {"bungeemod/traitorstart1.ogg", "bungeemod/traitorstart2.ogg", "bungeemod/traitorstart3.ogg"} traitorwinarr = {"bungeemod/traitorwin1.ogg", "bungeemod/traitorwin2.ogg", "bungeemod/traitorwin3.ogg"} innocentstartarr = {"bungeemod/innocentstart1.ogg", "bungeemod/innocentstart2.ogg", "bungeemod/innocentstart3.ogg"} innocentwinarr = {"bungeemod/innocentswin1.ogg", "bungeemod/innocentwin2.ogg", "bungeemod/innocentwin3.ogg"} detectivestartarr = {"bungeemod/detectivestart1.ogg", "bungeemod/detectivestart2.ogg", "bungeemod/detectivestart3.ogg"} roundendarr = {"bungeemod/roundend1.ogg", "bungeemod/roundend2.ogg", "bungeemod/roundend3.ogg"} if SERVER then -- Add files to download resource.AddSingleFile("sound/bungeemod/traitorstart1.ogg") resource.AddSingleFile("sound/bungeemod/traitorstart2.ogg") resource.AddSingleFile("sound/bungeemod/traitorstart3.ogg") resource.AddSingleFile("sound/bungeemod/detectivestart1.ogg") resource.AddSingleFile("sound/bungeemod/detectivestart2.ogg") resource.AddSingleFile("sound/bungeemod/detectivestart3.ogg") resource.AddSingleFile("sound/bungeemod/innocentstart1.ogg") resource.AddSingleFile("sound/bungeemod/innocentstart2.ogg") resource.AddSingleFile("sound/bungeemod/innocentstart3.ogg") resource.AddSingleFile("sound/bungeemod/traitorwin1.ogg") resource.AddSingleFile("sound/bungeemod/traitorwin2.ogg") resource.AddSingleFile("sound/bungeemod/traitorwin3.ogg") resource.AddSingleFile("sound/bungeemod/innocentwin1.ogg") resource.AddSingleFile("sound/bungeemod/innocentwin2.ogg") resource.AddSingleFile("sound/bungeemod/innocentwin3.ogg") resource.AddSingleFile("sound/bungeemod/roundend1.ogg") resource.AddSingleFile("sound/bungeemod/roundend2.ogg") resource.AddSingleFile("sound/bungeemod/roundend3.ogg") -- Precache the sounds after all entities are created. Because why not? hook.Add( "InitPostEntity", "delaySoundPrecache", function() util.PrecacheSound( "detectivestart1.ogg" ) util.PrecacheSound( "detectivestart2.ogg" ) util.PrecacheSound( "detectivestart3.ogg" ) util.PrecacheSound( "innocentstart1.ogg" ) util.PrecacheSound( "innocentstart2.ogg" ) util.PrecacheSound( "innocentstart3.ogg" ) util.PrecacheSound( "traitorstart1.ogg" ) util.PrecacheSound( "traitorstart2.ogg" ) util.PrecacheSound( "traitorstart3.ogg" ) util.PrecacheSound( "innocentwin1.ogg" ) util.PrecacheSound( "innocentwin2.ogg" ) util.PrecacheSound( "innocentwin3.ogg" ) util.PrecacheSound( "traitorwin1.ogg" ) util.PrecacheSound( "traitorwin2.ogg" ) util.PrecacheSound( "traitorwin3.ogg" ) end ) end if CLIENT then -- On the round start. Play the precached sounds to the right people. hook.Add( "TTTBeginRound", "sexyRoundMusic", function( ply ) if LocalPlayer():GetTraitor() then -- If traitor LocalPlayer():EmitSound( table.Random( traitorstartarr ) ) elseif LocalPlayer():GetDetective() then -- If Detective LocalPlayer():EmitSound( table.Random( detectivestartarr ) ) else -- Everything else LocalPlayer():EmitSound( table.Random( innocentstartarr ) ) end end ) -- On the round end, play music from arrays according to the players class, same principle as above but with the (wintype) function local function PlayMusic(wintype) if wintype == WIN_INNOCENT then LocalPlayer():EmitSound( table.Random( innocentwinarr ) ) elseif wintype == WIN_TRAITOR then LocalPlayer():EmitSound( table.Random( traitorwinarr ) ) elseif wintype == WIN_TIMELIMIT then LocalPlayer():EmitSound( table.Random( roundendarr ) ) end end hook.Add("TTTEndRound", "MyMusic", PlayMusic) end[/CODE] [editline]9th November 2013[/editline] [B]SOLVED[/B] Using surface.PlaySound busted the problem. I don't exactly know who recommended this function over surface.PlaySound, but welp... Thanks for your help everybody :D.
Fixed with Bungee ingame, he should be closing this soon :P Just switched EmitSound to surface.PlaySound
Sorry, you need to Log In to post a reply to this thread.