50 lines
1.3 KiB
Lua
50 lines
1.3 KiB
Lua
local allItems = {}
|
|
|
|
local defaultTable = {
|
|
load_value_in = 0,
|
|
fuel_in = 100,
|
|
set_efficiency = 100,
|
|
set_fission_efficiency = 75,
|
|
set_max_power = 20000,
|
|
set_silent = 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]
|
|
|
|
if mem[connection.Name] == signalNum then
|
|
return
|
|
end
|
|
|
|
mem[connection.Name] = signalNum
|
|
|
|
local turbineoutput = (mem.load_value_in / mem.set_max_power) * mem.set_efficiency
|
|
local fissionrate = turbineoutput / (mem.fuel_in / mem.set_fission_efficiency)
|
|
|
|
if mem.set_silent == 1 then
|
|
if turbineoutput > 10 then
|
|
turbineoutput = 10
|
|
end
|
|
if fissionrate > 10 then
|
|
fissionrate = 10
|
|
end
|
|
end
|
|
|
|
this.SendSignal(turbineoutput, "turbine_output_out")
|
|
this.SendSignal(fissionrate, "fission_rate_out")
|
|
end
|
|
|
|
Hook.Add("signalreceived.reactorcontrollercomponent", "reactorcontrollercomponent.signalReceived", signalReceived)
|