Welcome, Guest. Please login or register.
Did you miss your activation email?
November 22, 2024, 08:51:43 AM
Home Help Login Register
News: Trouble in Terrorist Town? Site here, forum here.

Zombie Master  |  Other  |  Trouble in Terrorist Town  |  Topic: TTT Randomized Win Music?
Pages: [1]
Author Topic: TTT Randomized Win Music?  (Read 5562 times)
Glathal
Poster

Posts: 13


« on: October 29, 2011, 12:13:33 AM »

I know that there's a way to code in win music depending on the team who won is, or was. But, Say I had 5 traitor win songs, and 5 innocent win songs, What would I do to make them randomly pick from those depending on who won?
An example of what I have so far is as follows :


resource.AddFile("sound/ttt/traitorwin1.mp3")
resource.AddFile("sound/ttt/innocentwin1.mp3")
 
local function PlayMusic(wintype)
if wintype == WIN_INNOCENT then
BroadcastLua('surface.PlaySound("ttt/innocentwin1.mp3")')
 
elseif wintype == WIN_TRAITOR then
BroadcastLua('surface.PlaySound("ttt/traitorwin1.mp3") ')
 
elseif wintype == WIN_TIMELIMIT then
BroadcastLua('surface.PlaySound("ttt/innocentwin1.mp3")')
end
end
hook.Add("TTTEndRound", "MyMusic", PlayMusic)


I know that designates only one song per team, but What would I have to do to make it select from one of the 5 traitor songs when a traitor wins, or from the 5 other songs when innocents win, thanks!
moarx
Poster

Posts: 40


« Reply #1 on: October 29, 2011, 06:11:25 PM »

Please, don't make the clips too long, I've been on a few servers that have played music nearly the entire time between rounds and it's extremely annoying.
Tommynator
Poster

Posts: 173

Tommynator is a traitor!


« Reply #2 on: October 29, 2011, 07:59:23 PM »

I suck @ lua, but this might work. I'm sure I did an error somewhere but I can't test...  :D


local songs = {
"sound/ttt/traitorwin1.mp3",
"sound/ttt/innocentwin1.mp3"
       }
 
for i = 0, #t, 1 do
   Resource.AddFile(songs[i])
end  
 
local function PlayMusic(wintype)
   local randomsound = songs[math.random(#songs)]
   local stringsong = string.Implode("", { "'surface.PlaySound(\"", randomsound, "\")'" })
   BroadcastLua(stringsong)
end
hook.Add("TTTEndRound", "MyMusic", PlayMusic)


« Last Edit: October 29, 2011, 08:01:53 PM by Tommynator »
Anonymous
Poster

Posts: 126


« Reply #3 on: October 29, 2011, 08:03:20 PM »

	
local function PlayMusic(wintype)
if wintype == WIN_INNOCENT then

local choice = math.random( 1, 7 )
if ( choice == 1 ) then
BroadcastLua('surface.PlaySound("ttt/innocentwin1.mp3")')

Tommynator
Poster

Posts: 173

Tommynator is a traitor!


« Reply #4 on: October 29, 2011, 08:07:08 PM »

Well mine is better if he wants to add more songs :D
Anonymous
Poster

Posts: 126


« Reply #5 on: October 29, 2011, 11:35:45 PM »

All he has to do is:


if ( choice == <NUMBER> ) then
BroadcastLua('surface.PlaySound("<MUSIC PATH>")')

nrich588
Poster

Posts: 253

WzG Owner


« Reply #6 on: October 31, 2011, 04:11:04 AM »

Don't listen to anonymous, Tommynator's looked the most correct.
Glathal
Poster

Posts: 13


« Reply #7 on: November 04, 2011, 04:40:58 PM »

Sorry to be a bother, but I just tried both, and they didn't work. :U... I'm putting the file into  "lua/autorun/server"  I'm decently new to lua, so I'm sorry if I'm a pain in the booty. Can someone walk me through the variables in tommy's script? Are the strings inclusive to what files are being downloaded? do I have to add a completely different section for traitors? etc. Thanks.
Pages: [1]
Zombie Master  |  Other  |  Trouble in Terrorist Town  |  Topic: TTT Randomized Win Music? « previous next »
Jump to:  


Login with username, password and session length

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines
Page created in 0.01 seconds with 18 queries.