-- @name Joystick Data -- @author Opti1337 JOYSTICK_INPUT_TYPE = {Axis = 1, Button = 2} local CONFIG = { Steer = { DeviceId = 0, InputId = 0, Type = JOYSTICK_INPUT_TYPE.Axis, Handler = function(value) return math.remap(value, 0, 65535, -1, 1) end }, Clutch = { DeviceId = 0, InputId = 7, Type = JOYSTICK_INPUT_TYPE.Axis, Handler = function(value) return math.remap(value, 0, 65535, 1, 0) end }, Throttle = { DeviceId = 0, InputId = 1, Type = JOYSTICK_INPUT_TYPE.Axis, Handler = function(value) return math.remap(value, 0, 65535, 1, 0) end }, Brake = { DeviceId = 0, InputId = 5, Type = JOYSTICK_INPUT_TYPE.Axis, Handler = function(value) return math.remap(value, 0, 65535, 1, 0) end }, Handbrake = { DeviceId = 0, InputId = 0, Type = JOYSTICK_INPUT_TYPE.Button, Handler = function(value) return math.remap(value, 0, 128, 0, 1) end }, GearUp = { DeviceId = 0, InputId = 4, Type = JOYSTICK_INPUT_TYPE.Button, Handler = function(value) return math.remap(value, 0, 128, 0, 1) end }, GearDown = { DeviceId = 0, InputId = 5, Type = JOYSTICK_INPUT_TYPE.Button, Handler = function(value) return math.remap(value, 0, 128, 0, 1) end }, Gear1 = { DeviceId = 0, InputId = 8, Type = JOYSTICK_INPUT_TYPE.Button, Handler = function(value) return math.remap(value, 0, 128, 0, 1) end }, Gear2 = { DeviceId = 0, InputId = 9, Type = JOYSTICK_INPUT_TYPE.Button, Handler = function(value) return math.remap(value, 0, 128, 0, 1) end }, Gear3 = { DeviceId = 0, InputId = 10, Type = JOYSTICK_INPUT_TYPE.Button, Handler = function(value) return math.remap(value, 0, 128, 0, 1) end }, Gear4 = { DeviceId = 0, InputId = 11, Type = JOYSTICK_INPUT_TYPE.Button, Handler = function(value) return math.remap(value, 0, 128, 0, 1) end }, Gear5 = { DeviceId = 0, InputId = 12, Type = JOYSTICK_INPUT_TYPE.Button, Handler = function(value) return math.remap(value, 0, 128, 0, 1) end }, Gear6 = { DeviceId = 0, InputId = 13, Type = JOYSTICK_INPUT_TYPE.Button, Handler = function(value) return math.remap(value, 0, 128, 0, 1) end }, GearR = { DeviceId = 0, InputId = 14, Type = JOYSTICK_INPUT_TYPE.Button, Handler = function(value) return math.remap(value, 0, 128, 0, 1) end }, } if CLIENT and player() == owner() then local data = {} local isDirty = false hook.add("tick", "_tick", function() for k, v in pairs(CONFIG) do local value = 0 if v.Type == JOYSTICK_INPUT_TYPE.Axis then value = joystick.getAxis(v.DeviceId, v.InputId) elseif v.Type == JOYSTICK_INPUT_TYPE.Button then value = joystick.getButton(v.DeviceId, v.InputId) end if v.Handler ~= nil and type(v.Handler) == "function" then value = v.Handler(value) or value end if not isDirty and data[k] ~= value then isDirty = true end data[k] = value end if isDirty then net.start("data") for k in pairs(CONFIG) do net.writeFloat(data[k]) end net.send({}, true) isDirty = false end end) elseif SERVER then local outputs = {} for _, v in pairs(table.getKeys(CONFIG)) do outputs[v] = "NORMAL" end wire.adjustPorts({}, outputs) net.receive("data", function() for k in pairs(CONFIG) do wire.ports[k] = net.readFloat() end end) end