I wanna upload a few mp3/wavs to play at the end of the round on my TTT server, I have no experience in Lua but I'm asking for the file that will allow me to do that if anybody actually has it.
I also wanna know where to upload it/where to put music files in.
I appreciate this very much, many thanks
[QUOTE]local iwin = {"/AfterRoundMusic/zeph-bloodsugar-v00.mp3","/AfterRoundMusic/zeph-saveme-v00.mp3","/AfterRoundMusic/zeph-omen-v00.mp3"}
local twin = {"/AfterRoundMusic/tswin1.mp3","/AfterRoundMusic/zeph-glory-v00.mp3","/AfterRoundMusic/zeph-invadersmustdie-v00.mp3"}
local function PlayMusic(wintype)
if wintype == WIN_INNOCENT then
BroadcastLua('surface.PlaySound("' ..table.Random(iwin).. '")')
elseif wintype == WIN_TRAITOR then
BroadcastLua('surface.PlaySound("' ..table.Random(twin).. '") ')
elseif wintype == WIN_TIMELIMIT then
BroadcastLua('surface.PlaySound("' ..table.Random(iwin).. '")')
end
end
hook.Add("TTTEndRound", "MyMusic", PlayMusic)[/QUOTE]
[editline]23rd April 2013[/editline]
Instead of the music I have up there, put your songs up
[editline]23rd April 2013[/editline]
And to upload music, do this. resource.AddFile('<your mucic here with out the <>>")
[editline]23rd April 2013[/editline]
here is an example, [QUOTE]resource.AddFile ("sound/ttt/omen.mp3")[/QUOTE]
Ok thanks! But I have a question, where do I add the music, and where do I put resource.AddFile ("sound/ttt/omen.mp3")
Also, where do I add the file? I'd save it as music.lua?
You need to have different names for each music file. This post round music file would go as any name you want. It goes into garrysmod/lua/autorun/server. The music clips go into sound/ttt. This is where you name one of clips. You cant name one file the same as others. Give me one of your music clip names and I will put done an example of the resource.AddLua.
korn.mp3, where do I do resource.Addlua? is that a command or do I put that in the file you gave me
edit: I tried playing the sound and I got this
You played sound ttt/korn.mp3 [LC ULib ERROR] Received invalid sound
heres another version
[lua]-- You can add up to 3 sounds for this. Add or delete resource.addfile as you need
resource.AddFile("sound/trawon1.mp3")
resource.AddFile("sound/trawon2.mp3")
resource.AddFile("sound/trawon3.mp3")
resource.AddFile("sound/inowon1.mp3")
resource.AddFile("sound/inowon2.mp3")
resource.AddFile("sound/inowon3.mp3")
resource.AddFile("sound/timelimitreached.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("inowon'..math.random(1,3)..'.mp3")')
elseif wintype == WIN_TRAITOR then
BroadcastLua('surface.PlaySound("trawon'..math.random(1,3)..'.mp3")')
elseif wintype == WIN_TIMELIMIT then
BroadcastLua('surface.PlaySound("timelimitreached.mp3")')
end
end
hook.Add("TTTEndRound", "MyMusic", PlayMusic)[/lua]
pretty much create a lua file paste this in then put it in lua/autorun name your songs inowon1 inowon2 inowon3 and trawon1 trawon2 trawon3 it will randomize between the tracks put the mp3s in you garrymod/sounds folder and restart and you should be good
Thank you so much guys!!! Sikvi your script works but tobias' script may work too but sikvi's is easier since it has resource.addfile and the music in 1 file, thank's a lot guys, I'll try to return the favor somehow
With this you should be able to just add more .mp3's to your defined folder and it should be good to go:
[lua]
local BaseFolder = "MyFolderStuff"; -- Relative to sounds/
local TraitorPrefix = "tra_"; -- What the traitor sound names should start with.
local InnocentPrefix = "inno_"; -- What the innocent sound names should start with.
local Sounds = {
[ WIN_INNOCENT ] = {},
[ WIN_TRAITOR ] = {}
};
local tFiles, tDirs = file.Find( "sound/" .. BaseFolder .. "/*.mp3", "GAME" );
for k, v in pairs( tFiles ) do
resource.AddFile( "sound/" .. BaseFolder .. "/" .. v ); -- Add te sound to the resources.
-- Check if the file starts with either of the prefixes, and
-- adds them to the correct table.
if ( string.StartWith( v, TraitorPrefix ) ) then
table.insert( Sounds[ WIN_TRAITOR ], v );
elseif ( string.StartWith( v, InnocentPrefix ) ) then
table.insert( Sounds[ WIN_INNOCENT ], v );
end
end
-- Basically just to make it look neater.
local function PlaySound( sSound )
BroadcastLua( 'surface.PlaySound("' .. BaseFolder .. '/' .. sSound .. '")' );
end
hook.Add( "TTTEndRound", "EndRoundMusiks", function( type )
if ( Sounds[ type ] ) then
PlaySound( Sounds[ type ][ math.random( 1, #Sounds[ type ] ) ] );
else
PlaySound( "timelimitreached.mp3" );
end
end );[/lua]
Sorry, you need to Log In to post a reply to this thread.