fix: key binds not registering until resource restart

There were a number of people with issues regarding their key binds not getting registered until the resource was restarted. This appears to have been caused by QBus interfering with the `playerSpawned` event which the resource relied on to register the key binds. The exact qb resource in question is unknown presently.
This commit is contained in:
Dan
2021-08-30 20:16:34 +01:00
parent 3d003b1683
commit 1feb7ba599
2 changed files with 14 additions and 34 deletions

View File

@@ -41,7 +41,7 @@ local pairs = pairs
--[[---------------------------------------------------------------------------------- --[[----------------------------------------------------------------------------------
Key bind registering UI loading and key binds registering
----------------------------------------------------------------------------------]]-- ----------------------------------------------------------------------------------]]--
local function RegisterKeyBinds() local function RegisterKeyBinds()
if ( UTIL:IsResourceNameValid() ) then if ( UTIL:IsResourceNameValid() ) then
@@ -115,12 +115,6 @@ local function RegisterKeyBinds()
end end
end end
--[[----------------------------------------------------------------------------------
UI loading and key binds trigger
----------------------------------------------------------------------------------]]--
local spawned = false
local function LoadUISettings() local function LoadUISettings()
UTIL:Log( "Attempting to load saved UI settings data." ) UTIL:Log( "Attempting to load saved UI settings data." )
@@ -140,32 +134,6 @@ local function LoadUISettings()
end end
end end
-- Runs every time the player spawns, but the additional check means it only runs the first time
-- the player spawns
AddEventHandler( "playerSpawned", function()
if ( not spawned ) then
RegisterKeyBinds()
LoadUISettings()
spawned = true
end
end )
-- Loads the UI settings when the resource gets restarted, this way active users don't have the
-- default settings applied
AddEventHandler( "onResourceStart", function( resourceName )
if ( GetCurrentResourceName() == resourceName ) then
Citizen.CreateThread( function()
Citizen.Wait( 1000 )
RegisterKeyBinds()
LoadUISettings()
DecorSetBool( PlayerPedId(), "wk_wars2x_sync_remoteOpen", false )
end )
end
end )
--[[---------------------------------------------------------------------------------- --[[----------------------------------------------------------------------------------
Radar variables Radar variables
@@ -1819,6 +1787,18 @@ Citizen.CreateThread( function()
RADAR:CreateFastLimitConfig() RADAR:CreateFastLimitConfig()
end end
-- Register the key binds
RegisterKeyBinds()
-- Wait a short period of time
Citizen.Wait( 1000 )
-- Load the saved UI settings (if available)
LoadUISettings()
-- Set the player's remoteOpen decorator to false
DecorSetBool( PlayerPedId(), "wk_wars2x_sync_remoteOpen", false )
-- Update the operator menu positions -- Update the operator menu positions
RADAR:UpdateOptionIndexes( true ) RADAR:UpdateOptionIndexes( true )

View File

@@ -38,7 +38,7 @@ game "gta5"
name "Wraith ARS 2X" name "Wraith ARS 2X"
description "Police radar and plate reader system for FiveM" description "Police radar and plate reader system for FiveM"
author "WolfKnight" author "WolfKnight"
version "1.3.0" version "1.3.1"
-- Include the files -- Include the files
files { files {