Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local AlarmSystem = {}
- local SoundService = game.Workspace.Sounds
- local Permissions = require(game.ServerScriptService.Services.Modules.Permissions)
- local CollectionService = game:GetService("CollectionService")
- local SafeZoneParts = CollectionService:GetTagged("OxyDepSafeZone")
- local SafetyZones = {}
- for _, part in ipairs(workspace:GetDescendants()) do
- if part:GetAttribute("OxygenSafeZone") then
- table.insert(SafetyZones, part)
- end
- end
- local function isInSafetyZone(Player)
- if not Player.Character then
- return false
- end
- if Player.Character:FindFirstChild("Oxygen") then
- return true
- end
- for _, Zone in ipairs(SafetyZones) do
- local humanoidRootPart = Player.Character:FindFirstChild("HumanoidRootPart")
- if not humanoidRootPart then
- return false
- end
- local WhitelistedParts = { humanoidRootPart }
- local Params = OverlapParams.new()
- Params.FilterDescendantsInstances = WhitelistedParts
- Params.FilterType = Enum.RaycastFilterType.Include
- local Parts = workspace:GetPartBoundsInBox(Zone.CFrame, Zone.Size, Params)
- if #Parts >= 1 then
- return true
- end
- end
- return false
- end
- AlarmSystem.Procedures = {
- ClearHorizon = {
- Name = "ClearHorizon",
- IsActive = false,
- CanToggle = true,
- IsPrimary = true,
- ClearOnDisable = false,
- DisableAlarms = true,
- DisablePrevious = true,
- AnnouncementSound = SoundService.Protocols.ClearHorizon:FindFirstChild("ClearHorizonAnnouncement"),
- Permissions = {
- ["Group:Main"] = 255
- }
- },
- OrangeFire = {
- Name = "OrangeFire",
- IsActive = false,
- CanToggle = true,
- IsPrimary = true,
- ClearOnDisable = true,
- DisablePrevious = true,
- AnnouncementSound = SoundService.Protocols.OrangeFire:FindFirstChild("OrangeFireAnnouncement"),
- AlarmSettings = {
- Color = Color3.new(1, 0.521569, 0.101961),
- BackgroundAmbience = SoundService.Protocols.OrangeFire:FindFirstChild("OrangeFireAmbience"),
- },
- Permissions = {
- ["Group:Main"] = 255
- }
- },
- OxygenDepletion = {
- Name = "OxygenDepletion",
- IsActive = false,
- CanToggle = false,
- IsPrimary = false,
- ClearOnDisable = false,
- DisablePrevious = true,
- AnnouncementSound = SoundService.Protocols.OxygenDepletion:FindFirstChild("OxygenDepletionAnnouncement"),
- AlarmSettings = {
- BackgroundAmbience = SoundService.Protocols.OxygenDepletion:FindFirstChild("OxygenDepletionAmbience"),
- },
- Permissions = {
- ["Group:Main"] = 243
- },
- EnableServerFunction = function()
- game.Workspace.OxygenDep.OxCount.Value = 5
- game.Workspace.OxygenDep.DepletionInProgress.Value = true
- while game.Workspace.OxygenDep.DepletionInProgress.Value do
- warn(game.Workspace.OxygenDep.OxCount.Value)
- if game.Workspace.OxygenDep.OxCount.Value == -1 then
- game.Workspace.OxygenDep.Extracting.Value = true
- game.Workspace.OxygenDep.DepletionInProgress.Value = false
- SoundService.Protocols.OxygenDepletion:FindFirstChild("Vacuum"):Play()
- for _, Player in ipairs(game.Players:GetPlayers()) do
- if Player.Character then
- local HumanoidRootPart = Player.Character:FindFirstChild("HumanoidRootPart")
- local Humanoid = Player.Character:FindFirstChild("Humanoid")
- if HumanoidRootPart and Humanoid then
- local IsInSafety = isInSafetyZone(Player)
- if not IsInSafety or game.Workspace.OxygenDep.AffectShelter.Value == true then
- Humanoid:TakeDamage(Humanoid.MaxHealth)
- end
- end
- end
- end
- task.wait(1)
- AlarmSystem:ActivateProcedure("OrangeFire", "Server")
- end
- game.Workspace.OxygenDep.OxCount.Value -= 1
- task.wait(1)
- end
- end,
- DisableServerFunction = function()
- game.Workspace.OxygenDep.OxCount.Value = 5
- game.Workspace.OxygenDep.DepletionInProgress.Value = false
- end,
- },
- }
- function AlarmSystem:GetProcedure(name)
- return AlarmSystem.Procedures[name]
- end
- function AlarmSystem:ListProcedures()
- local list = {}
- for _, proc in pairs(AlarmSystem.Procedures) do
- table.insert(list, proc.Name)
- end
- return list
- end
- function AlarmSystem:Init()
- game.ReplicatedStorage.Events.GetProtocols.OnServerInvoke = function()
- return AlarmSystem:ListProcedures()
- end
- game.ServerStorage.Events.GetProtocols.OnInvoke = function()
- return AlarmSystem:ListProcedures()
- end
- self:ActivateProcedure("ClearHorizon", "Server")
- end
- function AlarmSystem:DisableAll(primaryOnly)
- for _, proc in pairs(AlarmSystem.Procedures) do
- if proc.IsActive and (not primaryOnly or proc.IsPrimary) then
- AlarmSystem:DeactivateProcedure(proc.Name, "Server")
- end
- end
- end
- function AlarmSystem:ActivateProcedure(name, player)
- local proc = AlarmSystem:GetProcedure(name)
- if not proc then
- warn("Invalid procedure: " .. tostring(name))
- return "Invalid procedure: " .. tostring(name)
- end
- if player ~= "Server" then
- if not Permissions:CanUserAccess(player, proc.Permissions) then
- warn("Access denied for " .. player.Name)
- return "Access denied for " .. player.Name
- end
- end
- if proc.IsActive then
- warn("Procedure already active: " .. proc.Name)
- return "Procedure already active: " .. proc.Name
- end
- if proc.DisableAlarms then
- game.Workspace.Alarms.Value = Color3.new(0, 0, 0)
- wait(0.4)
- game.Workspace.AlarmState.Value = false
- else
- if proc.AlarmSettings.Color then
- game.Workspace.Alarms.Value = proc.AlarmSettings.Color
- end
- wait(0.4)
- game.Workspace.AlarmState.Value = true
- end
- if proc.DisablePrevious then
- AlarmSystem:DisableAll()
- end
- proc.IsActive = true
- if proc.AnnouncementSound then proc.AnnouncementSound:Play() end
- if proc.AlarmSettings and proc.AlarmSettings.BackgroundAmbience then
- proc.AlarmSettings.BackgroundAmbience:Play()
- end
- coroutine.wrap(function()
- if proc.EnableServerFunction then
- proc.EnableServerFunction()
- end
- end)()
- return proc.Name .. " activated"
- end
- function AlarmSystem:DeactivateProcedure(name, player, clear)
- local proc = AlarmSystem:GetProcedure(name)
- if not proc then
- warn("Invalid procedure: " .. tostring(name))
- return "Invalid procedure: " .. tostring(name)
- end
- if not proc.IsActive then
- warn("Procedure already inactive: " .. proc.Name)
- return "Procedure already inactive: " .. proc.Name
- end
- if player ~= "Server" and proc.Name == "ClearHorizon" then
- warn("Unable to disable this protocol as it is a primary protocol")
- return "Unable to disable this protocol as it is a primary protocol"
- end
- if player ~= "Server" and not Permissions:CanUserAccess(player, proc.Permissions) then
- warn("Access denied for " .. player.Name)
- return "Access denied for " .. player.Name
- end
- if clear and proc.ClearOnDisable then
- AlarmSystem:ActivateProcedure("ClearHorizon", player)
- end
- proc.IsActive = false
- if proc.AnnouncementSound then proc.AnnouncementSound:Stop() end
- if proc.AlarmSettings and proc.AlarmSettings.BackgroundAmbience then
- proc.AlarmSettings.BackgroundAmbience:Stop()
- end
- coroutine.wrap(function()
- if proc.DisableServerFunction then
- proc.DisableServerFunction()
- end
- end)()
- return proc.Name .. " deactivated"
- end
- return AlarmSystem
Advertisement
Add Comment
Please, Sign In to add comment