mirror of
https://github.com/Michatec/wk_wars2x.git
synced 2026-04-01 08:26:27 +02:00
UI settings get loaded when the resource is restarted
This commit is contained in:
@@ -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
|
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 )
|
self:SetDisplayHidden( true )
|
||||||
SendNUIMessage( { _type = "setReaderDisplayState", state = false } )
|
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 )
|
self:SetDisplayHidden( false )
|
||||||
SendNUIMessage( { _type = "setReaderDisplayState", state = true } )
|
SendNUIMessage( { _type = "setReaderDisplayState", state = true } )
|
||||||
end
|
end
|
||||||
|
|||||||
46
cl_radar.lua
46
cl_radar.lua
@@ -45,31 +45,45 @@ local pairs = pairs
|
|||||||
----------------------------------------------------------------------------------]]--
|
----------------------------------------------------------------------------------]]--
|
||||||
local spawned = false
|
local spawned = false
|
||||||
|
|
||||||
|
local function LoadUISettings()
|
||||||
|
UTIL:Log( "Attempting to load saved UI settings data." )
|
||||||
|
|
||||||
|
-- Try and get the saved UI data
|
||||||
|
local uiData = GetResourceKvpString( "wk_wars2x_ui_data" )
|
||||||
|
|
||||||
|
-- If the data exists, then we send it off!
|
||||||
|
if ( uiData ~= nil ) then
|
||||||
|
SendNUIMessage( { _type = "loadUiSettings", data = json.decode( uiData ) } )
|
||||||
|
|
||||||
|
UTIL:Log( "Saved UI settings data loaded!" )
|
||||||
|
-- If the data doesn't exist, then we send the defaults
|
||||||
|
else
|
||||||
|
SendNUIMessage( { _type = "setUiDefaults", data = CONFIG.uiDefaults } )
|
||||||
|
|
||||||
|
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
|
-- Runs every time the player spawns, but the additional check means it only runs the first time
|
||||||
-- the player spawns
|
-- the player spawns
|
||||||
AddEventHandler( "playerSpawned", function()
|
AddEventHandler( "playerSpawned", function()
|
||||||
if ( not spawned ) then
|
if ( not spawned ) then
|
||||||
UTIL:Log( "Attempting to load saved UI settings data." )
|
LoadUISettings()
|
||||||
|
|
||||||
-- Try and get the saved UI data
|
|
||||||
local uiData = GetResourceKvpString( "wk_wars2x_ui_data" )
|
|
||||||
|
|
||||||
-- If the data exists, then we send it off!
|
|
||||||
if ( uiData ~= nil ) then
|
|
||||||
SendNUIMessage( { _type = "loadUiSettings", data = json.decode( uiData ) } )
|
|
||||||
|
|
||||||
UTIL:Log( "Saved UI settings data loaded!" )
|
|
||||||
-- If the data doesn't exist, then we send the defaults
|
|
||||||
else
|
|
||||||
SendNUIMessage( { _type = "setUiDefaults", data = CONFIG.uiDefaults } )
|
|
||||||
|
|
||||||
UTIL:Log( "Could not find any saved UI settings data." )
|
|
||||||
end
|
|
||||||
|
|
||||||
spawned = true
|
spawned = true
|
||||||
end
|
end
|
||||||
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
|
Player info variables
|
||||||
|
|||||||
Reference in New Issue
Block a user