Skip to content

Commit

Permalink
Merge pull request #6 from nwvh/main
Browse files Browse the repository at this point in the history
ESX Support, Config option for more jobs and Czech Translation
  • Loading branch information
BubbleDK authored Aug 24, 2023
2 parents 5b39fb3 + 94848b6 commit 532c994
Show file tree
Hide file tree
Showing 6 changed files with 656 additions and 542 deletions.
90 changes: 64 additions & 26 deletions client/main.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
local QBCore = exports['qb-core']:GetCoreObject()
local framework = string.lower(Config.Framework)

if framework == 'qb' then
local QBCore = exports['qb-core']:GetCoreObject()
else
ESX = exports["es_extended"]:getSharedObject()
end

local obj = nil
local firstTimeOpening = true
Expand All @@ -17,12 +23,10 @@ local function openMdt()
obj = nil
end

local object = lib.requestModel(`prop_cs_tablet`)

local object = RequestModel(`prop_cs_tablet`)
obj = CreateObject(object, GetEntityCoords(cache.ped), 1, 1, 1)
AttachEntityToEntity(obj, cache.ped, GetPedBoneIndex(cache.ped, 28422), 0.0, 0.0, 0.03, 0.0, 0.0, 0.0, 1, 1, 0, 1, 0, 1)


lib.requestAnimDict('amb@world_human_seat_wall_tablet@female@base')
TaskPlayAnim(cache.ped, "amb@world_human_seat_wall_tablet@female@base", "generic_radio_enter", 8.0, 2.0, -1, 50, 2.0, 0, 0, 0)

Expand All @@ -41,38 +45,70 @@ RegisterNetEvent('bub_mdt:client:openMDT', function()
openMdt()
end)

RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
local player = QBCore.Functions.GetPlayerData()
if framework == 'qb' then
RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
local player = QBCore.Functions.GetPlayerData()

if player.job.name == 'police' then
TriggerServerEvent('bub-mdt:server:removeActiveOfficer')
end
end)
if Config.Jobs[player.job.name] then
TriggerServerEvent('bub-mdt:server:removeActiveOfficer')
end
end)

RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
local player = QBCore.Functions.GetPlayerData()
RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
local player = QBCore.Functions.GetPlayerData()

if player.job.name == 'police' then
local uiLocales = {}
local locales = lib.getLocales()
if Config.Jobs[player.job.name] then
local uiLocales = {}
local locales = lib.getLocales()

for k, v in pairs(locales) do
if k:find('^ui_') then
uiLocales[k] = v
for k, v in pairs(locales) do
if k:find('^ui_') then
uiLocales[k] = v
end
end

local personalInformation = lib.callback.await('bub-mdt:server:getPersonalInformation', false)

SendNUIMessage({ action = 'init', data = { locale = uiLocales, personalInformation = personalInformation }})
TriggerServerEvent('bub-mdt:server:addActiveOfficer')
Wait(500)
fetchActiveOfficers()
end
end)
else
AddEventHandler("esx:onPlayerLogout", function()
local player = ESX.GetPlayerData()
if Config.Jobs[player.job.name] then
TriggerServerEvent('bub-mdt:server:removeActiveOfficer')
end
end)
AddEventHandler("esx:playerLoaded", function(playerData, isNew, skin)
local player = playerData

if Config.Jobs[player.job.name] then
local uiLocales = {}
local locales = lib.getLocales()

for k, v in pairs(locales) do
if k:find('^ui_') then
uiLocales[k] = v
end
end

local personalInformation = lib.callback.await('bub-mdt:server:getPersonalInformation', false)
local personalInformation = lib.callback.await('bub-mdt:server:getPersonalInformation', false)

SendNUIMessage({ action = 'init', data = { locale = uiLocales, personalInformation = personalInformation }})
TriggerServerEvent('bub-mdt:server:addActiveOfficer')
Wait(500)
fetchActiveOfficers()
end
end)
SendNUIMessage({ action = 'init', data = { locale = uiLocales, personalInformation = personalInformation }})
TriggerServerEvent('bub-mdt:server:addActiveOfficer')
Wait(500)
fetchActiveOfficers()
end
end)
end

RegisterCommand('restart', function()
TriggerEvent('QBCore:Client:OnPlayerLoaded')
if framework == 'qb' then
TriggerEvent('QBCore:Client:OnPlayerLoaded')
end

if obj ~= nil then
DeleteEntity(obj)
Expand All @@ -84,4 +120,6 @@ end, false)
RegisterNUICallback('exit', function(_, cb)
cb(1)
SetNuiFocus(false, false)
DeleteEntity(obj)
ClearPedTasks(PlayerPedId())
end)
8 changes: 8 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Config = {}

Config.Framework = 'esx' -- [esx/qb] Set your desired framework
Config.Jobs = { -- Jobs that have access to mdt
['police'] = true,
['sheriff'] = true,
['trooper'] = true,
}
3 changes: 3 additions & 0 deletions locales/cs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ui_logout": "Odhlásit se"
}
4 changes: 4 additions & 0 deletions server/framework/esx.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
local resourceName = 'es_extended'

if not GetResourceState(resourceName):find('start') then return end

22 changes: 19 additions & 3 deletions server/main.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
local QBCore = exports['qb-core']:GetCoreObject()
local framework = string.lower(Config.Framework)

if framework == 'qb' then
local QBCore = exports['qb-core']:GetCoreObject()
else
ESX = exports["es_extended"]:getSharedObject()
end

local officersCache = {}
local activeOfficersCache = {}
Expand Down Expand Up @@ -66,7 +72,12 @@ end)

RegisterNetEvent('bub-mdt:server:removeActiveOfficer', function()
local src = source
local Player = QBCore.Functions.GetPlayer(src)
local Player = nil
if framework == 'qb' then
Player = QBCore.Functions.GetPlayer(src)
else
Player = ESX.GetPlayerFromId(src)
end

if not Player then return end
local CID = Player.PlayerData.citizenid
Expand All @@ -76,7 +87,12 @@ end)

RegisterNetEvent('bub-mdt:server:addActiveOfficer', function()
local src = source
local Player = QBCore.Functions.GetPlayer(src)
local Player = nil
if framework == 'qb' then
Player = QBCore.Functions.GetPlayer(src)
else
Player = ESX.GetPlayerFromId(src)
end

if not Player then return end
local CID = Player.PlayerData.citizenid
Expand Down
Loading

0 comments on commit 532c994

Please sign in to comment.