!tweak(es_extended): another attempt to mitigate vehicle creation issues

Note: this increases the Minimum Artifact to 10188
This commit is contained in:
Kasey FItton
2024-11-05 16:05:20 +00:00
parent 856ee5e569
commit b5e0474d13
4 changed files with 43 additions and 33 deletions
+2 -1
View File
@@ -1,6 +1,7 @@
{ {
"Lua.diagnostics.globals": [ "Lua.diagnostics.globals": [
"MySQL", "MySQL",
"GetPlayerTimeOnline" "GetPlayerTimeOnline",
"SetEntityOrphanMode"
] ]
} }
+9 -3
View File
@@ -260,10 +260,16 @@ AddStateBagChangeHandler("VehicleProperties", nil, function(bagName, _, value)
error("Tried to set vehicle properties with invalid netId") error("Tried to set vehicle properties with invalid netId")
return return
end end
local vehicle = NetToVeh(netId) local vehicle = NetToVeh(netId)
if not DoesEntityExist(vehicle) then
error("Tried to set vehicle properties with invalid vehicle") local tries = 0
return while not NetworkDoesEntityExistWithNetworkId(vehicle) do
Wait(200)
tries = tries + 1
if tries > 20 then
return error(("Invalid entity - ^5%s^7!"):format(netId))
end
end end
if not NetworkGetEntityOwner(vehicle) == ESX.playerId then if not NetworkGetEntityOwner(vehicle) == ESX.playerId then
+26 -25
View File
@@ -46,9 +46,9 @@ end
local function onPlayerJoined(playerId) local function onPlayerJoined(playerId)
local identifier = ESX.GetIdentifier(playerId) local identifier = ESX.GetIdentifier(playerId)
if not identifier then if not identifier then
return DropPlayer(playerId, "there was an error loading your character!\nError code: identifier-missing-ingame\n\nThe cause of this error is not known, your identifier could not be found. Please come back later or report this problem to the server administration team.") return DropPlayer(playerId, "there was an error loading your character!\nError code: identifier-missing-ingame\n\nThe cause of this error is not known, your identifier could not be found. Please come back later or report this problem to the server administration team.")
end end
if ESX.GetPlayerFromIdentifier(identifier) then if ESX.GetPlayerFromIdentifier(identifier) then
DropPlayer( DropPlayer(
@@ -102,8 +102,9 @@ if not Config.Multichar then
local playerId = source local playerId = source
local identifier = ESX.GetIdentifier(playerId) local identifier = ESX.GetIdentifier(playerId)
if not GetPlayerTimeOnline then
return deferrals.done(("[ESX] ESX Requires a minimum Artifact version of 9515, Please update your server."):format(oneSyncState)) if not SetEntityOrphanMode then
return deferrals.done(("[ESX] ESX Requires a minimum Artifact version of 10188, Please update your server."):format(oneSyncState))
end end
if oneSyncState == "off" or oneSyncState == "legacy" then if oneSyncState == "off" or oneSyncState == "legacy" then
@@ -226,8 +227,8 @@ function loadESXPlayer(identifier, playerId, isNew)
-- Loadout -- Loadout
if not Config.CustomInventory then if not Config.CustomInventory then
if not result.loadout or result.loadout == "" then if not result.loadout or result.loadout == "" then
return return
end end
local loadout = json.decode(result.loadout) local loadout = json.decode(result.loadout)
for name, weapon in pairs(loadout) do for name, weapon in pairs(loadout) do
@@ -292,8 +293,8 @@ function loadESXPlayer(identifier, playerId, isNew)
if not Config.CustomInventory then if not Config.CustomInventory then
xPlayer.triggerEvent("esx:createMissingPickups", Core.Pickups) xPlayer.triggerEvent("esx:createMissingPickups", Core.Pickups)
elseif setPlayerInventory then elseif setPlayerInventory then
setPlayerInventory(playerId, xPlayer, userData.inventory, isNew) setPlayerInventory(playerId, xPlayer, userData.inventory, isNew)
end end
xPlayer.triggerEvent("esx:registerSuggestions", Core.RegisteredCommands) xPlayer.triggerEvent("esx:registerSuggestions", Core.RegisteredCommands)
@@ -384,13 +385,13 @@ if not Config.CustomInventory then
if itemType == "item_standard" then if itemType == "item_standard" then
local sourceItem = sourceXPlayer.getInventoryItem(itemName) local sourceItem = sourceXPlayer.getInventoryItem(itemName)
if itemCount < 1 or sourceItem.count < itemCount then if itemCount < 1 or sourceItem.count < itemCount then
return sourceXPlayer.showNotification(TranslateCap("imp_invalid_quantity")) return sourceXPlayer.showNotification(TranslateCap("imp_invalid_quantity"))
end end
if not targetXPlayer.canCarryItem(itemName, itemCount) then if not targetXPlayer.canCarryItem(itemName, itemCount) then
return sourceXPlayer.showNotification(TranslateCap("ex_inv_lim", targetXPlayer.name)) return sourceXPlayer.showNotification(TranslateCap("ex_inv_lim", targetXPlayer.name))
end end
sourceXPlayer.removeInventoryItem(itemName, itemCount) sourceXPlayer.removeInventoryItem(itemName, itemCount)
targetXPlayer.addInventoryItem(itemName, itemCount) targetXPlayer.addInventoryItem(itemName, itemCount)
@@ -398,9 +399,9 @@ if not Config.CustomInventory then
sourceXPlayer.showNotification(TranslateCap("gave_item", itemCount, sourceItem.label, targetXPlayer.name)) sourceXPlayer.showNotification(TranslateCap("gave_item", itemCount, sourceItem.label, targetXPlayer.name))
targetXPlayer.showNotification(TranslateCap("received_item", itemCount, sourceItem.label, sourceXPlayer.name)) targetXPlayer.showNotification(TranslateCap("received_item", itemCount, sourceItem.label, sourceXPlayer.name))
elseif itemType == "item_account" then elseif itemType == "item_account" then
if itemCount < 1 or sourceXPlayer.getAccount(itemName).money < itemCount then if itemCount < 1 or sourceXPlayer.getAccount(itemName).money < itemCount then
return sourceXPlayer.showNotification(TranslateCap("imp_invalid_amount")) return sourceXPlayer.showNotification(TranslateCap("imp_invalid_amount"))
end end
sourceXPlayer.removeAccountMoney(itemName, itemCount, "Gave to " .. targetXPlayer.name) sourceXPlayer.removeAccountMoney(itemName, itemCount, "Gave to " .. targetXPlayer.name)
targetXPlayer.addAccountMoney(itemName, itemCount, "Received from " .. sourceXPlayer.name) targetXPlayer.addAccountMoney(itemName, itemCount, "Received from " .. sourceXPlayer.name)
@@ -416,8 +417,8 @@ if not Config.CustomInventory then
if targetXPlayer.hasWeapon(itemName) then if targetXPlayer.hasWeapon(itemName) then
sourceXPlayer.showNotification(TranslateCap("gave_weapon_hasalready", targetXPlayer.name, weaponLabel)) sourceXPlayer.showNotification(TranslateCap("gave_weapon_hasalready", targetXPlayer.name, weaponLabel))
targetXPlayer.showNotification(TranslateCap("received_weapon_hasalready", sourceXPlayer.name, weaponLabel)) targetXPlayer.showNotification(TranslateCap("received_weapon_hasalready", sourceXPlayer.name, weaponLabel))
return return
end end
local _, weapon = sourceXPlayer.getWeapon(itemName) local _, weapon = sourceXPlayer.getWeapon(itemName)
local _, weaponObject = ESX.GetWeapon(itemName) local _, weaponObject = ESX.GetWeapon(itemName)
@@ -448,7 +449,7 @@ if not Config.CustomInventory then
end end
elseif itemType == "item_ammo" then elseif itemType == "item_ammo" then
if not sourceXPlayer.hasWeapon(itemName) then if not sourceXPlayer.hasWeapon(itemName) then
return return
end end
local _, weapon = sourceXPlayer.getWeapon(itemName) local _, weapon = sourceXPlayer.getWeapon(itemName)
@@ -456,11 +457,11 @@ if not Config.CustomInventory then
if not targetXPlayer.hasWeapon(itemName) then if not targetXPlayer.hasWeapon(itemName) then
sourceXPlayer.showNotification(TranslateCap("gave_weapon_noweapon", targetXPlayer.name)) sourceXPlayer.showNotification(TranslateCap("gave_weapon_noweapon", targetXPlayer.name))
targetXPlayer.showNotification(TranslateCap("received_weapon_noweapon", sourceXPlayer.name, weapon.label)) targetXPlayer.showNotification(TranslateCap("received_weapon_noweapon", sourceXPlayer.name, weapon.label))
end end
local _, weaponObject = ESX.GetWeapon(itemName) local _, weaponObject = ESX.GetWeapon(itemName)
if not weaponObject.ammo then return end if not weaponObject.ammo then return end
local ammoLabel = weaponObject.ammo.label local ammoLabel = weaponObject.ammo.label
if weapon.ammo >= itemCount then if weapon.ammo >= itemCount then
@@ -486,7 +487,7 @@ if not Config.CustomInventory then
if itemCount > xItem.count or xItem.count < 1 then if itemCount > xItem.count or xItem.count < 1 then
return xPlayer.showNotification(TranslateCap("imp_invalid_quantity")) return xPlayer.showNotification(TranslateCap("imp_invalid_quantity"))
end end
xPlayer.removeInventoryItem(itemName, itemCount) xPlayer.removeInventoryItem(itemName, itemCount)
local pickupLabel = ("%s [%s]"):format(xItem.label, itemCount) local pickupLabel = ("%s [%s]"):format(xItem.label, itemCount)
@@ -509,7 +510,7 @@ if not Config.CustomInventory then
elseif itemType == "item_weapon" then elseif itemType == "item_weapon" then
itemName = string.upper(itemName) itemName = string.upper(itemName)
if not xPlayer.hasWeapon(itemName) then return end if not xPlayer.hasWeapon(itemName) then return end
local _, weapon = xPlayer.getWeapon(itemName) local _, weapon = xPlayer.getWeapon(itemName)
local _, weaponObject = ESX.GetWeapon(itemName) local _, weaponObject = ESX.GetWeapon(itemName)
@@ -536,9 +537,9 @@ if not Config.CustomInventory then
local xPlayer = ESX.GetPlayerFromId(source) local xPlayer = ESX.GetPlayerFromId(source)
local count = xPlayer.getInventoryItem(itemName).count local count = xPlayer.getInventoryItem(itemName).count
if count < 1 then if count < 1 then
return xPlayer.showNotification(TranslateCap("act_imp")) return xPlayer.showNotification(TranslateCap("act_imp"))
end end
ESX.UseItem(source, itemName) ESX.UseItem(source, itemName)
end) end)
@@ -556,8 +557,8 @@ if not Config.CustomInventory then
if pickup.type == "item_standard" then if pickup.type == "item_standard" then
if not xPlayer.canCarryItem(pickup.name, pickup.count) then if not xPlayer.canCarryItem(pickup.name, pickup.count) then
return xPlayer.showNotification(TranslateCap("threw_cannot_pickup")) return xPlayer.showNotification(TranslateCap("threw_cannot_pickup"))
end end
xPlayer.addInventoryItem(pickup.name, pickup.count) xPlayer.addInventoryItem(pickup.name, pickup.count)
success = true success = true
@@ -93,19 +93,21 @@ function ESX.OneSync.SpawnVehicle(model, coords, heading, properties, cb)
if vehicleType then if vehicleType then
local createdVehicle = CreateVehicleServerSetter(vehicleModel, vehicleType, coords.x, coords.y, coords.z, heading) local createdVehicle = CreateVehicleServerSetter(vehicleModel, vehicleType, coords.x, coords.y, coords.z, heading)
local tries = 0 local tries = 0
while not DoesEntityExist(createdVehicle) do
while not createdVehicle or createdVehicle == 0 or not GetEntityCoords(createdVehicle) do
Wait(200) Wait(200)
tries = tries + 1 tries = tries + 1
if tries > 10 then if tries > 20 then
return print("[^1ERROR^7] Unfortunately, this vehicle has not spawned") return error(("Could not spawn vehicle - ^5%s^7!"):format(model))
end end
end end
SetEntityOrphanMode(createdVehicle, 2)
local networkId = NetworkGetNetworkIdFromEntity(createdVehicle) local networkId = NetworkGetNetworkIdFromEntity(createdVehicle)
Entity(createdVehicle).state:set("VehicleProperties", vehicleProperties, true) Entity(createdVehicle).state:set("VehicleProperties", vehicleProperties, true)
cb(networkId) cb(networkId)
else else
print(("[^1ERROR^7] Tried to spawn invalid vehicle - ^5%s^7!"):format(model)) error(("Tried to spawn invalid vehicle - ^5%s^7!"):format(model))
end end
end) end)
end) end)