This repository has been archived on 2025-07-31. You can view files and clone it, but cannot push or open issues or pull requests.
Files
barotrauma-custom-components/Lua/activeflipflopcomponent.lua

33 lines
945 B
Lua

local allItems = {}
Hook.Add("item.created", "activeflipflopcomponent.init", function(item)
if item.Prefab.Identifier == "activeflipflopcomponent" then
allItems[item] = true
end
end)
local signalReceived = function(signal, connection)
local this = connection.Item
local mem = this.Components[2]
if signal.value == "" then return end
local input = tonumber(signal.value) or 1
if input == 1 then
if mem.value == "0" then mem.value = "1" else mem.value = "0" end
elseif input == 0 then
mem.value = "0"
elseif input == -1 then
mem.value = "1"
end
end
local think = function()
for component, _ in pairs(allItems) do
component.SendSignal(component.Components[2].value, "state_out")
end
end
Hook.Add("think", "activeflipflopcomponent.think", think)
Hook.Add("signalreceived.activeflipflopcomponent", "activeflipflopcomponent.signalReceived", signalReceived)