mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 17:28:53 +00:00
Merge branch 'main' of https://github.com/esx-framework/esx-legacy
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:', '')
|
||||
|
||||
@@ -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
|
||||
@@ -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.
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
}
|
||||
Enabled = true,
|
||||
Sprite = 407,
|
||||
Display = 4,
|
||||
Scale = 0.8,
|
||||
Colour = 27,
|
||||
ShortRange = true
|
||||
}
|
||||
|
||||
@@ -1,3 +1 @@
|
||||
|
||||
|
||||
ALTER TABLE jobs add whitelisted BOOLEAN NOT NULL DEFAULT FALSE;
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user