Skip to content

Commit

Permalink
Add consulcast plugin (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
Miyoglow committed Apr 24, 2022
1 parent 4d23fa8 commit fc0b555
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 0 deletions.
13 changes: 13 additions & 0 deletions consulcast/cl_plugin.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

local PLUGIN = PLUGIN

ix.chat.Register("consulcast", {
format = "PA system broadcasts \"%s\"",
color = Color(175, 54, 45),
CanSay = function(_, speaker)
return not IsValid(speaker)
end,
OnChatAdd = function(self, _, text)
chat.AddText(self.color, string.format(self.format, text))
end
})
24 changes: 24 additions & 0 deletions consulcast/sh_plugin.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

local PLUGIN = PLUGIN

PLUGIN.name = "Consulcast"
PLUGIN.author = "wowm0d"
PLUGIN.description = "Adds ambient industrial (beta) announcement broadcasts to the city."
PLUGIN.schema = "HL2 RP"
PLUGIN.license = [[
Copyright 2022 wowm0d
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
To view a copy of this license, visit http:https://creativecommons.org/licenses/by-nc-sa/4.0/.
]]

ix.config.Add("consulcastDelay", 300, "How long of a delay inbetween Consulcasts in seconds.", function()
if (SERVER) then
PLUGIN:OnLoaded()
end
end, {
data = {min = 1, max = 3600},
category = "server"
})

ix.util.Include("sv_plugin.lua")
ix.util.Include("cl_plugin.lua")
70 changes: 70 additions & 0 deletions consulcast/sv_plugin.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@

local PLUGIN = PLUGIN

PLUGIN.consulcasts = {
["industrial17/c17_pa0.wav"] = "The true citizen knows that duty is the greatest gift.",
["industrial17/c17_pa1.wav"] = "The true citizen appreciates the comforts of City 17, but uses discretion.",
["industrial17/c17_pa2.wav"] = "The true citizen's identiband is kept clean and visible at all times.",
["industrial17/c17_pa3.wav"] = "The true citizen's job is the opposite of slavery.",
["industrial17/c17_pa4.wav"] = "The true citizen conserves valuable oxygen."
}

PLUGIN.speakers = {
["rp_industrial17_v1"] = {3319, 3320, 3321, 3322, 3323, 3324, 3325, 3476, 4976}
}

function PLUGIN:InitPostEntity()
if (self.speakers[game.GetMap()]) then
self.speakerEnts = {}

for _, v in next, self.speakers[game.GetMap()] do
table.insert(self.speakerEnts, ents.GetMapCreatedEntity(v))
end
else
ix.plugin.SetUnloaded("consulcast", true, true)
end
end

local lastCast

function PLUGIN:OnLoaded()
timer.Create("consulcast", ix.config.Get("consulcastDelay"), 0, function()
local message, soundPath

repeat
message, soundPath = table.Random(self.consulcasts)
until (soundPath ~= lastCast)

lastCast = soundPath

for _, v in next, self.speakerEnts do
v:EmitSound(soundPath, 85, nil, nil, nil, nil, 57)
end

ix.chat.Send(nil, "consulcast", message)
end)
end

function PLUGIN:OnUnload()
timer.Remove("consulcast")
end

ix.chat.Register("consulcast", {
CanSay = function(_, speaker)
return not IsValid(speaker)
end,
CanHear = function(_, _, listener)
for _, v in next, PLUGIN.speakerEnts do
local speakerPos = v:GetPos()

local recipientFilter = RecipientFilter()
recipientFilter:AddPAS(speakerPos)

if (table.HasValue(recipientFilter:GetPlayers(), listener) and listener:EyePos():Distance(speakerPos) <= 2500) then
return true
end
end

return false
end
})

0 comments on commit fc0b555

Please sign in to comment.