• Playing world sound
    4 replies, posted
Hey there, I want to change the darkRP lockdown to loop a sound as well as play a sound when it is initiated. Basically, the mayor initiates lockdown, an overwatch message is broadcasted, then for the duration of the lockdown, this specific sound is looped. Once the lockdown ends, the sound stops. Code snippet: [code] local function Lockdown(ply) if not lstat and ply:Team() == TEAM_MAYOR then for k,v in pairs(player.GetAll()) do v:ConCommand("play npc/overwatch/cityvoice/f_confirmcivilstatus_1_spkr.wav\n") end lstat = true PrintMessageAll(HUD_PRINTTALK , LANGUAGE.lockdown_started) RunConsoleCommand("DarkRP_LockDown", 1) NotifyAll(4, 3, LANGUAGE.lockdown_started) end return "" end [/code] The sound I want to loop is: "ambient/alarms/citadel_alert_loop2.wav"
[lua] local function Lockdown(ply) if not lstat and ply:Team() == TEAM_MAYOR then timer.Create( "lockdowntimer", 5, 0, function() // Change the value 5 to the number of seconds in between the sounds played for k,v in pairs(player.GetAll()) do v:ConCommand("play npc/overwatch/cityvoice/f_confirmcivilstatus_1_spkr.wav\n") end end) lstat = true PrintMessageAll(HUD_PRINTTALK , LANGUAGE.lockdown_started) RunConsoleCommand("DarkRP_LockDown", 1) NotifyAll(4, 3, LANGUAGE.lockdown_started) end return "" end [/lua] IMPORTANT!!! You must put: [lua]timer.Destroy("lockdowntimer")[/lua] somewhere in the code that ends the lockdown, or the timer will be infinite
Thanks for the reply Andriko! I assume where you put function() in the timer.create you mean I should make a new function which simply plays the sound? For example: local playlockdownFunction() ConCommand("play ambient/alarms/citadel_alert_loop2.wav\n") like that?
no, but what you could do is this: [lua] local function lockdowntimer() for k,v in pairs(player.GetAll()) do v:ConCommand("play npc/overwatch/cityvoice/f_confirmcivilstatus_1_spkr.wav\n") end end timer.Create( "lockdowntimer", 5, 0, lockdowntimer ) [/lua] My other version is just better This also works with hook.Add(), concommand.Add(), and anything else where you input a function as an argument
It is not liking the "pairs" value. "Bad Argument #1 'pairs' (table expected, got nil)" EDIT: NEVERMIND! That error was from something else. I had a nil timer error but that was because I hadn't declared the function until after the lockdown function so I had to move my timer function above it, as you showed in your code snippet.
Sorry, you need to Log In to post a reply to this thread.