- Add setting to enable/disable exit delay countdown!
This commit is contained in:
Christopher Cookman 2024-08-16 21:56:51 -06:00
parent 37e62c514a
commit 684767fe86
Signed by: ChrisChrome
GPG key ID: A023A26E42C33A42
4 changed files with 59 additions and 57 deletions

View file

@ -30,6 +30,13 @@ local demoLoop = function()
repeat wait() until armState == 3
wait(5)
disarm()
wait(5)
script.Parent.Zones["2"].Sensors.Demo.Alarm.Value = true
wait(1)
script.Parent.Zones["2"].Sensors.Demo.Alarm.Value = false
repeat wait() until armState == 4
wait(5)
disarm()
end
end
task.spawn(demoLoop)

View file

@ -1,4 +1,4 @@
local defaultCodes = {"1234"}
local defaultCodes = require(script.DefaultCodes)
local dataStore = nil
local DataStoreService = game:GetService("DataStoreService")
@ -20,7 +20,7 @@ end
function setup(parentScript)
-- dont touch
local version = "v1.2.2"
local version = "v1.2.4"
-- codes object, will be swapped for data store later
codes = dataStore:GetAsync("codes")
@ -46,6 +46,8 @@ function setup(parentScript)
fires = {}
zones = {}
keypads = {}
countdown = nil
--[[
armState
0 is disarmed
@ -135,71 +137,44 @@ delay
3 slow pulse (entry/exit delay main)
4 fast pulse (end of exit/entry delay and trouble)
]]
function switchKeypadAudio(enabled)
for i,e in ipairs(script.KeypadAudio:GetChildren()) do
if e.Name ~= enabled then
e.Disabled = true
else
e.Enabled = true
end
end
end
function audioLoop()
while true do
wait()
if not power then curTone = 0 end
if curTone == 0 then -- Stop tone
for i, keypad in ipairs(keypads) do
stopAud(keypad.Display.hi)
stopAud(keypad.Display.lo)
end
switchKeypadAudio("off")
elseif curTone == 1 then -- Constant tone
for i, keypad in ipairs(keypads) do
playAud(keypad.Display.hi)
stopAud(keypad.Display.lo)
end
switchKeypadAudio("constant")
elseif curTone == 2 then -- Slow pulse tone
for i, keypad in ipairs(keypads) do
stopAud(keypad.Display.hi)
stopAud(keypad.Display.lo)
end
wait(0.5)
for i, keypad in ipairs(keypads) do
playAud(keypad.Display.hi)
end
wait(0.5)
switchKeypadAudio("slowpulse")
elseif curTone == 3 then -- Fast pulse tone
for i, keypad in ipairs(keypads) do
stopAud(keypad.Display.hi)
stopAud(keypad.Display.lo)
end
wait(0.065)
for i, keypad in ipairs(keypads) do
playAud(keypad.Display.hi)
end
wait(0.065)
switchKeypadAudio("fastpulse")
elseif curTone == 4 then -- HiLo tone alarm
for i, keypad in ipairs(keypads) do
playAud(keypad.Display.hi)
stopAud(keypad.Display.lo)
end
wait(0.5)
for i, keypad in ipairs(keypads) do
stopAud(keypad.Display.hi)
playAud(keypad.Display.lo)
end
wait(0.5)
switchKeypadAudio("hilo")
elseif curTone == 5 then -- Fire alarm tone
-- Make this do temporal 3
for i = 1, 3 do
for i, keypad in ipairs(keypads) do
playAud(keypad.Display.hi)
stopAud(keypad.Display.lo)
end
wait(.5)
for i, keypad in ipairs(keypads) do
stopAud(keypad.Display.hi)
stopAud(keypad.Display.lo)
end
wait(.5)
end
wait(1)
switchKeypadAudio("fire")
end
end
end
function alignText(leftText, rightText, totalWidth)
local leftLength = #leftText
local rightLength = #rightText
local spaceBetween = totalWidth - (leftLength + rightLength)
-- If the total length of both texts exceeds the totalWidth, return concatenated textif spaceBetween < 0thenreturn leftText .. rightText
return leftText .. string.rep(" ", spaceBetween) .. rightText
end
function displayLoop()
while true do
wait()
@ -238,7 +213,12 @@ delay
ux.setLEDs(keypads, "armed", true)
ux.setLEDs(keypads, "ready", false)
if delay == 1 then
ux.setDisplays(keypads, "ARMED ***AWAY***", "You may exit now")
if settings.showCountdown then
ln2 = alignText("May Exit Now", tostring(settings.exitDelay - countdown), 16)
else
ln2 = "You may exit now"
end
ux.setDisplays(keypads, "ARMED ***AWAY***", ln2)
elseif delay == 2 then
ux.setDisplays(keypads, "DISARM SYSTEM", "Or alarm occurs.")
else
@ -265,7 +245,12 @@ delay
ux.setLEDs(keypads, "armed", true)
ux.setLEDs(keypads, "ready", false)
if delay == 1 then
ux.setDisplays(keypads, "ARMED *MAXIMUM*", "You may exit now")
if settings.showCountdown then
ln2 = alignText("May Exit Now", tostring(settings.exitDelay - countdown), 16)
else
ln2 = "You may exit now"
end
ux.setDisplays(keypads, "ARMED *MAXIMUM*", ln2)
else
ux.setDisplays(keypads, "ARMED *MAXIMUM*", "***ALL SECURE***")
end
@ -448,10 +433,12 @@ delay
for i = 1, settings.exitDelay do
if armState ~= 1 then
delay = 0
countdown = 0
return
end
countdown = i
wait(1)
if i >= settings.exitDelay then delay = 0 end
if i >= settings.exitDelay then delay = 0 countdown = 0 end
end
end)
end
@ -469,13 +456,16 @@ delay
if armState ~= 2 then
changeTone(0)
delay = 0
countdown = 0
return
end
countdown = i
wait(1)
if i >= settings.exitDelay - 10 then changeTone(3) end
if i >= settings.exitDelay then
changeTone(0)
delay = 0
countdown = 0
end
end
end)
@ -494,13 +484,16 @@ delay
if armState ~= 6 then
changeTone(0)
delay = 0
countdown = 0
return
end
countdown = i
wait(1)
if i >= settings.exitDelay - 10 then changeTone(3) end
if i >= settings.exitDelay then
changeTone(0)
delay = 0
countdown = 0
end
end
end)
@ -518,10 +511,12 @@ delay
for i = 1, settings.exitDelay do
if armState ~= 5 then
delay = 0
countdown = 0
return
end
countdown = i
wait(1)
if i >= settings.exitDelay then delay = 0 end
if i >= settings.exitDelay then delay = 0 countdown = 0 end
end
end)
end