UI settings get loaded when the resource is restarted

This commit is contained in:
Dan
2020-11-07 13:12:05 +00:00
parent 6266bd8ed4
commit 7bbfd8c27a
2 changed files with 31 additions and 17 deletions

View File

@@ -284,7 +284,7 @@ function READER:RunDisplayValidationCheck()
if ( ( ( PLY.veh == 0 or ( PLY.veh > 0 and not PLY.vehClassValid ) ) and self:GetDisplayState() and not self:GetDisplayHidden() ) or IsPauseMenuActive() and self:GetDisplayState() ) then
self:SetDisplayHidden( true )
SendNUIMessage( { _type = "setReaderDisplayState", state = false } )
elseif ( PLY.veh > 0 and PLY.vehClassValid and PLY.inDriverSeat and self:GetDisplayState() and self:GetDisplayHidden() ) then
elseif ( PLY:CanRunRadar() and self:GetDisplayState() and self:GetDisplayHidden() ) then
self:SetDisplayHidden( false )
SendNUIMessage( { _type = "setReaderDisplayState", state = true } )
end

View File

@@ -45,10 +45,7 @@ local pairs = pairs
----------------------------------------------------------------------------------]]--
local spawned = false
-- 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
local function LoadUISettings()
UTIL:Log( "Attempting to load saved UI settings data." )
-- Try and get the saved UI data
@@ -65,11 +62,28 @@ AddEventHandler( "playerSpawned", function()
UTIL:Log( "Could not find any saved UI settings data." )
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
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.Wait( 2000 )
LoadUISettings()
end
end )
--[[----------------------------------------------------------------------------------
Player info variables