Skip to content

Commit

Permalink
🚨 [v1.1.5] Mejor gestión datos job / lado cliente
Browse files Browse the repository at this point in the history
  • Loading branch information
imkuroneko authored May 18, 2024
1 parent dd81fdf commit d76218c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
31 changes: 20 additions & 11 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local QBCore = exports['qb-core']:GetCoreObject()
lib.locale()
local defconMenu = {}
PlayerLoaded = false
PlayerJob = {}

-- ===== Armar estructura del menú
defconMenu = {
Expand Down Expand Up @@ -40,17 +41,15 @@ lib.registerContext(defconMenu)
-- ===== Armar estructura del menú de alertas
RegisterNetEvent('neko_alertas_defcon:client:open_menu')
AddEventHandler('neko_alertas_defcon:client:open_menu', function()
QBCore.Functions.GetPlayerData(function(PlayerData)
if PlayerData.job.type ~= 'leo' then
lib.notify({ description = locale('player_not_police') , type = 'error' })
if PlayerJob.type ~= 'leo' then
lib.notify({ description = locale('player_not_police') , type = 'error' })
else
if not PlayerJob.onduty then
lib.notify({ description = locale('player_not_duty') , type = 'error' })
else
if not PlayerData.job.onduty then
lib.notify({ description = locale('player_not_duty') , type = 'error' })
else
lib.showContext(defconMenu.id)
end
lib.showContext(defconMenu.id)
end
end)
end
end)

-- ===== Enviar el evento de estado al cliente de los jugadores
Expand All @@ -66,14 +65,24 @@ end)


RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
PlayerLoaded = true
QBCore.Functions.GetPlayerData(function(PlayerData)
PlayerJob = PlayerData.job
PlayerLoaded = true
end)
end)

RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
PlayerLoaded = false
end)

RegisterNetEvent('QBCore:Client:OnJobUpdate', function(JobInfo)
PlayerJob = JobInfo
end)

AddEventHandler('onResourceStart', function(resourceName)
if GetCurrentResourceName() ~= resourceName then return end
PlayerLoaded = true
QBCore.Functions.GetPlayerData(function(PlayerData)
PlayerJob = PlayerData.job
PlayerLoaded = true
end)
end)
2 changes: 1 addition & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ lua54 'yes'
description 'Sistemas de alertas (DEFCON) para la policía'
author 'KuroNeko'
-- ===========================================================
version '1.1.4'
version '1.1.5'

-- ===========================================================
shared_scripts { '@ox_lib/init.lua' }
Expand Down
4 changes: 2 additions & 2 deletions server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ DefconCurrentStatus = nil
-- ===== Registrar comando
lib.addCommand(Config.Command, { help = locale('command_help'), params = {} }, function(source, args)
local Player = QBCore.Functions.GetPlayer(source)

if Player and Player.PlayerData.job.type == 'leo' then
if not Player then return end -- no existe entonces se ignora por defecto (fake o deslogueado)
if Player.PlayerData.job.type == 'leo' then
if Player.PlayerData.job.onduty then
TriggerClientEvent('neko_alertas_defcon:client:open_menu', source)
else
Expand Down

0 comments on commit d76218c

Please sign in to comment.