-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) |