diff --git a/gamemodes/zombieplague/gamemode/cl_init.lua b/gamemodes/zombieplague/gamemode/cl_init.lua index 8c66b275..3f62a7fb 100644 --- a/gamemodes/zombieplague/gamemode/cl_init.lua +++ b/gamemodes/zombieplague/gamemode/cl_init.lua @@ -1,6 +1,7 @@ include("shared.lua") include("cl_roundmanager.lua") +include("cl_soundmanager.lua") include("cl_message.lua") include("cl_player.lua") include("cl_hud.lua") diff --git a/gamemodes/zombieplague/gamemode/cl_soundmanager.lua b/gamemodes/zombieplague/gamemode/cl_soundmanager.lua new file mode 100644 index 00000000..29af4dee --- /dev/null +++ b/gamemodes/zombieplague/gamemode/cl_soundmanager.lua @@ -0,0 +1,56 @@ +SoundManager = { + Sounds = {} +} + +function SoundManager:EmitLoopSound(SoundId, SoundPath, SoundDuration) + local TimerName = SoundId .. "Timer" + + SoundManager:PlaySound(SoundId, SoundPath, SoundDuration) + timer.Create(TimerName, SoundDuration, 0, function() + SoundManager:PlaySound(SoundId, SoundPath, SoundDuration) + end) +end +function SoundManager:PlaySound(SoundId, SoundPath, SoundDuration) + local SoundData = SoundManager.Sounds[SoundId] + + if SoundData then + SoundData.LoopSound:Stop() + end + + local LoopSound = CreateSound(LocalPlayer(), SoundPath) + + LoopSound:SetSoundLevel(0) + LoopSound:Play() + + local SoundData = { + LoopSound = LoopSound, + TimerName = TimerName + } + + SoundManager.Sounds[SoundId] = SoundData +end +function SoundManager:StopLoopSound(SoundId) + local SoundData = SoundManager.Sounds[SoundId] + + if SoundData then + local LoopSound = SoundData.LoopSound + local TimerName = SoundData.TimerName + + LoopSound:Stop() + timer.Remove(TimerName) + + SoundManager.Sounds[SoundId] = nil + end +end + +net.Receive("EmitLoopSound", function() + local SoundId = net.ReadString() + local SoundPath = net.ReadString() + local SoundDuration = net.ReadInt(32) + + SoundManager:EmitLoopSound(SoundId, SoundPath, SoundDuration) +end) + +net.Receive("StopLoopSound", function() + local SoundId = net.ReadString() +end) \ No newline at end of file diff --git a/gamemodes/zombieplague/gamemode/init.lua b/gamemodes/zombieplague/gamemode/init.lua index cb4e9cf0..d6c2d753 100644 --- a/gamemodes/zombieplague/gamemode/init.lua +++ b/gamemodes/zombieplague/gamemode/init.lua @@ -10,6 +10,7 @@ include("sv_language.lua") include("sv_message.lua") include("sv_classmanager.lua") include("sv_roundmanager.lua") +include("sv_soundmanager.lua") include("sv_eventmanager.lua") include("sv_infectionmanager.lua") include("sv_weaponmanager.lua") @@ -23,6 +24,7 @@ AddCSLuaFile("sh_bank.lua") AddCSLuaFile("sh_roundmanager.lua") AddCSLuaFile("sh_player.lua") AddCSLuaFile("sh_playermanager.lua") +AddCSLuaFile("cl_soundmanager.lua") AddCSLuaFile("cl_hud.lua") AddCSLuaFile("cl_language.lua") AddCSLuaFile("cl_message.lua") diff --git a/gamemodes/zombieplague/gamemode/sv_roundmanager.lua b/gamemodes/zombieplague/gamemode/sv_roundmanager.lua index 1059668f..365e0a8d 100644 --- a/gamemodes/zombieplague/gamemode/sv_roundmanager.lua +++ b/gamemodes/zombieplague/gamemode/sv_roundmanager.lua @@ -27,10 +27,20 @@ function RoundManager:SearchRounds() RoundToAdd.Order = 100 include(Files) + --Improve this validation in the future if RoundToAdd:ShouldBeEnabled() then if !RoundToAdd.StartFunction || !RoundToAdd.Name then Utils:Print(WARNING_MESSAGE, "Invalid round format: '" .. File .. "'!") - else + elseif RoundToAdd.Sound then + if RoundToAdd.Sound.Path then + Utils:Print(WARNING_MESSAGE, "No 'Path' was informed to the 'Sound' on file: '" .. File .. "'!") + end + if RoundToAdd.Sound.Duration then + Utils:Print(WARNING_MESSAGE, "No 'Duration' was informed to the 'Sound' on file: '" .. File .. "'!") + end + + RoundManager:AddRoundType(RoundToAdd) + elseif !RoundToAdd.Sound || (RoundToAdd.Sound.Path && RoundToAdd.Sound.Duration) then RoundManager:AddRoundType(RoundToAdd) end end @@ -47,6 +57,13 @@ function RoundManager:AddRoundType(RoundID, RoundType) resource.AddFile("sound/" .. SoundPath) end end + if RoundType.Sound then + for k, Sound in pairs(RoundType.Sound) do + PrintTable(RoundType.Sound) + local SoundPath = Sound.Path + resource.AddFile("sound/" .. Sound.Path) + end + end end function RoundManager:GetServerStatus(Requester) local ServerStatus = { @@ -212,6 +229,12 @@ function RoundManager:StartRound(RoundToStart, ply) self:SetRoundState(ROUND_PLAYING) self.RoundPlaying = RoundToStart + if RoundToStart.Sound then + timer.Create("TriggerRoundSound", 2, 1, function() + SoundManager:EmitLoopSound("RoundSound", SafeTableRandom(RoundToStart.Sound)) + end) + end + hook.Call("ZPNewRound", GAMEMODE, RoundToStart, self:GetRound()) end function RoundManager:GetCurrentRoundPlaying() @@ -333,12 +356,17 @@ function RoundManager:ReturnValidPlayerToBeRewardedOrNil(SteamID64, Team) return (ply && ply:Team() == Team) and ply or nil end function RoundManager:AddDefaultRounds() + local AmbienceSound = {{ + Path = "zombieplague/ambience.wav", + Duration = 18 + }} local ROUND = {} ROUND.Name = "RoundSimpleName" ROUND.MinPlayers = cvars.Number("zp_min_players", 2) ROUND.Chance = 100 ROUND.SpecialRound = false ROUND.Respawn = false + ROUND.Sound = AmbienceSound ROUND.Order = 1 ROUND.StartFunction = function(ply) local PlayersToPlay = RoundManager:GetPlayersToPlay(true) @@ -361,6 +389,7 @@ function RoundManager:AddDefaultRounds() ROUND.Name = "RoundMultiInfectionName" ROUND.Chance = 15 ROUND.MinPlayers = 4 + ROUND.Sound = AmbienceSound ROUND.Order = 2 ROUND.Respawn = false ROUND.StartFunction = function() @@ -386,6 +415,7 @@ function RoundManager:AddDefaultRounds() ROUND.SpecialRound = true ROUND.Respawn = false ROUND.StartSound = {"zombieplague/nemesis1.mp3", "zombieplague/nemesis2.mp3"} + ROUND.Sound = AmbienceSound ROUND.Order = 3 ROUND.StartFunction = function() local PlayersToPlay = RoundManager:GetPlayersToPlay(true) @@ -418,6 +448,7 @@ function RoundManager:AddDefaultRounds() ROUND.MinPlayers = 3 ROUND.SpecialRound = true ROUND.StartSound = {"zombieplague/survivor1.mp3", "zombieplague/survivor2.mp3"} + ROUND.Sound = AmbienceSound ROUND.Order = 4 ROUND.StartFunction = function() local Players = RoundManager:GetPlayersToPlay(true) @@ -450,6 +481,7 @@ function RoundManager:AddDefaultRounds() ROUND.MinPlayers = 4 ROUND.SpecialRound = true ROUND.StartSound = {"zombieplague/swarmmode.mp3"} + ROUND.Sound = AmbienceSound ROUND.Order = 5 ROUND.StartFunction = function() local Players = RoundManager:GetPlayersToPlay(true) @@ -474,6 +506,7 @@ function RoundManager:AddDefaultRounds() ROUND.MinPlayers = 4 ROUND.SpecialRound = true ROUND.StartSound = {"zombieplague/plaguemode.mp3"} + ROUND.Sound = AmbienceSound ROUND.Order = 6 ROUND.StartFunction = function() local Players = RoundManager:GetPlayersToPlay(true) diff --git a/gamemodes/zombieplague/gamemode/sv_soundmanager.lua b/gamemodes/zombieplague/gamemode/sv_soundmanager.lua new file mode 100644 index 00000000..ef161dc5 --- /dev/null +++ b/gamemodes/zombieplague/gamemode/sv_soundmanager.lua @@ -0,0 +1,19 @@ +SoundManager = {} + +function SoundManager:EmitLoopSound(SoundId, Sound) + print(Sound.Path) + print(Sound.Duration) + net.Start("EmitLoopSound") + net.WriteString(SoundId) + net.WriteString(Sound.Path) + net.WriteInt(Sound.Duration, 32) + net.Broadcast() +end +function SoundManager:StopLoopSound(SoundId) + net.Start("StopLoopSound") + net.WriteString(SoundId) + net.Broadcast() +end + +util.AddNetworkString("EmitLoopSound") +util.AddNetworkString("StopLoopSound") \ No newline at end of file diff --git a/sound/zombieplague/ambience.wav b/sound/zombieplague/ambience.wav new file mode 100644 index 00000000..d94b420f Binary files /dev/null and b/sound/zombieplague/ambience.wav differ