local allItems = {} local defaultTable = { velocity_x_in = 0, current_velocity_x_in = 0, set_trm_target = 20, set_trm_aggression = 600, set_mode = 1, set_silent = 0, acceleration = 0, } Hook.Add("item.created", "enginecontrollercomponent.init", function(item) if item.Prefab.Identifier == "enginecontrollercomponent" 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 connection.Name == "current_velocity_x_in" then mem.acceleration = (signalNum - mem.current_velocity_x_in) mem.current_velocity_x_in = signalNum else mem[connection.Name] = signalNum end -- Skip signals for optimization if connection.Name ~= "velocity_x_in" then return end local main_force_out local boost_force_out if mem.set_mode == 1 then main_force_out = mem.velocity_x_in boost_force_out = 0 elseif mem.set_mode == 2 then main_force_out = mem.velocity_x_in boost_force_out = mem.velocity_x_in elseif mem.set_mode == 0 then local absolute_current_velocity = math.abs(mem.current_velocity_x_in) if mem.set_trm_target -0.25 < absolute_current_velocity and mem.velocity_x_in * mem.current_velocity_x_in > 0 then local target_acceleration = - (absolute_current_velocity * mem.set_trm_aggression) + (mem.set_trm_target * mem.set_trm_aggression) if math.abs(mem.velocity_x_in) > math.abs(target_acceleration) then if mem.current_velocity_x_in > 0 then main_force_out = target_acceleration else main_force_out = -target_acceleration end else main_force_out = mem.velocity_x_in end else main_force_out = mem.velocity_x_in end boost_force_out = 0 end if mem.set_silent == 1 then main_force_out = main_force_out * 0.2 boost_force_out = boost_force_out * 0.2 end this.SendSignal(main_force_out, "main_force_out") this.SendSignal(boost_force_out, "boost_force_out") end Hook.Add("signalreceived.enginecontrollercomponent", "enginecontrollercomponent.signalReceived", signalReceived)