local C={}C.Version="\050\046\048\046\049"C.OutputPrefix="\082\101\100\111\110 \084\101\099\104 \070\105\114\101 \083\121\115\116\101\109 \086"..(C.Version.."\058")C.FireActive=nil function C.StdOut(G,U)local H=string.lower(G)if H=="\119\097\114\110"then warn(C.OutputPrefix..(" "..U))else print(C.OutputPrefix..(" "..U))end end function C.APICall(G,...)if C.Settings.EnableAPI then C.APIPoints.Server:Fire(G,...)C.APIPoints.Client:FireAllClients(G,...)elseif C.Settings.Deubg then C.StdOut("\119\097\114\110","\065\080\073 \105\115 \100\105\115\097\098\108\101\100 \105\103\110\111\114\105\110\103 \065\080\073 \099\097\108\108")end end local G=(script:WaitForChild("\070\105\114\101\080\097\114\116\105\099\108\101\115")):GetChildren()C.FirefightersActive=0 C.Fire=nil function C.IgnitePart(C)local U=Instance.new("\073\110\116\086\097\108\117\101")U.Value=50 U.Name="\070\105\114\101\083\105\122\101"U.Parent=C for G,U in pairs(G)do if U:IsA("\080\097\114\116\105\099\108\101\069\109\105\116\116\101\114")then local G=U:Clone()G.Parent=C G.Enabled=true G.Rate=((C.Size.X*C.Size.Y)*C.Size.Z)*.5 end end local H H=C.Touched:Connect(function(G)if string.lower(G.Name)=="\119\097\116\101\114"then G:Destroy()if U.Value>0 then U.Value=U.Value-1 else U:Destroy()for C,G in pairs(C:GetChildren())do if G:IsA("\080\097\114\116\105\099\108\101\069\109\105\116\116\101\114")then G:Destroy()end end H:Disconnect()end elseif G.Parent:FindFirstChild("\072\117\109\097\110\111\105\100")then if G.Parent.Humanoid:FindFirstChild("\066\117\110\107\101\114\071\101\097\114")and G.Parent.Humanoid:FindFirstChild("\083\067\066\065")then if not G.Parent.Humanoid.SCBA.Value and G.Parent.Humanoid.Health>10 then G.Parent.Humanoid.Health=G.Parent.Humanoid.Health-.5 end elseif G.Parent.Humanoid.Health>10 then G.Parent.Humanoid.Health=G.Parent.Humanoid.Health-.5 end end end)end function C.BuildingFire(G,U)if C.FirefightersActive>=C.Settings.MinFirefighters then if U=="\076\097\114\103\101"and C.FirefightersActive>=C.Settings.MinLarge then C.StdOut("\112\114\105\110\116","\083\116\097\114\116\105\110\103 \097 \108\097\114\103\101 \102\105\114\101\046")for G,U in pairs(G:GetDescendants())do if U:IsA("\066\097\115\101\080\097\114\116")and(U.Name~="\078\111\110\070\108\097\109\109\097\098\108\101"and U.Name~="\077\097\105\110\083\109\111\107\101")then C.IgnitePart(U)elseif U.Name=="\077\097\105\110\083\109\111\107\101"then local C=(script.FireParticles:FindFirstChild("\083\109\111\107\101")):Clone()C.Parent=U C.Enabled=true C.Rate=((U.Size.X*U.Size.Y)*U.Size.Z)*.5 end end C.Fire=G C.APICall("\070\105\114\101\083\116\097\114\116\101\100","\076\097\114\103\101",G)else C.StdOut("\112\114\105\110\116","\083\116\097\114\116\105\110\103 \097 \115\109\097\108\108 \102\105\114\101\046")local U={}for C,G in pairs(G:GetDescendants())do if G:IsA("\066\097\115\101\080\097\114\116")and(G.Name~="\078\111\110\070\108\097\109\109\097\098\108\101"and G.Name~="\077\097\105\110\083\109\111\107\101")then table.insert(U,G)end end local H=U[math.random(1,#U)]for G,U in pairs(G:GetDescendants())do if U:IsA("\066\097\115\101\080\097\114\116")and((U.Position-H.Position).magnitude<25 and(U.Name~="\078\111\110\070\108\097\109\109\097\098\108\101"and U.Name~="\077\097\105\110\083\109\111\107\101"))then C.IgnitePart(U)elseif U.Name=="\077\097\105\110\083\109\111\107\101"then local C=(script.FireParticles:FindFirstChild("\083\109\111\107\101")):Clone()C.Parent=U C.Enabled=true C.Rate=((U.Size.X*U.Size.Y)*U.Size.Z)*.25 end end C.Fire=G C.APICall("\070\105\114\101\083\116\097\114\116\101\100","\083\109\097\108\108",G)end end end function C.CheckBuildingFireStatus(C)local G=false for C,U in pairs(C:GetDescendants())do if U:FindFirstChild("\070\105\114\101")then G=true end end return G end function C.BrushFire(C,G) end local U=game:GetService("\082\117\110\083\101\114\118\105\099\101")local H C.Buildings={}function C.Kill()H:Disconnect()script:Destroy()end function C.Load(G)C.Settings=G if C.Settings.EnableAPI then C.APIPoints={Server=Instance.new("\066\105\110\100\097\098\108\101\069\118\101\110\116"),Client=Instance.new("\082\101\109\111\116\101\069\118\101\110\116")}C.APIPoints.Server.Parent=game.ServerStorage C.APIPoints.Server.Name="\082\084\070\083\083\101\114\118\101\114\065\080\073"C.APIPoints.Client.Parent=game.ReplicatedStorage C.APIPoints.Client.Name="\082\084\070\083\067\108\105\101\110\116\065\080\073"C.APICall("\083\116\097\114\116\117\112")end H=coroutine.create(function()while wait()do if C.FireActive~=nil then wait(C.Settings.WaitTimes.CheckFireTime)local G=C.CheckBuildingFireStatus(C.FireActive)if G then print("\070\105\114\101 \115\116\105\108\108 \097\099\116\105\118\101")else print("\070\105\114\101 \105\115 \110\111 \108\111\110\103\101\114 \097\099\116\105\118\101")for C,G in pairs(C.FireActive:GetDescendants())do if G.Name=="\077\097\105\110\083\109\111\107\101"then G.Smoke:Destroy()end end C.FireActive=nil C.StdOut("\112\114\105\110\116","\070\105\114\101 \104\097\115 \098\101\101\110 \101\120\116\105\110\103\117\105\115\104\101\100\046")C.APICall("\070\105\114\101\069\110\100\101\100")wait(math.random(C.Settings.WaitTimes.BetweenTimes.Min*C.Settings.WaitTimes.BetweenTimes.Multiplier,C.Settings.WaitTimes.BetweenTimes.Max*C.Settings.WaitTimes.BetweenTimes.Multiplier))end else C.FirefightersActive=0 for U,H in pairs(game.Teams:GetChildren())do if table.find(G.FireTeams,H.Name)then C.FirefightersActive=C.FirefightersActive+#H:GetPlayers()end end for G,U in pairs(G.BuildingLocations)do for G,U in pairs(U:GetChildren())do if U:IsA("\077\111\100\101\108")and not table.find(C.Buildings,U)then table.insert(C.Buildings,U)end end end if C.FirefightersActive>=G.MinFirefighters then if next(C.Buildings)~=nil then local G=C.Buildings[math.random(1,#C.Buildings)]local U=math.random(1,100)if U==1 then U="\076\097\114\103\101"else U="\083\109\097\108\108"end C.BuildingFire(G,U)C.FireActive=G wait(C.Settings.WaitTimes.ResourceSaver)else error(C.OutputPrefix.." \078\111 \098\117\105\108\100\105\110\103\115 \100\101\116\101\099\116\101\100\046")end end end end end)coroutine.resume(H)end function C.Start(G,U)if G and(G:IsA("\077\111\100\117\108\101\083\099\114\105\112\116")and(type(U)=="\116\097\098\108\101"and U.Version==C.Version))then C.Load(U)return true else C.StdOut("\119\097\114\110","\083\101\116\116\105\110\103\115 \097\114\101 \111\117\116\100\097\116\101\100 \111\114 \105\110\118\097\108\105\100\046 \076\111\097\100\105\110\103 \119\105\116\104 \100\101\102\097\117\108\116\046")C.Load(require(script.default_settings))return true end return false end return C
																																																					--[[
  _____               _                     _______                 _     
 |  __ \             | |                   |__   __|               | |    
 | |__) |   ___    __| |   ___    _ __        | |      ___    ___  | |__  
 |  _  /   / _ \  / _  |  / _ \  |  _ \       | |     / _ \  / __| |  _ \ 
 | | \ \  |  __/ | (_| | | (_) | | | | |      | |    |  __/ | (__  | | | |
 |_|  \_\  \___|  \__,_|  \___/  |_| |_|      |_|     \___|  \___| |_| |_|
                                                           Fire System 2.0
                                                 MainModule
																																																						]]

-- DO NOT EDIT BELOW UNLESS YOU KNOW WHAT YOU ARE DOING --
-- CHANGING THIS SCRIPT MAY BREAK THE SYSTEM DO NOT CHANGE IT --
-- THIS SCRIPT IS COMPLETLY DIFFRENT AND REWRITTEN FROM V1.0 --
-- FIND THE GITHUB SOURCE AT https://github.com/Redon-Tech/Redon-Tech-Fire-System --

--\ SETUP /--
local MainModule = {}
MainModule.Version = "2.0.1" -- Will remain at x.x.1 until the first testing starts
MainModule.OutputPrefix = "Redon Tech Fire System V".. MainModule.Version ..":"
MainModule.FireActive = nil
-- MainModule.Settings = script:WaitForChild("DefaultSettings") -- Default settings load first then will be replaced

function MainModule.StdOut(TypeOriginal, Message) -- Handles warnings/prints errors are handled in scripts to help us debug issues
    -- Done like this to allow you to change how warnings/prints are handled
    local Type = string.lower(TypeOriginal)
    if Type == "warn" then
        warn(MainModule.OutputPrefix .." ".. Message)
    else
        print(MainModule.OutputPrefix .." ".. Message)
    end
end

--\ MAIN FUNCTIONS /--
function MainModule.APICall(Call, ...)
    if MainModule.Settings.EnableAPI then
        MainModule.APIPoints.Server:Fire(Call, ...)
        MainModule.APIPoints.Client:FireAllClients(Call, ...)
    elseif MainModule.Settings.Deubg then
        MainModule.StdOut("warn", "API is disabled ignoring API call")
    end
end

local FireParticles = script:WaitForChild("FireParticles"):GetChildren()
MainModule.FirefightersActive = 0
MainModule.Fire = nil

function MainModule.IgnitePart(Part)
    local FireSize = Instance.new("IntValue")
    FireSize.Value = 50 -- Change this to change how long putting out fires takes
    FireSize.Name = "FireSize"
    FireSize.Parent = Part
    for i,v in pairs(FireParticles) do
        if v:IsA("ParticleEmitter") then
            local Particle = v:Clone()
            Particle.Parent = Part
            Particle.Enabled = true
            Particle.Rate = Part.Size.X * Part.Size.Y * Part.Size.Z * 0.5 -- Change 0.5 to adjust rate
        end
    end
    local TouchFunction
    TouchFunction = Part.Touched:Connect(function(TouchPart)
        if string.lower(TouchPart.Name) == "water" then
            TouchPart:Destroy() -- Comment out of you want water to stay after hiting
            if FireSize.Value > 0 then
                FireSize.Value = FireSize.Value - 1 -- Change 1 to the rate that you want the fire to die
                -- Add any effects you want to happen to the fire
            else
                FireSize:Destroy()
                for i,v in pairs(Part:GetChildren()) do
					if v:IsA("ParticleEmitter") then
						v:Destroy()
					end
				end
                TouchFunction:Disconnect() -- Kill this function to reduce lag
            end
        elseif TouchPart.Parent:FindFirstChild("Humanoid") then
            if TouchPart.Parent.Humanoid:FindFirstChild("BunkerGear") and TouchPart.Parent.Humanoid:FindFirstChild("SCBA") then
                if not TouchPart.Parent.Humanoid.SCBA.Value and TouchPart.Parent.Humanoid.Health > 10 then -- Change 10 to whatever value remove it all together to kill them
                    TouchPart.Parent.Humanoid.Health = TouchPart.Parent.Humanoid.Health - 0.5
                end
            elseif TouchPart.Parent.Humanoid.Health > 10 then -- Change 10 to whatever value remove it all together to kill them
                TouchPart.Parent.Humanoid.Health = TouchPart.Parent.Humanoid.Health - 0.5
            end
        end
    end)
end

function MainModule.BuildingFire(Building, Size) -- Future plan: Replace with more dynamic fires
    if MainModule.FirefightersActive >= MainModule.Settings.MinFirefighters then
        if Size == "Large" and MainModule.FirefightersActive >= MainModule.Settings.MinLarge then
            MainModule.StdOut("print", "Starting a large fire.")
            for i,v in pairs(Building:GetDescendants()) do
                if v:IsA("BasePart") and v.Name ~= "NonFlammable" and v.Name ~= "MainSmoke" then
                    MainModule.IgnitePart(v)
                elseif v.Name == "MainSmoke" then
                    local Smoke = script.FireParticles:FindFirstChild("Smoke"):Clone()
                    Smoke.Parent = v
                    Smoke.Enabled = true
                    Smoke.Rate = v.Size.X * v.Size.Y * v.Size.Z * 0.5 -- Change 0.5 to adjust rate
                end
            end
            MainModule.Fire = Building
            MainModule.APICall("FireStarted", "Large", Building)
        else
            MainModule.StdOut("print", "Starting a small fire.")
            local Parts = {}
            for i,v in pairs(Building:GetDescendants()) do
                if v:IsA("BasePart") and v.Name ~= "NonFlammable" and v.Name ~= "MainSmoke" then
                    table.insert(Parts, v)
                end
            end
            local Main = Parts[math.random(1,#Parts)]

            for i,v in pairs(Building:GetDescendants()) do
                if v:IsA("BasePart") and (v.Position - Main.Position).magnitude < 25 and v.Name ~= "NonFlammable" and v.Name ~= "MainSmoke" then
                    MainModule.IgnitePart(v)
                elseif v.Name == "MainSmoke" then
                    local Smoke = script.FireParticles:FindFirstChild("Smoke"):Clone()
                    Smoke.Parent = v
                    Smoke.Enabled = true
                    Smoke.Rate = v.Size.X * v.Size.Y * v.Size.Z * 0.25 -- Change 0.5 to adjust rate
                end
            end
            MainModule.Fire = Building
            MainModule.APICall("FireStarted", "Small", Building)
        end
    end
end

function MainModule.CheckBuildingFireStatus(Building)
    local fire = false
    for i,v in pairs(Building:GetDescendants()) do
        if v:FindFirstChild("Fire") then
            fire = true
        end
    end
    
    return fire
end

function MainModule.BrushFire(Area, Size) -- Coming Soon
end

--\ LOAD/KILL /--
local RunService = game:GetService("RunService")
local func
MainModule.Buildings = {}

function MainModule.Kill()
    func:Disconnect() -- I honestly have no idea if this works because there is no need to test it
    script:Destroy()
end

function MainModule.Load(Settings)
    MainModule.Settings = Settings

    if MainModule.Settings.EnableAPI then
        MainModule.APIPoints = {
            Server = Instance.new("BindableEvent"),
            Client = Instance.new("RemoteEvent"),
        }
        MainModule.APIPoints.Server.Parent = game.ServerStorage
        MainModule.APIPoints.Server.Name = "RTFSServerAPI"
        MainModule.APIPoints.Client.Parent = game.ReplicatedStorage
        MainModule.APIPoints.Client.Name = "RTFSClientAPI"

        MainModule.APICall("Startup")
    end

    func = coroutine.create(function() while wait() do
        if MainModule.FireActive ~= nil then
            wait(MainModule.Settings.WaitTimes.CheckFireTime) -- Run the check every 10 seconds for lag reasons
            local FireStatus = MainModule.CheckBuildingFireStatus(MainModule.FireActive)
            if FireStatus then
                print("Fire still active")
            else
                print("Fire is no longer active")
                for i,v in pairs(MainModule.FireActive:GetDescendants()) do
                    if v.Name == "MainSmoke" then
                        v.Smoke:Destroy()
                    end
                end

                MainModule.FireActive = nil
                MainModule.StdOut("print", "Fire has been extinguished.")
                MainModule.APICall("FireEnded")
                wait(math.random(MainModule.Settings.WaitTimes.BetweenTimes.Min*MainModule.Settings.WaitTimes.BetweenTimes.Multiplier, MainModule.Settings.WaitTimes.BetweenTimes.Max*MainModule.Settings.WaitTimes.BetweenTimes.Multiplier))
            end
        else
            MainModule.FirefightersActive = 0
            for i,v in pairs(game.Teams:GetChildren()) do
                if table.find(Settings.FireTeams, v.Name) then
                    MainModule.FirefightersActive = MainModule.FirefightersActive + #v:GetPlayers()
                end
            end
            for i,v in pairs(Settings.BuildingLocations) do -- Could be betterr but once again I am lazy and making this 100% for free
                for ind,va in pairs(v:GetChildren()) do
                    if va:IsA("Model") and not table.find(MainModule.Buildings, va) then
                        table.insert(MainModule.Buildings, va)
                    end
                end
            end

            if MainModule.FirefightersActive >= Settings.MinFirefighters then
                if next(MainModule.Buildings) ~= nil then
                    local Building = MainModule.Buildings[math.random(1, #MainModule.Buildings)]
                    local Size = math.random(1,100) -- Change 100 to change the chances of large fires
                    if Size == 1 then Size = "Large" else Size = "Small" end
                    MainModule.BuildingFire(Building, Size)
                    MainModule.FireActive = Building
                    wait(MainModule.Settings.WaitTimes.ResourceSaver) -- Change to save resources
                else
                    error(MainModule.OutputPrefix .." No buildings detected.")
                end
            end
        end
    end end)

    coroutine.resume(func)
end

function MainModule.Start(Settings, RequiredSettings)
    if Settings and Settings:IsA("ModuleScript") and type(RequiredSettings) == "table" and RequiredSettings.Version == MainModule.Version then
        MainModule.Load(RequiredSettings)

        return true
    else
        MainModule.StdOut("warn", "Settings are outdated or invalid. Loading with default.")
        MainModule.Load(require(script.default_settings))

        return true
    end

    return false
end

return MainModule

-- Manually put out fires. USE THE SERVER CONSOLE
-- for i,v in pairs(workspace:GetDescendants()) do if (v:IsA("ParticleEmitter") or v:IsA("IntValue")) and v.Parent.Name ~= "MainSmoke" then v:Destroy() end end