Merge branch 'development'

This commit is contained in:
Mycroft
2022-08-10 06:14:23 +01:00
4 changed files with 137 additions and 135 deletions
+84 -47
View File
@@ -403,23 +403,14 @@ function ESX.UI.ShowInventoryItemNotification(add, item, count)
end
function ESX.Game.GetPedMugshot(ped, transparent)
if DoesEntityExist(ped) then
local mugshot
if not DoesEntityExist(ped) then return end
local mugshot = transparent and RegisterPedheadshotTransparent(ped) or RegisterPedheadshot(ped)
if transparent then
mugshot = RegisterPedheadshotTransparent(ped)
else
mugshot = RegisterPedheadshot(ped)
end
while not IsPedheadshotReady(mugshot) do
Wait(0)
end
return mugshot, GetPedheadshotTxdString(mugshot)
else
return
while not IsPedheadshotReady(mugshot) do
Wait(0)
end
return mugshot, GetPedheadshotTxdString(mugshot)
end
function ESX.Game.Teleport(entity, coords, cb)
@@ -442,18 +433,35 @@ function ESX.Game.Teleport(entity, coords, cb)
end
function ESX.Game.SpawnObject(object, coords, cb, networked)
local model = type(object) == 'number' and object or GetHashKey(object)
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
ESX.TriggerServerCallback('esx:Onesync:SpawnObject', function(NetworkID)
if cb then
local obj = NetworkGetEntityFromNetworkId(NetworkID)
local Tries = 0
while not DoesEntityExist(obj) do
obj = NetworkGetEntityFromNetworkId(NetworkID)
Wait(0)
Tries += 1
if Tries > 250 then
break
end
end
cb(obj)
end
end, object, coords, 0.0)
else
local model = type(object) == 'number' and object or GetHashKey(object)
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)
CreateThread(function()
ESX.Streaming.RequestModel(model)
CreateThread(function()
ESX.Streaming.RequestModel(model)
local obj = CreateObject(model, vector.xyz, networked, false, true)
if cb then
cb(obj)
end
end)
local obj = CreateObject(model, vector.xyz, networked, false, true)
if cb then
cb(obj)
end
end)
end
end
function ESX.Game.SpawnLocalObject(object, coords, cb)
@@ -461,7 +469,7 @@ function ESX.Game.SpawnLocalObject(object, coords, cb)
end
function ESX.Game.DeleteVehicle(vehicle)
SetEntityAsMissionEntity(vehicle, false, true)
SetEntityAsMissionEntity(vehicle, true, true)
DeleteVehicle(vehicle)
end
@@ -474,30 +482,58 @@ function ESX.Game.SpawnVehicle(vehicle, coords, heading, cb, networked)
local model = (type(vehicle) == 'number' and vehicle or GetHashKey(vehicle))
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)
networked = networked == nil and true or networked
CreateThread(function()
ESX.Streaming.RequestModel(model)
if networked then
local isAutomobile = IsThisModelACar(model)
if isAutomobile ~= false then isAutomobile = true end
ESX.TriggerServerCallback('esx:Onesync:SpawnVehicle',function(NetID)
print("Spawned Vehicle: " .. NetID)
if NetID then
local vehicle = NetworkGetEntityFromNetworkId(NetID)
local Tries = 0
while not DoesEntityExist(vehicle) do
vehicle = NetworkGetEntityFromNetworkId(NetID)
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)
local vehicle = CreateVehicle(model, vector.xyz, heading, networked, false)
local vehicle = CreateVehicle(model, vector.xyz, heading, networked, false)
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, false)
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)
if cb then
cb(vehicle)
end
end)
end
end
function ESX.Game.SpawnLocalVehicle(vehicle, coords, heading, cb)
@@ -549,6 +585,7 @@ function ESX.Game.GetPlayers(onlyOtherPlayers, returnKeyValue, returnPeds)
return players
end
function ESX.Game.GetClosestObject(coords, modelFilter)
return ESX.Game.GetClosestEntity(ESX.Game.GetObjects(), false, coords, modelFilter)
end
@@ -665,7 +702,7 @@ function ESX.Game.GetVehicleProperties(vehicle)
for extraId = 0, 12 do
if DoesExtraExist(vehicle, extraId) then
local state = IsVehicleExtraTurnedOn(vehicle, extraId) == 1
local state = IsVehicleExtraTurnedOn(vehicle, extraId)
extras[tostring(extraId)] = state
end
end
+12 -54
View File
@@ -55,46 +55,41 @@ AddEventHandler('esx:playerLoaded', function(xPlayer, isNew, skin)
NetworkSetFriendlyFireOption(true)
end
if Config.DisableVehicleRewards then
DisablePlayerVehicleRewards(PlayerId())
end
if Config.DisableNPCDrops then
RemoveAllPickupsOfType(0xDF711959) -- carbine rifle
RemoveAllPickupsOfType(0xF9AFB48F) -- pistol
RemoveAllPickupsOfType(0xA9355DCD) -- pumpshotgun
end
CreateThread(function()
while true do
local Sleep = 1500
Wait(0)
if Config.DisableHealthRegeneration then
SetPlayerHealthRechargeMultiplier(PlayerId(), 0.0)
end
if Config.DisableWeaponWheel then
Sleep = 0
BlockWeaponWheelThisFrame()
DisableControlAction(0, 37,true)
end
if Config.DisableAimAssist then
if Sleep == 1500 then Sleep = 100 end
if IsPedArmed(ESX.PlayerData.ped, 4) then
SetPlayerLockonRangeOverride(PlayerId(), 2.0)
end
end
if Config.DisableVehicleRewards then
DisablePlayerVehicleRewards(PlayerId())
end
if Config.DisableNPCDrops then
RemoveAllPickupsOfType(0xDF711959) -- carbine rifle
RemoveAllPickupsOfType(0xF9AFB48F) -- pistol
RemoveAllPickupsOfType(0xA9355DCD) -- pumpshotgun
end
if Config.RemoveHudCommonents then
if Sleep ~= 0 then Sleep = 0 end
for i=1, #(Config.RemoveHudCommonents) do
if Config.RemoveHudCommonents[i] then
HideHudComponentThisFrame(i)
end
end
end
Wait(Sleep)
end
end)
@@ -115,6 +110,7 @@ AddEventHandler('esx:playerLoaded', function(xPlayer, isNew, skin)
})
end
SetDefaultVehicleNumberPlateTextPattern(-1, 'ESX.A111')
FreezeEntityPosition(PlayerPedId(), false)
StartServerSyncLoops()
end)
@@ -395,44 +391,6 @@ if not Config.OxInventory then
end)
end
RegisterNetEvent('esx:deleteVehicle')
AddEventHandler('esx:deleteVehicle', function(radius)
if radius and tonumber(radius) then
radius = tonumber(radius) + 0.01
local vehicles = ESX.Game.GetVehiclesInArea(GetEntityCoords(ESX.PlayerData.ped), radius)
for k,entity in ipairs(vehicles) do
local attempt = 0
while not NetworkHasControlOfEntity(entity) and attempt < 100 and DoesEntityExist(entity) do
Wait(100)
NetworkRequestControlOfEntity(entity)
attempt = attempt + 1
end
if DoesEntityExist(entity) and NetworkHasControlOfEntity(entity) then
ESX.Game.DeleteVehicle(entity)
end
end
else
local vehicle, attempt = ESX.Game.GetVehicleInDirection(), 0
if IsPedInAnyVehicle(ESX.PlayerData.ped, true) then
vehicle = GetVehiclePedIsIn(ESX.PlayerData.ped, false)
end
while not NetworkHasControlOfEntity(vehicle) and attempt < 100 and DoesEntityExist(vehicle) do
Wait(100)
NetworkRequestControlOfEntity(vehicle)
attempt = attempt + 1
end
if DoesEntityExist(vehicle) and NetworkHasControlOfEntity(vehicle) then
ESX.Game.DeleteVehicle(vehicle)
end
end
end)
-- Pause menu disables HUD display
if Config.EnableHud then
CreateThread(function()
+9 -4
View File
@@ -23,14 +23,19 @@ ESX.RegisterCommand('car', 'admin', function(xPlayer, args, showError)
if not args.car then args.car = GameBuild >= 2699 and "DRAUGUR" or "Prototipo" end
xPlayer.triggerEvent('esx:spawnVehicle', args.car)
end, false, {help = _U('command_car'), validate = false, arguments = {
{name = 'car', help = _U('command_car_car'), type = 'any'}
{name = 'car',validate = false, help = _U('command_car_car'), type = 'string'}
}})
ESX.RegisterCommand({'cardel', 'dv'}, 'admin', function(xPlayer, args, showError)
if not args.radius then args.radius = 4 end
xPlayer.triggerEvent('esx:deleteVehicle', args.radius)
local Vehicles = ESX.OneSync.GetVehiclesInArea(xPlayer.getCoords(true), tonumber(args.radius) or 4)
for i=1, #Vehicles do
local Vehicle = NetworkGetEntityFromNetworkId(Vehicles[i])
if DoesEntityExist(Vehicle) then
DeleteEntity(Vehicle)
end
end
end, false, {help = _U('command_cardel'), validate = false, arguments = {
{name = 'radius', help = _U('command_cardel_radius'), type = 'any'}
{name = 'radius',validate = false, help = _U('command_cardel_radius'), type = 'string'}
}})
ESX.RegisterCommand('setaccountmoney', 'admin', function(xPlayer, args, showError)
+32 -30
View File
@@ -25,15 +25,14 @@ local function getNearbyPlayers(source, closest, distance, ignore)
local coords = GetEntityCoords(entity)
if not closest then
local dist = #(source - coords)
local dist = #(xPlayer.source - coords)
if dist <= distance then
count += 1
result[count] = {id = xPlayer.source, ped = entity, coords = coords, dist = dist}
result[count] = {id = xPlayer.source, ped = NetworkGetNetworkIdFromEntity(entity), coords = coords, dist = dist}
end
else
local dist = #(source - coords)
if dist <= (result.dist or distance) then
result = {id = xPlayer.source, ped = entity, coords = coords, dist = dist}
local dist = #(xPlayer.source - coords)
result = {id = xPlayer.source, ped = NetworkGetNetworkIdFromEntity(entity), coords = coords, dist = dist} if dist <= (result.dist or distance) then
end
end
end
@@ -60,26 +59,14 @@ end
---@param coords vector3|table
---@param heading number
---@param cb function
function ESX.OneSync.SpawnVehicle(model, coords, heading, cb)
function ESX.OneSync.SpawnVehicle(model, coords, heading, autoMobile, cb)
if type(model) == 'string' then model = GetHashKey(model) end
CreateThread(function()
local entity = Citizen.InvokeNative(`CREATE_AUTOMOBILE`, model, coords.x, coords.y, coords.z, heading)
while not DoesEntityExist(entity) do Wait(50) end
-- Sometimes peds can spawn in the vehicle
local ped = GetPedInVehicleSeat(entity, -1)
if ped > 0 then
for i = -1, 6 do
ped = GetPedInVehicleSeat(entity, i)
local popType = GetEntityPopulationType(ped)
if popType <= 5 or popType >= 1 then
DeleteEntity(ped)
end
end
end
cb(entity)
end)
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)
if type(autoMobile) ~= 'boolean' then
return
end
local Entity = autoMobile and Citizen.InvokeNative(`CREATE_AUTOMOBILE`, model, coords.x, coords.y, coords.z, heading) or CreateVehicle(model, coords, heading, true, true)
cb(NetworkGetNetworkIdFromEntity(Entity))
end
---@param model number|string
@@ -88,11 +75,12 @@ end
---@param cb function
function ESX.OneSync.SpawnObject(model, coords, heading, cb)
if type(model) == 'string' then model = GetHashKey(model) end
local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z)
CreateThread(function()
local entity = CreateObject(model, coords, true, true)
while not DoesEntityExist(entity) do Wait(50) end
SetEntityHeading(entity, heading)
cb(entity)
cb(NetworkGetNetworkIdFromEntity(entity))
end)
end
@@ -105,7 +93,7 @@ function ESX.OneSync.SpawnPed(model, coords, heading, cb)
CreateThread(function()
local entity = CreatePed(0, model, coords.x, coords.y, coords.z, heading, true, true)
while not DoesEntityExist(entity) do Wait(50) end
cb(entity)
return entity
end)
end
@@ -118,7 +106,7 @@ function ESX.OneSync.SpawnPedInVehicle(model, vehicle, seat, cb)
CreateThread(function()
local entity = CreatePedInsideVehicle(vehicle, 1, model, seat, true, true)
while not DoesEntityExist(entity) do Wait(50) end
cb(entity)
return entity
end)
end
@@ -130,7 +118,7 @@ local function getNearbyEntities(entities, coords, modelFilter, maxDistance, isP
if not modelFilter or modelFilter[GetEntityModel(entity)] then
local entityCoords = GetEntityCoords(entity)
if not maxDistance or #(coords - entityCoords) <= maxDistance then
nearbyEntities[#nearbyEntities+1] = {entity=entity, coords=entityCoords}
nearbyEntities[#nearbyEntities+1] = NetworkGetNetworkIdFromEntity(entity)
end
end
end
@@ -159,7 +147,7 @@ end
---@param maxDistance number
---@param modelFilter table models to ignore, where the key is the model hash and the value is true
---@return table
function ESX.OneSync.GetVehiclesInArea(coords, maxDistance, modelFilter)
function ESX.OneSync.GetVehiclesInArea(coords, maxDistance, modelFilter, cb)
return getNearbyEntities(GetAllVehicles(), coords, modelFilter, maxDistance)
end
@@ -178,7 +166,7 @@ local function getClosestEntity(entities, coords, modelFilter, isPed)
end
end
end
return closestEntity, distance, closestCoords
return NetworkGetNetworkIdFromEntity(closestEntity), distance, closestCoords
end
---@param coords vector3
@@ -201,3 +189,17 @@ end
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