FlipFlop, Counter, Reactor Controller Components
This commit is contained in:
44
Lua/reactorcontrollercomponent.lua
Normal file
44
Lua/reactorcontrollercomponent.lua
Normal file
@@ -0,0 +1,44 @@
|
||||
local allItems = {}
|
||||
|
||||
local defaultTable = {
|
||||
load_value_in = 0,
|
||||
fuel_in = 100,
|
||||
efficiency_in = 100,
|
||||
fission_efficiency_in = 75,
|
||||
max_power_in = 20000,
|
||||
silent_in = 0
|
||||
}
|
||||
|
||||
Hook.Add("item.created", "reactorcontrollercomponent.init", function(item)
|
||||
if item.Prefab.Identifier == "reactorcontrollercomponent" then
|
||||
allItems[item] = {}
|
||||
for k, v in pairs(defaultTable) do
|
||||
allItems[item][k] = v
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
local signalReceived = function(signal, connection)
|
||||
local this = connection.Item
|
||||
local mem = allItems[this]
|
||||
|
||||
local signalNum = tonumber(signal.value) or defaultTable[connection.Name]
|
||||
mem[connection.Name] = signalNum
|
||||
|
||||
local turbineoutput = (mem.load_value_in / mem.max_power_in) * mem.efficiency_in
|
||||
local fissionrate = turbineoutput / (mem.fuel_in / mem.fission_efficiency_in)
|
||||
|
||||
if mem.silent_in == 1 then
|
||||
if turbineoutput > 10 then
|
||||
turbineoutput = 10
|
||||
end
|
||||
if fissionrate > 10 then
|
||||
fissionrate = 10
|
||||
end
|
||||
end
|
||||
|
||||
this.SendSignal(tostring(turbineoutput), "turbine_output_out")
|
||||
this.SendSignal(tostring(fissionrate), "fission_rate_out")
|
||||
end
|
||||
|
||||
Hook.Add("signalreceived.reactorcontrollercomponent", "reactorcontrollercomponent.signalReceived", signalReceived)
|
Reference in New Issue
Block a user