diff --git a/[esx]/es_extended/client/functions.lua b/[esx]/es_extended/client/functions.lua index 11e90319..3ba77831 100644 --- a/[esx]/es_extended/client/functions.lua +++ b/[esx]/es_extended/client/functions.lua @@ -490,70 +490,33 @@ function ESX.Game.DeleteObject(object) end function ESX.Game.SpawnVehicle(vehicle, coords, heading, cb, networked) - local model = (type(vehicle) == 'number' and vehicle or joaat(vehicle)) + local model = type(vehicle) == 'number' and vehicle or joaat(vehicle) local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z) networked = networked == nil and true or networked - if networked then - local isAutomobile = IsThisModelACar(model) - if isAutomobile ~= false then isAutomobile = true end - ESX.TriggerServerCallback('esx:Onesync:SpawnVehicle',function(NetID) - if NetID then - local Tries = 0 - SetNetworkIdCanMigrate(NetID, true) - local vehicle = NetworkGetEntityFromNetworkId(NetID) - while not DoesEntityExist(vehicle) do - Wait(0) - vehicle = NetworkGetEntityFromNetworkId(NetID) - Tries += 1 - if Tries > 250 then - break - end - end - Tries = 0 - NetworkRequestControlOfEntity(vehicle) - while not NetworkHasControlOfEntity(vehicle) do - Wait(0) - Tries += 1 - if Tries > 250 then - break - end - end - SetEntityAsMissionEntity(vehicle, true, true) - SetVehicleHasBeenOwnedByPlayer(vehicle, true) - SetVehicleNeedsToBeHotwired(vehicle, false) - SetModelAsNoLongerNeeded(model) - SetVehRadioStation(vehicle, 'OFF') - if cb then - cb(vehicle) - end - end - end, model, vector, heading, isAutomobile) - else - CreateThread(function() - ESX.Streaming.RequestModel(model) + CreateThread(function() + ESX.Streaming.RequestModel(model) - local vehicle = CreateVehicle(model, vector.xyz, heading, networked, false) + local vehicle = CreateVehicle(model, vector.xyz, heading, networked, true) - if networked then - local id = NetworkGetNetworkIdFromEntity(vehicle) - SetNetworkIdCanMigrate(id, true) - SetEntityAsMissionEntity(vehicle, true, false) - end - SetVehicleHasBeenOwnedByPlayer(vehicle, true) - SetVehicleNeedsToBeHotwired(vehicle, false) - SetModelAsNoLongerNeeded(model) - SetVehRadioStation(vehicle, 'OFF') + if networked then + local id = NetworkGetNetworkIdFromEntity(vehicle) + SetNetworkIdCanMigrate(id, true) + SetEntityAsMissionEntity(vehicle, true, true) + end + SetVehicleHasBeenOwnedByPlayer(vehicle, true) + SetVehicleNeedsToBeHotwired(vehicle, false) + SetModelAsNoLongerNeeded(model) + SetVehRadioStation(vehicle, 'OFF') - RequestCollisionAtCoord(vector.xyz) - while not HasCollisionLoadedAroundEntity(vehicle) do - Wait(0) - end + RequestCollisionAtCoord(vector.xyz) + while not HasCollisionLoadedAroundEntity(vehicle) do + Wait(0) + end - if cb then - cb(vehicle) - end - end) - end + if cb then + cb(vehicle) + end + end) end function ESX.Game.SpawnLocalVehicle(vehicle, coords, heading, cb) diff --git a/[esx]/es_extended/client/main.lua b/[esx]/es_extended/client/main.lua index 72ad617d..d9338792 100644 --- a/[esx]/es_extended/client/main.lua +++ b/[esx]/es_extended/client/main.lua @@ -193,6 +193,18 @@ AddEventHandler('esx:restoreLoadout', function() end end) +AddStateBagChangeHandler('VehicleProperties', nil, function(bagName, key, value) + if value then + Wait(0) + local NetId = tonumber(bagName:gsub('entity:', ''), 10) + local Vehicle = NetworkGetEntityFromNetworkId(NetId) + + if NetworkGetEntityOwner(Vehicle) == PlayerId() then + ESX.Game.SetVehicleProperties(Vehicle, value) + end + end +end) + RegisterNetEvent('esx:setAccountMoney') AddEventHandler('esx:setAccountMoney', function(account) for i=1, #(ESX.PlayerData.accounts) do diff --git a/[esx]/es_extended/server/functions.lua b/[esx]/es_extended/server/functions.lua index a9df8d1b..33111355 100644 --- a/[esx]/es_extended/server/functions.lua +++ b/[esx]/es_extended/server/functions.lua @@ -253,6 +253,10 @@ function ESX.GetPlayerFromIdentifier(identifier) end function ESX.GetIdentifier(playerId) + local fxDk = GetConvarInt('sv_fxdkMode', 0) + if fxDk == 1 then + return "ESX-DEBUG-LICENCE" + end for k, v in ipairs(GetPlayerIdentifiers(playerId)) do if string.match(v, 'license:') then local identifier = string.gsub(v, 'license:', '') diff --git a/[esx]/es_extended/server/onesync.lua b/[esx]/es_extended/server/onesync.lua index 0c1005db..039c721f 100644 --- a/[esx]/es_extended/server/onesync.lua +++ b/[esx]/es_extended/server/onesync.lua @@ -59,18 +59,22 @@ end ---@param model number|string ---@param coords vector3|table ---@param heading number +---@param autoMobile boolean +---@param Properties table ---@param cb function -function ESX.OneSync.SpawnVehicle(model, coords, heading, autoMobile, cb) - if type(model) == 'string' then model = joaat(model) end - local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z) - if type(autoMobile) ~= 'boolean' then - return - end - CreateThread(function() +function ESX.OneSync.SpawnVehicle(model, coords, heading, autoMobile, Properties, cb) + model = type(model) == 'string' and joaat(model) or model + Properties = Properties or {} + local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z) + if type(autoMobile) ~= 'boolean' then + return + end + CreateThread(function() local Entity = autoMobile and Citizen.InvokeNative(`CREATE_AUTOMOBILE`, model, coords.x, coords.y, coords.z, heading) or CreateVehicle(model, coords, heading, true, true) while not DoesEntityExist(Entity) do Wait(0) end + Entity(Entity).state:set('VehicleProperties', Properties, true) local netID = NetworkGetNetworkIdFromEntity(Entity) cb(netID) end) @@ -197,16 +201,6 @@ function ESX.OneSync.GetClosestVehicle(coords, modelFilter) return getClosestEntity(GetAllVehicles(), coords, modelFilter) end -ESX.RegisterServerCallback("esx:Onesync:SpawnVehicle", function(source, cb, model, coords, heading, autoMobile) - ESX.OneSync.SpawnVehicle(model, coords, heading, autoMobile, cb) -end) - ESX.RegisterServerCallback("esx:Onesync:SpawnObject", function(source, cb, model, coords, heading) ESX.OneSync.SpawnObject(model, coords, heading, cb) end) - --- for k,v in pairs(ESX.OneSync) do --- ESX.RegisterServerCallback("esx:Onesync:"..k, function(source, cb, ...) --- cb(v(...)) --- end) --- end \ No newline at end of file diff --git a/[esx_addons]/esx_joblisting/README.md b/[esx_addons]/esx_joblisting/README.md index 97ad643b..a8e4cfd5 100644 --- a/[esx_addons]/esx_joblisting/README.md +++ b/[esx_addons]/esx_joblisting/README.md @@ -6,7 +6,7 @@ This Simple resource lets you finally contribute to Society and make a differenc esx_joblisting - virtual Job Center! -Copyright (C) 2015-2022 Jérémie N'gadi +Copyright (C) 2015-2022 Jérémie N'gadi, ESX-Framework This program Is free software: you can redistribute it And/Or modify it under the terms Of the GNU General Public License As published by the Free Software Foundation, either version 3 Of the License, Or (at your option) any later version. diff --git a/[esx_addons]/esx_joblisting/client/main.lua b/[esx_addons]/esx_joblisting/client/main.lua index 94e7a053..5e958e13 100644 --- a/[esx_addons]/esx_joblisting/client/main.lua +++ b/[esx_addons]/esx_joblisting/client/main.lua @@ -1,82 +1,81 @@ -local menuIsShowed = false +local menuIsShowed, TextUIdrawing = false, false function ShowJobListingMenu() - menuIsShowed = true - ESX.TriggerServerCallback('esx_joblisting:getJobsList', function(jobs) - local elements = {} + menuIsShowed = true + ESX.TriggerServerCallback('esx_joblisting:getJobsList', function(jobs) + local elements = {{unselectable = "true", title = _U('job_center'), icon = "fas fa-briefcase"}} - for k,v in pairs(jobs) do - table.insert(elements, { - label = v.label, - job = k - }) - end + for i = 1, #(jobs) do + elements[#elements + 1] = {title = jobs[i].label, name = jobs[i].name} + end - ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'joblisting', { - title = _U('job_center'), - align = 'top-left', - elements = elements - }, function(data, menu) - TriggerServerEvent('esx_joblisting:setJob', data.current.job) - ESX.ShowNotification(_U('new_job')) - menuIsShowed = false - menu.close() - end, function(data, menu) - menuIsShowed = false - menu.close() - end) - - end) + ESX.OpenContext("right", elements, function(menu, SelectJob) + TriggerServerEvent('esx_joblisting:setJob', SelectJob.name) + ESX.CloseContext() + ESX.ShowNotification(_U('new_job', SelectJob.title), "success") + menuIsShowed = false + TextUIdrawing = false + end, function() + menuIsShowed = false + TextUIdrawing = false + end) + end) end -- Activate menu when player is inside marker, and draw markers CreateThread(function() - while true do - local Sleep = 1500 + while true do + local Sleep = 1500 - local coords = GetEntityCoords(PlayerPedId()) - local isInMarker = false + local coords = GetEntityCoords(ESX.PlayerData.ped) + local isInMarker = false - for i=1, #Config.Zones, 1 do - local distance = #(coords - Config.Zones[i]) + for i = 1, #Config.Zones, 1 do + local distance = #(coords - Config.Zones[i]) - if distance < Config.DrawDistance then - Sleep = 0 - DrawMarker(Config.MarkerType, Config.Zones[i], 0.0, 0.0, 0.0, 0, 0.0, 0.0, Config.ZoneSize.x, Config.ZoneSize.y, Config.ZoneSize.z, Config.MarkerColor.r, Config.MarkerColor.g, Config.MarkerColor.b, 100, false, true, 2, false, false, false, false) - end + if distance < Config.DrawDistance then + Sleep = 0 + DrawMarker(Config.MarkerType, Config.Zones[i], 0.0, 0.0, 0.0, 0, 0.0, 0.0, Config.ZoneSize.x, Config.ZoneSize.y, Config.ZoneSize.z, + Config.MarkerColor.r, Config.MarkerColor.g, Config.MarkerColor.b, 100, false, true, 2, false, false, false, false) + end - if distance < (Config.ZoneSize.x / 2) then - isInMarker = true - ESX.ShowHelpNotification(_U('access_job_center')) - if IsControlJustReleased(0, 38) and not menuIsShowed then - ESX.UI.Menu.CloseAll() - ShowJobListingMenu() - end - end - end + if distance < (Config.ZoneSize.x / 2) then + isInMarker = true + if not TextUIdrawing then + ESX.TextUI(_U("access_job_center")) + TextUIdrawing = true + end + if IsControlJustReleased(0, 38) and not menuIsShowed then + ShowJobListingMenu() + ESX.HideUI() + end + end + end - if not isInMarker and menuIsShowed then - ESX.UI.Menu.CloseAll() - menuIsShowed = false - end + if not isInMarker and TextUIdrawing then + ESX.HideUI() + TextUIdrawing = false + end - Wait(Sleep) - end + Wait(Sleep) + end end) -- Create blips -CreateThread(function() - for i=1, #Config.Zones, 1 do - local blip = AddBlipForCoord(Config.Zones[i]) +if Config.Blip.Enabled then + CreateThread(function() + for i = 1, #Config.Zones, 1 do + local blip = AddBlipForCoord(Config.Zones[i]) - SetBlipSprite (blip, Config.Blip.Sprite) - SetBlipDisplay(blip, Config.Blip.Display) - SetBlipScale (blip, Config.Blip.Scale) - SetBlipColour (blip, Config.Blip.Colour) - SetBlipAsShortRange(blip, Config.Blip.ShortRange) + SetBlipSprite(blip, Config.Blip.Sprite) + SetBlipDisplay(blip, Config.Blip.Display) + SetBlipScale(blip, Config.Blip.Scale) + SetBlipColour(blip, Config.Blip.Colour) + SetBlipAsShortRange(blip, Config.Blip.ShortRange) - BeginTextCommandSetBlipName("STRING") - AddTextComponentSubstringPlayerName(_U('job_center')) - EndTextCommandSetBlipName(blip) - end -end) + BeginTextCommandSetBlipName("STRING") + AddTextComponentSubstringPlayerName(_U('blip_text')) + EndTextCommandSetBlipName(blip) + end + end) +end \ No newline at end of file diff --git a/[esx_addons]/esx_joblisting/config.lua b/[esx_addons]/esx_joblisting/config.lua index 6e41cba7..b9f361fb 100644 --- a/[esx_addons]/esx_joblisting/config.lua +++ b/[esx_addons]/esx_joblisting/config.lua @@ -1,22 +1,22 @@ -Config = {} +Config = {} -Config.DrawDistance = 10.0 -Config.ZoneSize = {x = 2.7, y = 2.7, z = 0.5} -Config.MarkerColor = {r = 100, g = 200, b = 104} -Config.MarkerType = 27 +Config.DrawDistance = 15.0 +Config.ZoneSize = {x = 2.7, y = 2.7, z = 0.5} +Config.MarkerColor = {r = 100, g = 200, b = 104} +Config.MarkerType = 27 Config.Debug = ESX.GetConfig().EnableDebug - -Config.Locale = 'en' +Config.Locale = 'en' Config.Zones = { - vector3(-265.08, -964.1, 30.3) + vector3(-265.08, -964.1, 30.3) } Config.Blip = { - Sprite = 407, - Display = 4, - Scale = 0.9, - Colour = 27, - ShortRange = true -} \ No newline at end of file + Enabled = true, + Sprite = 407, + Display = 4, + Scale = 0.8, + Colour = 27, + ShortRange = true +} diff --git a/[esx_addons]/esx_joblisting/esx_joblisting.sql b/[esx_addons]/esx_joblisting/esx_joblisting.sql index 21e24f6b..98493ad5 100644 --- a/[esx_addons]/esx_joblisting/esx_joblisting.sql +++ b/[esx_addons]/esx_joblisting/esx_joblisting.sql @@ -1,3 +1 @@ - - ALTER TABLE jobs add whitelisted BOOLEAN NOT NULL DEFAULT FALSE; \ No newline at end of file diff --git a/[esx_addons]/esx_joblisting/locales/en.lua b/[esx_addons]/esx_joblisting/locales/en.lua index 0ca5861a..901e076f 100644 --- a/[esx_addons]/esx_joblisting/locales/en.lua +++ b/[esx_addons]/esx_joblisting/locales/en.lua @@ -1,5 +1,6 @@ Locales['en'] = { - ['new_job'] = 'you have a new job!', - ['access_job_center'] = 'press ~INPUT_PICKUP~ to access the job center.', - ['job_center'] = 'job Center', + ['new_job'] = 'New Job: ~b~%s~s~ !', + ['access_job_center'] = 'Press ~b~[E]~s~ To Open Job Selector.', + ['job_center'] = 'Select A Job.', + ["blip_text"] = "Job Centre" } diff --git a/[esx_addons]/esx_joblisting/server/main.lua b/[esx_addons]/esx_joblisting/server/main.lua index 83c5e330..987eb3a5 100644 --- a/[esx_addons]/esx_joblisting/server/main.lua +++ b/[esx_addons]/esx_joblisting/server/main.lua @@ -1,42 +1,47 @@ function getJobs() - local jobs = ESX.GetJobs() - local availableJobs = {} - for k,v in pairs(jobs) do - if v.whitelisted == false then - availableJobs[k] = {label = v.label} - end - end - return availableJobs + local jobs = ESX.GetJobs() + local availableJobs = {} + for k, v in pairs(jobs) do + if v.whitelisted == false then + availableJobs[#availableJobs + 1] = {label = v.label, name = k} + end + end + return availableJobs end ESX.RegisterServerCallback('esx_joblisting:getJobsList', function(source, cb) - local jobs = getJobs() - cb(jobs) + local jobs = getJobs() + cb(jobs) end) function IsNearCentre(player) - local Ped = GetPlayerPed(player) - local PedCoords = GetEntityCoords(Ped) - local Zones = Config.Zones + local Ped = GetPlayerPed(player) + local PedCoords = GetEntityCoords(Ped) + local Zones = Config.Zones + local Close = false - for i=1, #Config.Zones, 1 do - local distance = #(PedCoords - Config.Zones[i]) + for i = 1, #Config.Zones, 1 do + local distance = #(PedCoords - Config.Zones[i]) - if distance < Config.DrawDistance then - return true - end - end + if distance < Config.DrawDistance then + Close = true + end + end + + return Close end RegisterServerEvent('esx_joblisting:setJob') AddEventHandler('esx_joblisting:setJob', function(job) - local source = source - local xPlayer = ESX.GetPlayerFromId(source) - local jobs = getJobs() + local source = source + local xPlayer = ESX.GetPlayerFromId(source) + local jobs = getJobs() - if xPlayer and IsNearCentre(source) then - if jobs[job] then - xPlayer.setJob(job, 0) - end - end + if xPlayer and IsNearCentre(source) then + if ESX.DoesJobExist(job, 0) then + xPlayer.setJob(job, 0) + else + print("[^1ERROR^7] Tried Setting User To Invalid Job - ^5"..job .."^7!") + end + end end)