• Trouble in Terrorist Town Help (Sounds)
    72 replies, posted
Hello everyone, I've recently made a new TTT server and I would like some help with the coding. I would like to make it play music at the end of a round. So far, here's a script: resource.AddFile("sound/traitor_win.mp3") resource.AddFile("sound/inno_win.mp3") resource.AddFile("sound/time_win.mp3") local function PlayMusic(wintype) if wintype == WIN_INNOCENT then BroadcastLua('surface.PlaySound("inno_win.mp3")') elseif wintype == WIN_TRAITOR then BroadcastLua('surface.PlaySound("traitor_win.mp3")') elseif wintype == WIN_TIMELIMIT then BroadcastLua('surface.PlaySound("time_win.mp3")') end end hook.Add("TTTEndRound", "MyMusic", PlayMusic) I'd like it to play a song at random, NOT DEPENDING ON WHO WINS ; and I'd like it to stop as soon as the next round starts, Thanks! Thanks.
We also tried this: resource.AddFile("sound/ttt/1.mp3") resource.AddFile("sound/ttt/2.wav") resource.AddFile("sound/ttt/3.mp3") resource.AddFile("sound/ttt/4.mp3") resource.AddFile("sound/ttt/5.mp3") resource.AddFile("sound/ttt/6.mp3") resource.AddFile("sound/ttt/7.wav") resource.AddFile("sound/ttt/8.wav") resource.AddFile("sound/ttt/9.mp3") resource.AddFile("sound/ttt/10.mp3") local music = { Sound("sound/ttt/1.mp3"), Sound("sound/ttt/2.wav"), Sound("sound/ttt/3.mp3"), Sound("sound/ttt/4.mp3"), Sound("sound/ttt/5.mp3"), Sound("sound/ttt/6.mp3"), Sound("sound/ttt/7.wav"), Sound("sound/ttt/8.wav"), Sound("sound/ttt/9.mp3"), Sound("sound/ttt/10.mp3") }; local function PlayMusic(wintype) if wintype == WIN_INNOCENT then BroadcastLua('surface.PlaySound(table.Random(music))') elseif wintype == WIN_TRAITOR then BroadcastLua('surface.PlaySound(table.Random(music))') elseif wintype == WIN_TIMELIMIT then BroadcastLua('surface.PlaySound(table.Random(music))') end end hook.Add("TTTEndRound", "MyMusic", PlayMusic) I fail with LUA, so I have no idea what I am doing. Could anyone tell me why wont this work?
IIRC, surface.PlaySound is already in the sound directory so sound/ttt/1.mp3 -> ttt/1.mp3 [editline]28th June 2011[/editline] Also you need to escape BroadcastLua('surface.PlaySound(table.Random(music ))') to BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]])
[QUOTE=RetTurtl3;30760261]IIRC, surface.PlaySound is already in the sound directory so sound/ttt/1.mp3 -> ttt/1.mp3 [editline]28th June 2011[/editline] Also you need to escape BroadcastLua('surface.PlaySound(table.Random(music ))') to BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]])[/QUOTE] [lua] resource.AddFile("sound/ttt/blow.mp3") local music = { Sound("ttt/blow.mp3"), }; local function PlayMusic(wintype) if wintype == WIN_INNOCENT then BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) elseif wintype == WIN_TRAITOR then BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) elseif wintype == WIN_TIMELIMIT then BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) end end hook.Add("TTTEndRound", "MyMusic", PlayMusic) [/lua] i modified like this, but it was not works...
Hmm... It didn't seem to work. I even tried using songs from counter-strike and hl2. Here is what I used: local music = { Sound("ambient/music/country_rock_am_radio_loop.wav"), Sound("music/ravenholm_1.mp3"), Sound("music/hl2_song15.mp3"), Sound("ambient/music/cubanmusic1.wav"), Sound("ambient/music/flamenco.wav"), Sound("ambient/music/latin.wav"), Sound("ambient/music/looping_radio_mix.wav"), Sound("ambient/music/mirame_radio_thru_wall.wav"), Sound("ambient/music/dustmusic2.wav"), Sound("ambient/music/dustmusic3.wav") }; local function PlayMusic(wintype) if wintype == WIN_INNOCENT then BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) elseif wintype == WIN_TRAITOR then BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) elseif wintype == WIN_TIMELIMIT then BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) end end hook.Add("TTTEndRound", "MyMusic", PlayMusic) The lua file is currently in lua/autorun.
Bcuz WIN_INNOCENT isn't a team add it to autorun/server and find the proper TEAM TEAM ya know like TEAM_TRAITOR or something
The teams are correct, and I'm only playing the sounds once the round is over. I still need help, and I'm still open to suggestions. I can make sounds play, but I'd like random sounds to play instead of the same one over and over. Please HELP!
[QUOTE=Apozen;30766349]The teams are correct, and I'm only playing the sounds once the round is over. I still need help, and I'm still open to suggestions. I can make sounds play, but I'd like random sounds to play instead of the same one over and over. Please HELP![/QUOTE] How did you do that? please help me i wrote like that [lua] resource.AddFile("sound/ttt/blow.mp3") local music = { Sound("ttt/blow.mp3"), }; local function PlayMusic(wintype) if wintype == WIN_INNOCENT then BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) elseif wintype == WIN_traitor then BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) elseif wintype == WIN_TIMELIMIT then BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) end end hook.Add("TTTEndRound", "MyMusic", PlayMusic) [/lua] what is the wrong point?
instead of table.Random(music) try music[math.random(1, table.GetLastValue)] And WIN_INNOCENT isn't a team. It's a variable called when the innocent(s) / detective(s) are the last alive or kill off the traitor(s)
[QUOTE=cyw960517;30768545]How did you do that? please help me i wrote like that resource.AddFile("sound/ttt/blow.mp3") local music = { Sound("ttt/blow.mp3"), }; local function PlayMusic(wintype) if wintype == WIN_INNOCENT then BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) elseif wintype == WIN_traitor then BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) elseif wintype == WIN_TIMELIMIT then BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) end end hook.Add("TTTEndRound", "MyMusic", PlayMusic) what is the wrong point?[/QUOTE] Here's what I did, and It works right now: [lua] resource.AddFile("sound/ttt/traitor_win.mp3") resource.AddFile("sound/ttt/inno_win.mp3") resource.AddFile("sound/ttt/time_win.mp3") local function PlayMusic(wintype) if wintype == WIN_INNOCENT then BroadcastLua('surface.PlaySound("ttt/inno_win.mp3")') elseif wintype == WIN_TRAITOR then BroadcastLua('surface.PlaySound("ttt/traitor_win.mp3") ') elseif wintype == WIN_TIMELIMIT then BroadcastLua('surface.PlaySound("ttt/time_win.mp3")') end end hook.Add("TTTEndRound", "MyMusic", PlayMusic) [/lua] That's what I use at the moment, and it works wonderfully right now. I wanted to make it choose a song from random to play from my selected sounds. InfernalCookie, Could you please input your suggestion into the code? I'm a little off where to put it.
[lua] local function PlayMusic(wintype) if wintype == WIN_INNOCENT then BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) elseif wintype == WIN_TRAITOR then BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) elseif wintype == WIN_TIMELIMIT then BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) end end [/lua] instead of table.Random(music) try music[math.Random(1,table.GetLastValue)] although I don't think that's the issue. I think the issue is because it's inputting Sound("ambient/music/cubanmusic1.wav"), instead of the actual string, which is what it needs to do. Try making it just the string?
Alright, I'll mess around with it and see if anything happens :) [editline]28th June 2011[/editline] I messed around with it, and nothing worked :C Here's the script: [lua] resource.AddFile("sound/ttt/horse.mp3") resource.AddFile("sound/ttt/trollface.mp3") resource.AddFile("sound/ttt/pwnedftw.wav") resource.AddFile("sound/ttt/thisfire.mp3") resource.AddFile("sound/ttt/snakeeater.mp3") resource.AddFile("sound/ttt/pwnsong.mp3") local music = { Sound("ttt/pwnedftw.wav"), Sound("ttt/snakeeater.mp3"), Sound("ttt/thisfire.mp3"), Sound("ttt/trollface.mp3"), Sound("ttt/pwnsong.mp3"), Sound("ttt/horse.mp3"), }; local function PlayMusic(wintype) if wintype == WIN_INNOCENT then BroadcastLua([[surface.PlaySound(]]..music[math.Random(1,table.GetLastValue)] elseif wintype == WIN_TRAITOR then BroadcastLua([[surface.PlaySound(]]..music[math.Random(1,table.GetLastValue)] elseif wintype == WIN_TIMELIMIT then BroadcastLua([[surface.PlaySound(]]..music[math.Random(1,table.GetLastValue)] end end hook.Add("TTTEndRound", "MyMusic", PlayMusic) [/lua] I don't see what i'm doing wrong, and I'd like professional help. I am not a good LUA scripter, and I suck ass at coding. Anymore suggestions?
Bump
Replace this with your script [lua]local function PlayMusic(wintype) print(wintype) end hook.Add("TTTEndRound", "MyMusic", PlayMusic)[/lua] And type kill in console a few times even when traitor detective and innocent and give us the console output
I've found your issue now. This is in init.lua, I hope you can figure out what to do with the following code, if not we can help. :) [lua] function EndRound(type) ServerLog("Round ended.\n") ---------- most important vv if type == WIN_TIMELIMIT then LANG.Msg("win_time") ServerLog("Result: timelimit reached, traitors lose.\n") elseif type == WIN_TRAITOR then LANG.Msg("win_traitor") ServerLog("Result: traitors win.\n") elseif type == WIN_INNOCENT then LANG.Msg("win_innocent") ServerLog("Result: innocent win.\n") else ServerLog("Result: unknown victory condition!\n") end -------- most important ^^ -- first handle round end SetRoundState(ROUND_POST) local ptime = math.max(5, GetConVar("ttt_posttime_seconds"):GetInt()) LANG.Msg("win_showreport", {num = ptime}) timer.Create("end2prep", ptime, 1, PrepareRound) -- Piggyback on "round end" time global var to show end of phase timer SetRoundEnd(CurTime() + ptime) timer.Create("restartmute", ptime - 1, 1, MuteForRestart, true) -- Stop checking for wins StopWinChecks() -- ...... and it keeps going but the above is the most important. [/lua] [editline]29th June 2011[/editline] Just noticed something, the function at 755 in init.lua [lua] function GM:MapTriggeredEnd(wintype) self.MapWin = wintype end [/lua] has wintype, but that isn't even in the actual init.lua file. I will search for this variable, for now see if you can find out what to do with the above, as I have a feeling that will work.
[QUOTE=RetTurtl3;30788391]Replace this with your script local function PlayMusic(wintype) print(wintype) end hook.Add("TTTEndRound", "MyMusic", PlayMusic) And type kill in console a few times even when traitor detective and innocent and give us the console output[/QUOTE] I actually don't get anything. I only got this: RunConsoleCommand blocked - sent before player spawned (ZLib_Installed) TTT: The Traitors have been defeated! Round state: 4 TTT: Let's look at the round report for 30 seconds. I doubt that's anything. Was that what you're looking for?
He wanted to know if you were actually recieving a ... (can't think of the word) ... value ? (I guess that works). And since you aren't recieving a value it isn't printing, so you need to use the info I gave above, or find another way.
[QUOTE=InfernalCookie;30789051]I've found your issue now. This is in init.lua, I hope you can figure out what to do with the following code, if not we can help. :) [lua] function EndRound(type) ServerLog("Round ended.\n") ---------- most important vv if type == WIN_TIMELIMIT then LANG.Msg("win_time") ServerLog("Result: timelimit reached, traitors lose.\n") elseif type == WIN_TRAITOR then LANG.Msg("win_traitor") ServerLog("Result: traitors win.\n") elseif type == WIN_INNOCENT then LANG.Msg("win_innocent") ServerLog("Result: innocent win.\n") else ServerLog("Result: unknown victory condition!\n") end -------- most important ^^ -- first handle round end SetRoundState(ROUND_POST) local ptime = math.max(5, GetConVar("ttt_posttime_seconds"):GetInt()) LANG.Msg("win_showreport", {num = ptime}) timer.Create("end2prep", ptime, 1, PrepareRound) -- Piggyback on "round end" time global var to show end of phase timer SetRoundEnd(CurTime() + ptime) timer.Create("restartmute", ptime - 1, 1, MuteForRestart, true) -- Stop checking for wins StopWinChecks() -- ...... and it keeps going but the above is the most important. [/lua] [editline]29th June 2011[/editline] Just noticed something, the function at 755 in init.lua [lua] function GM:MapTriggeredEnd(wintype) self.MapWin = wintype end [/lua] has wintype, but that isn't even in the actual init.lua file. I will search for this variable, for now see if you can find out what to do with the above, as I have a feeling that will work.[/QUOTE] I actually have no idea what to do with that, and I am really sorry lol. What you wrote actually makes sense, but I have no knowledge of what to do with it :(
In your file put this here and try this, with your table of course. [lua] function EndRound( type ) if type == WIN_INNOCENT then BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) elseif type == WIN_TRAITOR then BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) elseif type == WIN_TIMELIMIT thenBroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) end end [/lua]
[QUOTE=InfernalCookie;30789437]In your file put this here and try this, with your table of course. [lua] function EndRound( type ) if type == WIN_INNOCENT then BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) elseif type == WIN_TRAITOR then BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) elseif type == WIN_TIMELIMIT thenBroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) end end [/lua][/QUOTE] I copied what you said and put it into my script, and nothing came up. Could you perhaps paste it into the script? I don't think I'm placing it right. And thanks for all your help so far :) I appreciate it. I'm placing the script in autorun>server btw.
[lua]local music = { Sound("ambient/music/country_rock_am_radio_loop.wav"), Sound("music/ravenholm_1.mp3"), Sound("music/hl2_song15.mp3"), Sound("ambient/music/cubanmusic1.wav"), Sound("ambient/music/flamenco.wav"), Sound("ambient/music/latin.wav"), Sound("ambient/music/looping_radio_mix.wav"), Sound("ambient/music/mirame_radio_thru_wall.wav"), Sound("ambient/music/dustmusic2.wav"), Sound("ambient/music/dustmusic3.wav") }; local function PlaySound(type) if type == WIN_INNOCENT then BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) elseif type == WIN_TRAITOR then BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) elseif type == WIN_TIMELIMIT then BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) end end hook.Add("TTTEndRound", "MyMusic", PlayMusic) [/lua] [editline]30th June 2011[/editline] try that
[QUOTE=InfernalCookie;30791285][lua]local music = { Sound("ambient/music/country_rock_am_radio_loop.wav"), Sound("music/ravenholm_1.mp3"), Sound("music/hl2_song15.mp3"), Sound("ambient/music/cubanmusic1.wav"), Sound("ambient/music/flamenco.wav"), Sound("ambient/music/latin.wav"), Sound("ambient/music/looping_radio_mix.wav"), Sound("ambient/music/mirame_radio_thru_wall.wav"), Sound("ambient/music/dustmusic2.wav"), Sound("ambient/music/dustmusic3.wav") }; local function PlaySound(type) if type == WIN_INNOCENT then BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) elseif type == WIN_TRAITOR then BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) elseif type == WIN_TIMELIMIT then BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) end end hook.Add("TTTEndRound", "MyMusic", PlayMusic) [/lua] [editline]30th June 2011[/editline] try that[/QUOTE] I tried it, and still no luck. [lua] local music = { Sound("ambient/music/country_rock_am_radio_loop.wav"), Sound("music/ravenholm_1.mp3"), Sound("music/hl2_song15.mp3"), Sound("ambient/music/cubanmusic1.wav"), Sound("ambient/music/flamenco.wav"), Sound("ambient/music/latin.wav"), Sound("ambient/music/looping_radio_mix.wav"), Sound("ambient/music/mirame_radio_thru_wall.wav"), Sound("ambient/music/dustmusic2.wav"), Sound("ambient/music/dustmusic3.wav") }; local function PlaySound(type) if type == WIN_INNOCENT then BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) elseif type == WIN_TRAITOR then BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) elseif type == WIN_TIMELIMIT then BroadcastLua([[surface.PlaySound(]]..table.Random(music)..[[)]]) end end hook.Add("TTTEndRound", "MyMusic", PlayMusic) [/lua] I'm sorry if this is getting really uptight, and you could take a break if needed :)
Okay so I tested it. Getting the random Sound works, playing the sound works, and the hook should work.. So that leaves it at the function. Let me test it on my own server and see if the server is getting "type" andit is actually being called. If it does work then it means it's where you placed it. I'll reply in a few minutes. [editline]30th June 2011[/editline] Okay so it is recieving the type AND getting a random value, as I saw it printing into the console. So the issue HAS to be the BroadcastLua code. Let me look into the TTT code for this more.
Alright! Thanks!
Can someone tell me where the code to play the sound in TTT is?
[lua] resource.AddFile("sound/ttt/traitor_win.mp3") resource.AddFile("sound/ttt/inno_win.mp3") resource.AddFile("sound/ttt/time_win.mp3") local function PlayMusic(wintype) if wintype == WIN_INNOCENT then BroadcastLua('surface.PlaySound("ttt/inno_win.mp3")') elseif wintype == WIN_TRAITOR then BroadcastLua('surface.PlaySound("ttt/traitor_win.mp3") ') elseif wintype == WIN_TIMELIMIT then BroadcastLua('surface.PlaySound("ttt/time_win.mp3")') end end hook.Add("TTTEndRound", "MyMusic", PlayMusic) [/lua] That's my code to play a sound if the traitor and innocent wins "Not at Random though". Hope that helps.
So I've singled out the problem. It's because apparently it won't load the "sound here", it has to be surrounded by a pair of ' '. For example. 'surface.PlaySound('..' "ttt/traitor_win.mp3" '..')' works but 'surface.PlaySound('..GetRandomValue..')' does not, and "surface.PlaySound("..GetRandomValue..")" doesn't work either.. everything else works fine though. We may have to find another way to make everyone play these sounds. Perhaps a for loop and make everyone run the console command to run the randomvalue?
Would we have to make everyone run the console command every time the server restarts?
Everytime the round ends.
[QUOTE=InfernalCookie;30808354]Everytime the round ends.[/QUOTE] Shall I code it for him or let him figure it out himself. :v:
Sorry, you need to Log In to post a reply to this thread.