Skip to content

Commit

Permalink
Merge pull request #25 from matsn0w/matsn0w/issue24
Browse files Browse the repository at this point in the history
fix: properly handle keybinds
  • Loading branch information
matsn0w authored Jan 12, 2022
2 parents 26e1341 + 4749dab commit 933a54d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Oh, and you might ask yourself where all the 'Els' or 'Miss Els' jokes come from
* Support for up to 4 different sirens per vehicle
* Optional light reflections around the vehicle
* Indicator controls
* Customizable key binds
* Customizable keybinds

*...and more!*

Expand Down
42 changes: 22 additions & 20 deletions resource/client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ local function HandleIndicators(vehicle)

local type = nil

if IsControlJustReleased(0, Config.KeyBinds['IndicatorHazard']) and IsUsingKeyboard(0) then type = 'hazard'
elseif IsControlJustReleased(0, Config.KeyBinds['IndicatorLeft']) and IsUsingKeyboard(0) then type = 'left'
elseif IsControlJustReleased(0, Config.KeyBinds['IndicatorRight']) and IsUsingKeyboard(0) then type = 'right' end
if IsDisabledControlJustReleased(0, Config.KeyBinds['IndicatorHazard']) and IsUsingKeyboard(0) then type = 'hazard'
elseif IsDisabledControlJustReleased(0, Config.KeyBinds['IndicatorLeft']) and IsUsingKeyboard(0) then type = 'left'
elseif IsDisabledControlJustReleased(0, Config.KeyBinds['IndicatorRight']) and IsUsingKeyboard(0) then type = 'right' end

if not type then return end

Expand Down Expand Up @@ -171,7 +171,7 @@ AddEventHandler('onClientResourceStart', function(name)

-- only run if player is in an ELS enabled vehicle and can control the sirens
if IsELSVehicle(vehicle) and CanControlSirens(vehicle) then

-- conflicting controls
local controls = {
{ 0, 58 }, -- INPUT_THROW_GRENADE
{ 0, 73 }, -- INPUT_VEH_DUCK
Expand All @@ -185,10 +185,12 @@ AddEventHandler('onClientResourceStart', function(name)

-- disable all conflicting controls
for _, control in ipairs(controls) do
-- do not disable if the control is in the key binds
if not TableHasValue(Config.KeyBinds, control[2]) then
DisableControlAction(control[1], control[2], true)
end
DisableControlAction(control[1], control[2], true)
end

-- disable all ELS keybinds
for _, control in pairs(Config.KeyBinds) do
DisableControlAction(0, control, true)
end

-- set vehicle state
Expand All @@ -204,23 +206,23 @@ AddEventHandler('onClientResourceStart', function(name)

if IsUsingKeyboard(0) then
-- light stages
if IsControlJustReleased(0, Config.KeyBinds['PrimaryLights']) then HandleLightStage(vehicle, 'primary')
elseif IsControlJustReleased(0, Config.KeyBinds['SecondaryLights']) then HandleLightStage(vehicle, 'secondary')
elseif IsControlJustReleased(0, Config.KeyBinds['MiscLights']) then HandleLightStage(vehicle, 'warning')
if IsDisabledControlJustReleased(0, Config.KeyBinds['PrimaryLights']) then HandleLightStage(vehicle, 'primary')
elseif IsDisabledControlJustReleased(0, Config.KeyBinds['SecondaryLights']) then HandleLightStage(vehicle, 'secondary')
elseif IsDisabledControlJustReleased(0, Config.KeyBinds['MiscLights']) then HandleLightStage(vehicle, 'warning')
end

-- siren toggles
if IsControlJustReleased(0, Config.KeyBinds['ActivateSiren']) then HandleSiren(vehicle)
elseif IsControlJustReleased(0, Config.KeyBinds['NextSiren']) then NextSiren(vehicle)
elseif IsControlJustReleased(0, Config.KeyBinds['Siren1']) then HandleSiren(vehicle, 1)
elseif IsControlJustReleased(0, Config.KeyBinds['Siren2']) then HandleSiren(vehicle, 2)
elseif IsControlJustReleased(0, Config.KeyBinds['Siren3']) then HandleSiren(vehicle, 3)
elseif IsControlJustReleased(0, Config.KeyBinds['Siren4']) then HandleSiren(vehicle, 4)
if IsDisabledControlJustReleased(0, Config.KeyBinds['ActivateSiren']) then HandleSiren(vehicle)
elseif IsDisabledControlJustReleased(0, Config.KeyBinds['NextSiren']) then NextSiren(vehicle)
elseif IsDisabledControlJustReleased(0, Config.KeyBinds['Siren1']) then HandleSiren(vehicle, 1)
elseif IsDisabledControlJustReleased(0, Config.KeyBinds['Siren2']) then HandleSiren(vehicle, 2)
elseif IsDisabledControlJustReleased(0, Config.KeyBinds['Siren3']) then HandleSiren(vehicle, 3)
elseif IsDisabledControlJustReleased(0, Config.KeyBinds['Siren4']) then HandleSiren(vehicle, 4)
end
else -- on controller
if IsControlJustReleased(1, 85 --[[ DPAD_LEFT ]]) then HandleLightStage(vehicle, 'primary')
elseif IsControlJustReleased(1, 170 --[[ B ]]) then NextSiren(vehicle)
elseif IsControlJustReleased(1, 173 --[[ DPAD_DOWN ]]) then HandleSiren(vehicle)
if IsDisabledControlJustReleased(1, 85 --[[ DPAD_LEFT ]]) then HandleLightStage(vehicle, 'primary')
elseif IsDisabledControlJustReleased(1, 170 --[[ B ]]) then NextSiren(vehicle)
elseif IsDisabledControlJustReleased(1, 173 --[[ DPAD_DOWN ]]) then HandleSiren(vehicle)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion resource/config.example.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Config.Beeps = false
-- B = activate next siren
Config.ControllerSupport = true

-- Sets key binds for various actions
-- Sets keybinds for various actions
-- See https://docs.fivem.net/docs/game-references/controls for a list of codes
Config.KeyBinds = {
PrimaryLights = 85, -- Q
Expand Down

0 comments on commit 933a54d

Please sign in to comment.