Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gamemodes/zombieplague/gamemode/cl_init.lua
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
56 changes: 56 additions & 0 deletions gamemodes/zombieplague/gamemode/cl_soundmanager.lua
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions gamemodes/zombieplague/gamemode/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down
35 changes: 34 additions & 1 deletion gamemodes/zombieplague/gamemode/sv_roundmanager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions gamemodes/zombieplague/gamemode/sv_soundmanager.lua
Original file line number Diff line number Diff line change
@@ -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")
Binary file added sound/zombieplague/ambience.wav
Binary file not shown.