From b645a74fb8ce4287d8b4597278a8836e1e53e23b Mon Sep 17 00:00:00 2001 From: MiddleSkillz Date: Thu, 6 May 2021 01:35:18 -0600 Subject: [PATCH 01/17] bump: version 1.1.9 --- client/main.lua | 1 + version.json | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/client/main.lua b/client/main.lua index 8e09eb81..59857c01 100644 --- a/client/main.lua +++ b/client/main.lua @@ -67,6 +67,7 @@ AddEventHandler('esx:playerLoaded', function(playerData, isNew) DoScreenFadeIn(10000) StartServerSyncLoops() if isNew then + TriggerEvent('esx_identity:showRegisterIdentity') -- Put your code for if you want to do something with new players. else -- If they aren't new put that code here. diff --git a/version.json b/version.json index 1762b8fa..3ff5d1a3 100644 --- a/version.json +++ b/version.json @@ -1,5 +1,5 @@ { "version": "legacy", - "commit" : "1.1.8", - "changelog": "Code Improvements; Redundant Code Removal" + "commit" : "1.1.9", + "changelog": "Fix esx_identity" } From 07dd52d78a8a07395158ad087b28e6239a36f4c1 Mon Sep 17 00:00:00 2001 From: MiddleSkillz Date: Thu, 6 May 2021 01:37:17 -0600 Subject: [PATCH 02/17] refactor: This function doesn't even do anything! --- client/main.lua | 3 --- 1 file changed, 3 deletions(-) diff --git a/client/main.lua b/client/main.lua index 59857c01..40816300 100644 --- a/client/main.lua +++ b/client/main.lua @@ -55,7 +55,6 @@ AddEventHandler('esx:playerLoaded', function(playerData, isNew) model = `mp_m_freemode_01`, skipFade = false }, function() - TriggerServerEvent('esx:onPlayerSpawn') TriggerEvent('esx:onPlayerSpawn') TriggerEvent('playerSpawned') -- compatibility with old scripts, will be removed soon TriggerEvent('esx:restoreLoadout') @@ -73,8 +72,6 @@ AddEventHandler('esx:playerLoaded', function(playerData, isNew) -- If they aren't new put that code here. end end) - - TriggerEvent('esx:loadingScreenOff') end) RegisterNetEvent('esx:setMaxWeight') From 2aed49b5eb9d71db5719d4d924a941b1641c9d9e Mon Sep 17 00:00:00 2001 From: MiddleSkillz Date: Thu, 6 May 2021 01:43:11 -0600 Subject: [PATCH 03/17] refactor: Remove Stupid LoadingScreenOff thing --- client/main.lua | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/client/main.lua b/client/main.lua index 40816300..356e03e0 100644 --- a/client/main.lua +++ b/client/main.lua @@ -72,6 +72,9 @@ AddEventHandler('esx:playerLoaded', function(playerData, isNew) -- If they aren't new put that code here. end end) + if Config.EnableHud then + ESX.UI.HUD.SetDisplay(1.0) + end end) RegisterNetEvent('esx:setMaxWeight') @@ -370,10 +373,6 @@ if Config.EnableHud then end end end) - - AddEventHandler('esx:loadingScreenOff', function() - ESX.UI.HUD.SetDisplay(1.0) - end) end function StartServerSyncLoops() From 0e68354728a60e2526b368f2c897dc637a5ebbc3 Mon Sep 17 00:00:00 2001 From: MiddleSkillz Date: Thu, 6 May 2021 01:56:34 -0600 Subject: [PATCH 04/17] fix: [client/main] identity might actually work now --- client/main.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/client/main.lua b/client/main.lua index 356e03e0..0718aee2 100644 --- a/client/main.lua +++ b/client/main.lua @@ -63,7 +63,6 @@ AddEventHandler('esx:playerLoaded', function(playerData, isNew) ShutdownLoadingScreen() ShutdownLoadingScreenNui() FreezeEntityPosition(PlayerPedId(), false) - DoScreenFadeIn(10000) StartServerSyncLoops() if isNew then TriggerEvent('esx_identity:showRegisterIdentity') From e9a26a413384129065d9cb724b031d771c5246b8 Mon Sep 17 00:00:00 2001 From: MiddleSkillz Date: Thu, 6 May 2021 02:00:47 -0600 Subject: [PATCH 05/17] Enjoy More Bad Code --- client/main.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/client/main.lua b/client/main.lua index 0718aee2..d1871e93 100644 --- a/client/main.lua +++ b/client/main.lua @@ -64,13 +64,13 @@ AddEventHandler('esx:playerLoaded', function(playerData, isNew) ShutdownLoadingScreenNui() FreezeEntityPosition(PlayerPedId(), false) StartServerSyncLoops() - if isNew then - TriggerEvent('esx_identity:showRegisterIdentity') - -- Put your code for if you want to do something with new players. - else - -- If they aren't new put that code here. - end end) + if isNew then + TriggerEvent('esx_identity:showRegisterIdentity') + -- Put your code for if you want to do something with new players. + else + -- If they aren't new put that code here. + end if Config.EnableHud then ESX.UI.HUD.SetDisplay(1.0) end From d100214a03db60b05f14a00334f4946cfea8221b Mon Sep 17 00:00:00 2001 From: MiddleSkillz Date: Thu, 6 May 2021 02:12:44 -0600 Subject: [PATCH 06/17] Fully Fix spawning I think --- client/main.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/main.lua b/client/main.lua index d1871e93..5df3fdaa 100644 --- a/client/main.lua +++ b/client/main.lua @@ -67,9 +67,10 @@ AddEventHandler('esx:playerLoaded', function(playerData, isNew) end) if isNew then TriggerEvent('esx_identity:showRegisterIdentity') - -- Put your code for if you want to do something with new players. else - -- If they aren't new put that code here. + ESX.TriggerServerCallback('esx_skin:getPlayerSkin', function(skin, jobSkin) + TriggerEvent('skinchanger:loadSkin', skin) + end) end if Config.EnableHud then ESX.UI.HUD.SetDisplay(1.0) From ca9515d6156943e122ee8fefac74c3b9236769c8 Mon Sep 17 00:00:00 2001 From: MiddleSkillz Date: Thu, 6 May 2021 02:16:45 -0600 Subject: [PATCH 07/17] refactor: remove 1 time use variables --- client/main.lua | 45 +++++++++++++-------------------------------- 1 file changed, 13 insertions(+), 32 deletions(-) diff --git a/client/main.lua b/client/main.lua index 5df3fdaa..f6dd1d79 100644 --- a/client/main.lua +++ b/client/main.lua @@ -173,65 +173,46 @@ end) RegisterNetEvent('esx:addWeapon') AddEventHandler('esx:addWeapon', function(weaponName, ammo) - local playerPed = PlayerPedId() - local weaponHash = GetHashKey(weaponName) - - GiveWeaponToPed(playerPed, weaponHash, ammo, false, false) + -- Removed PlayerPedId() from being stored in a variable, not needed + -- when it's only being used once, also doing it in a few + -- functions below this one + GiveWeaponToPed(PlayerPedId(), weaponName, ammo, false, false) end) RegisterNetEvent('esx:addWeaponComponent') AddEventHandler('esx:addWeaponComponent', function(weaponName, weaponComponent) - local playerPed = PlayerPedId() - local weaponHash = GetHashKey(weaponName) local componentHash = ESX.GetWeaponComponent(weaponName, weaponComponent).hash - - GiveWeaponComponentToPed(playerPed, weaponHash, componentHash) + GiveWeaponComponentToPed(PlayerPedId(), weaponName, componentHash) end) RegisterNetEvent('esx:setWeaponAmmo') AddEventHandler('esx:setWeaponAmmo', function(weaponName, weaponAmmo) - local playerPed = PlayerPedId() - local weaponHash = GetHashKey(weaponName) - - SetPedAmmo(playerPed, weaponHash, weaponAmmo) + SetPedAmmo(PlayerPedId(), weaponName, weaponAmmo) end) RegisterNetEvent('esx:setWeaponTint') AddEventHandler('esx:setWeaponTint', function(weaponName, weaponTintIndex) - local playerPed = PlayerPedId() - local weaponHash = GetHashKey(weaponName) - - SetPedWeaponTintIndex(playerPed, weaponHash, weaponTintIndex) + SetPedWeaponTintIndex(PlayerPedId(), weaponName, weaponTintIndex) end) RegisterNetEvent('esx:removeWeapon') AddEventHandler('esx:removeWeapon', function(weaponName) local playerPed = PlayerPedId() - local weaponHash = GetHashKey(weaponName) - - RemoveWeaponFromPed(playerPed, weaponHash) - SetPedAmmo(playerPed, weaponHash, 0) -- remove leftover ammo + RemoveWeaponFromPed(playerPed, weaponName) + SetPedAmmo(playerPed, weaponName, 0) end) RegisterNetEvent('esx:removeWeaponComponent') AddEventHandler('esx:removeWeaponComponent', function(weaponName, weaponComponent) - local playerPed = PlayerPedId() - local weaponHash = GetHashKey(weaponName) local componentHash = ESX.GetWeaponComponent(weaponName, weaponComponent).hash - - RemoveWeaponComponentFromPed(playerPed, weaponHash, componentHash) + RemoveWeaponComponentFromPed(PlayerPedId(), weaponName, componentHash) end) RegisterNetEvent('esx:teleport') AddEventHandler('esx:teleport', function(coords) - local playerPed = PlayerPedId() - - -- ensure decmial number - coords.x = coords.x + 0.0 - coords.y = coords.y + 0.0 - coords.z = coords.z + 0.0 - - ESX.Game.Teleport(playerPed, coords) + -- The coords x, y and z were having 0.0 added to them here to make them floats + -- Since we are forcing vectors in the teleport function now we don't need to do it + ESX.Game.Teleport(PlayerPedId(), coords) end) RegisterNetEvent('esx:setJob') From 7f4f4d14e03fd76ea0642d0784561d98a72a0263 Mon Sep 17 00:00:00 2001 From: MiddleSkillz Date: Thu, 6 May 2021 02:18:29 -0600 Subject: [PATCH 08/17] refactor: Optimize weapon ammo tracking --- client/main.lua | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/client/main.lua b/client/main.lua index f6dd1d79..94ad977d 100644 --- a/client/main.lua +++ b/client/main.lua @@ -362,11 +362,10 @@ function StartServerSyncLoops() while true do Citizen.Wait(1000) - if isDead then - Citizen.Wait(500) - else - local playerPed = PlayerPedId() + local letSleep = true + local playerPed = PlayerPedId() + if IsPedArmed(playerPed, 4) then if IsPedShooting(playerPed) then local _,weaponHash = GetCurrentPedWeapon(playerPed, true) local weapon = ESX.GetWeaponFromHash(weaponHash) @@ -377,6 +376,9 @@ function StartServerSyncLoops() end end end + if letSleep then + Citizen.Wait(500) + end end end) From 4cd90dc1d8888c3e9a9892f7279ff7bfef0ac889 Mon Sep 17 00:00:00 2001 From: MiddleSkillz Date: Thu, 6 May 2021 02:21:31 -0600 Subject: [PATCH 09/17] refactor: Optimize death module --- client/main.lua | 18 ++++++++---------- client/modules/death.lua | 10 ++++++++-- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/client/main.lua b/client/main.lua index 94ad977d..d9023ef9 100644 --- a/client/main.lua +++ b/client/main.lua @@ -405,17 +405,15 @@ function StartServerSyncLoops() end) end -Citizen.CreateThread(function() - while Config.EnableDefaultInventory do - Citizen.Wait(9) - - if IsControlJustReleased(0, 289) then - if IsInputDisabled(0) and not isDead and not ESX.UI.Menu.IsOpen('default', 'es_extended', 'inventory') then - ESX.ShowInventory() - end +if Config.EnableDefaultInventory then + RegisterCommand('showinv', function() + if not isDead and not ESX.UI.Menu.IsOpen('default', 'es_extended', 'inventory') then + ESX.ShowInventory() end - end -end) + end) + + RegisterKeyMapping('showinv', _U('keymap_showinventory'), 'keyboard', 'F2') +end Citizen.CreateThread(function() while true do diff --git a/client/modules/death.lua b/client/modules/death.lua index b7cd047a..baa2e727 100644 --- a/client/modules/death.lua +++ b/client/modules/death.lua @@ -2,13 +2,15 @@ Citizen.CreateThread(function() local isDead = false while true do - Citizen.Wait(150) + Citizen.Wait(0) + local letSleep = 0 local player = PlayerId() if NetworkIsPlayerActive(player) then local playerPed = PlayerPedId() if IsPedFatallyInjured(playerPed) and not isDead then + letSleep = false isDead = true local killerEntity, deathCause = GetPedSourceOfDeath(playerPed), GetPedCauseOfDeath(playerPed) @@ -20,10 +22,14 @@ Citizen.CreateThread(function() PlayerKilled(deathCause) end - elseif not IsPedFatallyInjured(playerPed) then + elseif not IsPedFatallyInjured(playerPed) and isDead then + letSleep = false isDead = false end end + if letSleep then + Citizen.Wait(500) + end end end) From bdc1109cde769b3814a19cdcd5af154839bfbaf0 Mon Sep 17 00:00:00 2001 From: MiddleSkillz Date: Thu, 6 May 2021 02:22:14 -0600 Subject: [PATCH 10/17] refactor: 64 is a odd number for VARCHAR --- es_extended.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/es_extended.sql b/es_extended.sql index 6bfa339e..977ed8de 100644 --- a/es_extended.sql +++ b/es_extended.sql @@ -2,7 +2,7 @@ CREATE DATABASE IF NOT EXISTS `es_extended`; USE `es_extended`; CREATE TABLE `users` ( - `identifier` VARCHAR(64) NOT NULL, + `identifier` VARCHAR(60) NOT NULL, `accounts` LONGTEXT NULL DEFAULT NULL, `group` VARCHAR(50) NULL DEFAULT 'user', `inventory` LONGTEXT NULL DEFAULT NULL, From 531c831e4c2335ff22c250df50f23a708030d9fe Mon Sep 17 00:00:00 2001 From: MiddleSkillz Date: Thu, 6 May 2021 02:24:02 -0600 Subject: [PATCH 11/17] refactor: optimize ESX.TimeoutCallbacks --- client/functions.lua | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/client/functions.lua b/client/functions.lua index 970a07ab..ba0d1791 100644 --- a/client/functions.lua +++ b/client/functions.lua @@ -1022,15 +1022,22 @@ end) Citizen.CreateThread(function() while true do Citizen.Wait(0) + local letSleep = true local currTime = GetGameTimer() - for i=1, #ESX.TimeoutCallbacks, 1 do - if ESX.TimeoutCallbacks[i] then - if currTime >= ESX.TimeoutCallbacks[i].time then - ESX.TimeoutCallbacks[i].cb() - ESX.TimeoutCallbacks[i] = nil + if #ESX.TimeoutCallbacks > 0 then + letSleep = false + for i=1, #ESX.TimeoutCallbacks, 1 do + if ESX.TimeoutCallbacks[i] then + if currTime >= ESX.TimeoutCallbacks[i].time then + ESX.TimeoutCallbacks[i].cb() + ESX.TimeoutCallbacks[i] = nil + end end end end + if letSleep then + Citizen.Wait(500) + end end end) From bf61df020325d1fbf8b383de3392146428017676 Mon Sep 17 00:00:00 2001 From: MiddleSkillz Date: Thu, 6 May 2021 02:26:52 -0600 Subject: [PATCH 12/17] fix: SetMaxWantedLevel doesn't need to be in a loop. --- client/main.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/client/main.lua b/client/main.lua index d9023ef9..a86f30a8 100644 --- a/client/main.lua +++ b/client/main.lua @@ -22,12 +22,6 @@ AddEventHandler('esx:playerLoaded', function(playerData, isNew) SetCanAttackFriendly(PlayerPedId(), true, false) NetworkSetFriendlyFireOption(true) end - - -- disable wanted level - if not Config.EnableWantedLevel then - ClearPlayerWantedLevel(PlayerId()) - SetMaxWantedLevel(0) - end if Config.EnableHud then for k,v in ipairs(playerData.accounts) do @@ -415,6 +409,12 @@ if Config.EnableDefaultInventory then RegisterKeyMapping('showinv', _U('keymap_showinventory'), 'keyboard', 'F2') end +-- disable wanted level +if not Config.EnableWantedLevel then + ClearPlayerWantedLevel(PlayerId()) + SetMaxWantedLevel(0) +end + Citizen.CreateThread(function() while true do Citizen.Wait(0) From 5c471535f10a0791e49526ff92c3153dd7c08a2f Mon Sep 17 00:00:00 2001 From: MiddleSkillz Date: Thu, 6 May 2021 02:27:20 -0600 Subject: [PATCH 13/17] refactor: odd code formatting --- client/main.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/main.lua b/client/main.lua index a86f30a8..1d36ccdf 100644 --- a/client/main.lua +++ b/client/main.lua @@ -3,8 +3,8 @@ local isPaused, isDead, pickups = false, false, {} Citizen.CreateThread(function() while NetworkIsPlayerActive(PlayerId()) do Citizen.Wait(5) - TriggerServerEvent('esx:onPlayerJoined') - break + TriggerServerEvent('esx:onPlayerJoined') + break end end) From 0cc99faa5f2588e3877f3507060376c99a29397a Mon Sep 17 00:00:00 2001 From: MiddleSkillz Date: Thu, 6 May 2021 02:28:16 -0600 Subject: [PATCH 14/17] fix: esx:loadingScreenOff for compatibility --- client/main.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/main.lua b/client/main.lua index 1d36ccdf..b4e64269 100644 --- a/client/main.lua +++ b/client/main.lua @@ -50,7 +50,7 @@ AddEventHandler('esx:playerLoaded', function(playerData, isNew) skipFade = false }, function() TriggerEvent('esx:onPlayerSpawn') - TriggerEvent('playerSpawned') -- compatibility with old scripts, will be removed soon + TriggerEvent('playerSpawned') -- compatibility with old scripts, will be removed soon. TriggerEvent('esx:restoreLoadout') Citizen.Wait(4000) @@ -69,6 +69,8 @@ AddEventHandler('esx:playerLoaded', function(playerData, isNew) if Config.EnableHud then ESX.UI.HUD.SetDisplay(1.0) end + + TriggerEvent('esx:loadingScreenOff') -- compatibility with old scripts, will be removed soon. end) RegisterNetEvent('esx:setMaxWeight') From c9aaab9a08bc7408ad5f6e53fa9147d30f2be065 Mon Sep 17 00:00:00 2001 From: MiddleSkillz Date: Thu, 6 May 2021 02:34:03 -0600 Subject: [PATCH 15/17] fix: force vector3 on Teleport function --- client/functions.lua | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/client/functions.lua b/client/functions.lua index ba0d1791..bf309bfd 100644 --- a/client/functions.lua +++ b/client/functions.lua @@ -308,21 +308,16 @@ ESX.Game.GetPedMugshot = function(ped, transparent) end ESX.Game.Teleport = function(entity, coords, cb) + local vector = type(coords) == "vector4" and coords or type(coords) == "vector3" and vector4(coords, 0.0) or vec(coords.x, coords.y, coords.z, coords.heading or 0.0) + if DoesEntityExist(entity) then - RequestCollisionAtCoord(coords.x, coords.y, coords.z) - local timeout = 0 - - -- we can get stuck here if any of the axies are "invalid" - while not HasCollisionLoadedAroundEntity(entity) and timeout < 2000 do - Citizen.Wait(0) - timeout = timeout + 1 + RequestCollisionAtCoord(vector.xyz) + while not HasCollisionLoadedAroundEntity(entity) do + Wait(0) end - SetEntityCoords(entity, coords.x, coords.y, coords.z, false, false, false, false) - - if type(coords) == 'table' and coords.heading then - SetEntityHeading(entity, coords.heading) - end + SetEntityCoords(entity, vector.xyz, false, false, false, false) + SetEntityHeading(entity, vector.w) end if cb then From 1662caa137601372359b92b0a46e62249584e616 Mon Sep 17 00:00:00 2001 From: MiddleSkillz Date: Thu, 6 May 2021 02:34:32 -0600 Subject: [PATCH 16/17] fix: Remove Redundant Function --- client/functions.lua | 85 ++++++++++++++------------------------------ 1 file changed, 27 insertions(+), 58 deletions(-) diff --git a/client/functions.lua b/client/functions.lua index bf309bfd..8d7df142 100644 --- a/client/functions.lua +++ b/client/functions.lua @@ -325,14 +325,18 @@ ESX.Game.Teleport = function(entity, coords, cb) end end -ESX.Game.SpawnObject = function(model, coords, cb) - local model = (type(model) == 'number' and model or GetHashKey(model)) - - Citizen.CreateThread(function() +ESX.Game.SpawnObject = function(model, coords, cb, networked, dynamic) + local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z) + networked = networked == nil and true or false + dynamic = dynamic ~= nil and true or false + + CreateThread(function() ESX.Streaming.RequestModel(model) - local obj = CreateObject(model, coords.x, coords.y, coords.z, true, false, true) - SetModelAsNoLongerNeeded(model) - + + -- The below has to be done just for CreateObject since for some reason CreateObjects model argument is set + -- as an Object instead of a hash so it doesn't automatically hash the item + model = type(model) == 'number' and model or GetHashKey(model) + local obj = CreateObject(model, vector.xyz, networked, false, dynamic) if cb then cb(obj) end @@ -340,17 +344,8 @@ ESX.Game.SpawnObject = function(model, coords, cb) end ESX.Game.SpawnLocalObject = function(model, coords, cb) - local model = (type(model) == 'number' and model or GetHashKey(model)) - - Citizen.CreateThread(function() - ESX.Streaming.RequestModel(model) - local obj = CreateObject(model, coords.x, coords.y, coords.z, false, false, true) - SetModelAsNoLongerNeeded(model) - - if cb then - cb(obj) - end - end) + -- Why have 2 separate functions for this? Just call the other one with an extra param + ESX.Game.SpawnObject(model, coords, cb, false) end ESX.Game.DeleteVehicle = function(vehicle) @@ -363,28 +358,25 @@ ESX.Game.DeleteObject = function(object) DeleteObject(object) end -ESX.Game.SpawnVehicle = function(modelName, coords, heading, cb) - local model = (type(modelName) == 'number' and modelName or GetHashKey(modelName)) - - Citizen.CreateThread(function() +ESX.Game.SpawnVehicle = function(model, coords, heading, cb, networked) + local vector = type(coords) == "vector3" and coords or vec(coords.x, coords.y, coords.z) + networked = networked == nil and true or false + CreateThread(function() ESX.Streaming.RequestModel(model) - local vehicle = CreateVehicle(model, coords.x, coords.y, coords.z, heading, true, false) - local networkId = NetworkGetNetworkIdFromEntity(vehicle) - local timeout = 0 + local vehicle = CreateVehicle(model, vector.xyz, heading, networked, false) + local id = NetworkGetNetworkIdFromEntity(vehicle) - SetNetworkIdCanMigrate(networkId, true) + SetNetworkIdCanMigrate(id, true) SetEntityAsMissionEntity(vehicle, true, false) SetVehicleHasBeenOwnedByPlayer(vehicle, true) SetVehicleNeedsToBeHotwired(vehicle, false) - SetVehRadioStation(vehicle, 'OFF') SetModelAsNoLongerNeeded(model) - RequestCollisionAtCoord(coords.x, coords.y, coords.z) + SetVehRadioStation(vehicle, 'OFF') - -- we can get stuck here if any of the axies are "invalid" - while not HasCollisionLoadedAroundEntity(vehicle) and timeout < 2000 do - Citizen.Wait(0) - timeout = timeout + 1 + RequestCollisionAtCoord(vector.xyz) + while not HasCollisionLoadedAroundEntity(vehicle) do + Wait(0) end if cb then @@ -393,32 +385,9 @@ ESX.Game.SpawnVehicle = function(modelName, coords, heading, cb) end) end -ESX.Game.SpawnLocalVehicle = function(modelName, coords, heading, cb) - local model = (type(modelName) == 'number' and modelName or GetHashKey(modelName)) - - Citizen.CreateThread(function() - ESX.Streaming.RequestModel(model) - - local vehicle = CreateVehicle(model, coords.x, coords.y, coords.z, heading, false, false) - local timeout = 0 - - SetEntityAsMissionEntity(vehicle, true, false) - SetVehicleHasBeenOwnedByPlayer(vehicle, true) - SetVehicleNeedsToBeHotwired(vehicle, false) - SetVehRadioStation(vehicle, 'OFF') - SetModelAsNoLongerNeeded(model) - RequestCollisionAtCoord(coords.x, coords.y, coords.z) - - -- we can get stuck here if any of the axies are "invalid" - while not HasCollisionLoadedAroundEntity(vehicle) and timeout < 2000 do - Citizen.Wait(0) - timeout = timeout + 1 - end - - if cb then - cb(vehicle) - end - end) +ESX.Game.SpawnLocalVehicle = function(model, coords, heading, cb) + -- Why have 2 separate functions for this? Just call the other one with an extra param + ESX.Game.SpawnVehicle(model, coords, heading, cb, false) end ESX.Game.IsVehicleEmpty = function(vehicle) From 620ca92f6134d5b5776c05dc4c171cedf962e25c Mon Sep 17 00:00:00 2001 From: MiddleSkillz Date: Thu, 6 May 2021 02:35:47 -0600 Subject: [PATCH 17/17] fix: weird esx:spawnVehicle code --- client/main.lua | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/client/main.lua b/client/main.lua index b4e64269..751b5c33 100644 --- a/client/main.lua +++ b/client/main.lua @@ -223,21 +223,18 @@ AddEventHandler('esx:setJob', function(Job) end) RegisterNetEvent('esx:spawnVehicle') -AddEventHandler('esx:spawnVehicle', function(vehicleName) - local model = (type(vehicleName) == 'number' and vehicleName or GetHashKey(vehicleName)) - - if IsModelInCdimage(model) then +AddEventHandler('esx:spawnVehicle', function(vehicle) + if IsModelInCdimage(vehicle) then local playerPed = PlayerPedId() local playerCoords, playerHeading = GetEntityCoords(playerPed), GetEntityHeading(playerPed) - ESX.Game.SpawnVehicle(model, playerCoords, playerHeading, function(vehicle) + ESX.Game.SpawnVehicle(vehicle, playerCoords, playerHeading, function(vehicle) TaskWarpPedIntoVehicle(playerPed, vehicle, -1) end) else - TriggerEvent('chat:addMessage', {args = {'^1SYSTEM', 'Invalid vehicle model.'}}) + TriggerEvent('chat:addMessage', { args = { '^1SYSTEM', 'Invalid vehicle model.' } }) end end) - RegisterNetEvent('esx:createPickup') AddEventHandler('esx:createPickup', function(pickupId, label, coords, type, name, components, tintIndex) local function setObjectProperties(object)