• Start Round Music
    9 replies, posted
Hello, I want to modify this code [CODE]-- You can add up to 3 sounds for this. Add or delete resource.addfile as you need resource.AddFile("sound/startandendmusic/startmusic/start_music_1.mp3") resource.AddFile("sound/startandendmusic/startmusic/start_music_2.mp3") -- Remember to change the name of the sounds to the sound you want from above local function PlayMusic(wintype) if wintype == WIN_INNOCENT then BroadcastLua('surface.PlaySound("music/start/start_music_1.mp3")') elseif wintype == WIN_TRAITOR then BroadcastLua('surface.PlaySound("music/start/start_music_2.mp3")') end end hook.Add("TTTBeginRound", "MyMusic", PlayMusic)[/CODE] But instead of round end I want it to randomize one of these files and play it at the beginning. THanks in advanced.
Just a note .. as I remember it "TTTBeginRound" has no parameters. I'm tired, its 2:46 here .. and no clue if this works. [lua] // List over all the sound files (Without the 'sound/' !!!) local List = {} // Make table List[1] = "startandendmusic/startmusic/start_music_1.mp3" // Add to table List[2] = "startandendmusic/startmusic/rickroll.mp3" List[3] = "startandendmusic/startmusic/getonmyhorse.mp3" // We make the clients download all the music in the list for i, fil in ipairs(List) do // Runs through the list resource.AddFile("sound/"..fil) // Adds them to the "download" list end local function PlayMusic() BroadcastLua('surface.PlaySound("'..List[math.random(1,#List)]..'")') // Run this string with a random sound path from the list end hook.Add("TTTBeginRound", "SomethingThatArentTaken", PlayMusic) // Runs PlayMusic each time the round starts[/lua] No idea if I did a mistype and if I were you, I won't use the "BroadcastLua" that much. Night
Hmm, it doesn't work. It's not forcing us to download anything and there are no errors.
This is my current code [CODE]-- List over all the sound files (Without the 'sound/' !!!) local List = {} // Make table List[1] = "music/start/track1.mp3" // Add to table List[2] = "music/start/track2.mp3" local function PlayMusic() BroadcastLua('surface.PlaySound("'..List[math.random(1,#List)]..'")') -- Run this string with a random sound path from the list end hook.Add("TTTBeginRound", "SomethingThatArentTaken", PlayMusic) -- Runs PlayMusic each time the round starts[/CODE] But on round start I get this error [CODE]Failed to load sound "music\start\track2.mp3", file probably missing from disk/repository Y[/CODE] The file that forces them to download is a seperate file, but this is the code [CODE]if (SERVER) then resource.AddFile("sound/music/start/track1.mp3") resource.AddFile("sound/music/start/track2.mp3") end [/CODE]
Maybe because you forgot to copy this?: [lua] // We make the clients download all the music in the list for i, fil in ipairs(List) do // Runs through the list resource.AddFile("sound/"..fil) // Adds them to the "download" list end[/lua]
Also, when you put // do you mean --? Because when you put // it still counts it as code, but with -- it doesn't.
Probably your editor which doesn't like // being comments, they're not in default lua, it's something garry added.
[QUOTE=GlenSH;39682269]Also, when you put // do you mean --?[/QUOTE] [url=http://wiki.teamfortress.com/w/images/6/64/Spy_highfive04.wav]Trust me[/url], I only added those to help you continue working with G-LUA. If you knew that '//' kinda looks like '--' .. you should have seen the connection :P [Protip] Read the full posted code .. sometimes it pays off reading the "comments" that someone spent 10-20 key-hits on. [QUOTE=GlenSH;39682269]Because when you put // it still counts it as code, but with -- it doesn't.[/QUOTE] Get notepad++ (A great tool) and the Gmod plugin for it: [url]http://code.google.com/p/npp-gmod-lua/[/url]
Ok, it's nearly all working now. Only one problem, it's only playing one song, and that's strack1. Any idea why this is happening? This is the code: [CODE]-- List over all the sound files (Without the 'sound/' !!!) local List = {} // Make table List[1] = "strack1.mp3" -- Add to table List[2] = "strack1.mp3" -- We make the clients download all the music in the list for i, fil in ipairs(List) do -- Runs through the list resource.AddFile("sound/"..fil) -- Adds them to the "download" list end local function PlayMusic() BroadcastLua('surface.PlaySound("'..List[math.random(1,#List)]..'")') -- Run this string with a random sound path from the list end hook.Add("TTTBeginRound", "SomethingThatArentTaken", PlayMusic) -- Runs PlayMusic each time the round starts[/CODE] Oh, and I already use Notepad++ and the Plugin wouldn't install correctly. From my LUA knowledge (Extremely Small) there doesn't seem to be anything wrong with the code. [editline]23rd February 2013[/editline] Wait, forget all that. I just realized I derped hard xD
[QUOTE=GlenSH;39688122]-snip-[/QUOTE] What have the symbol "/" ever don to you? .-. You can't just dis' it cu'z its different! Jk :P
Sorry, you need to Log In to post a reply to this thread.