Skip to content

Commit

Permalink
!tweak(es_extended): another attempt to mitigate vehicle creation issues
Browse files Browse the repository at this point in the history
Note: this increases the Minimum Artifact to 10188
  • Loading branch information
Mycroft-Studios committed Nov 5, 2024
1 parent 856ee5e commit b5e0474
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 33 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"Lua.diagnostics.globals": [
"MySQL",
"GetPlayerTimeOnline"
"GetPlayerTimeOnline",
"SetEntityOrphanMode"
]
}
12 changes: 9 additions & 3 deletions [core]/es_extended/client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,16 @@ AddStateBagChangeHandler("VehicleProperties", nil, function(bagName, _, value)
error("Tried to set vehicle properties with invalid netId")
return
end

local vehicle = NetToVeh(netId)
if not DoesEntityExist(vehicle) then
error("Tried to set vehicle properties with invalid vehicle")
return

local tries = 0
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

if not NetworkGetEntityOwner(vehicle) == ESX.playerId then
Expand Down
51 changes: 26 additions & 25 deletions [core]/es_extended/server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ end

local function onPlayerJoined(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.")
end
end

if ESX.GetPlayerFromIdentifier(identifier) then
DropPlayer(
Expand Down Expand Up @@ -102,8 +102,9 @@ if not Config.Multichar then
local playerId = source
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

if oneSyncState == "off" or oneSyncState == "legacy" then
Expand Down Expand Up @@ -226,8 +227,8 @@ function loadESXPlayer(identifier, playerId, isNew)
-- Loadout
if not Config.CustomInventory then
if not result.loadout or result.loadout == "" then
return
end
return
end

local loadout = json.decode(result.loadout)
for name, weapon in pairs(loadout) do
Expand Down Expand Up @@ -292,8 +293,8 @@ function loadESXPlayer(identifier, playerId, isNew)

if not Config.CustomInventory then
xPlayer.triggerEvent("esx:createMissingPickups", Core.Pickups)
elseif setPlayerInventory then
setPlayerInventory(playerId, xPlayer, userData.inventory, isNew)
elseif setPlayerInventory then
setPlayerInventory(playerId, xPlayer, userData.inventory, isNew)
end

xPlayer.triggerEvent("esx:registerSuggestions", Core.RegisteredCommands)
Expand Down Expand Up @@ -384,23 +385,23 @@ if not Config.CustomInventory then
if itemType == "item_standard" then
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"))
end

if not targetXPlayer.canCarryItem(itemName, itemCount) then
if not targetXPlayer.canCarryItem(itemName, itemCount) then
return sourceXPlayer.showNotification(TranslateCap("ex_inv_lim", targetXPlayer.name))
end
end

sourceXPlayer.removeInventoryItem(itemName, itemCount)
targetXPlayer.addInventoryItem(itemName, itemCount)

sourceXPlayer.showNotification(TranslateCap("gave_item", itemCount, sourceItem.label, targetXPlayer.name))
targetXPlayer.showNotification(TranslateCap("received_item", itemCount, sourceItem.label, sourceXPlayer.name))
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"))
end
end

sourceXPlayer.removeAccountMoney(itemName, itemCount, "Gave to " .. targetXPlayer.name)
targetXPlayer.addAccountMoney(itemName, itemCount, "Received from " .. sourceXPlayer.name)
Expand All @@ -416,8 +417,8 @@ if not Config.CustomInventory then
if targetXPlayer.hasWeapon(itemName) then
sourceXPlayer.showNotification(TranslateCap("gave_weapon_hasalready", targetXPlayer.name, weaponLabel))
targetXPlayer.showNotification(TranslateCap("received_weapon_hasalready", sourceXPlayer.name, weaponLabel))
return
end
return
end

local _, weapon = sourceXPlayer.getWeapon(itemName)
local _, weaponObject = ESX.GetWeapon(itemName)
Expand Down Expand Up @@ -448,19 +449,19 @@ if not Config.CustomInventory then
end
elseif itemType == "item_ammo" then
if not sourceXPlayer.hasWeapon(itemName) then
return
return
end

local _, weapon = sourceXPlayer.getWeapon(itemName)

if not targetXPlayer.hasWeapon(itemName) then
sourceXPlayer.showNotification(TranslateCap("gave_weapon_noweapon", targetXPlayer.name))
targetXPlayer.showNotification(TranslateCap("received_weapon_noweapon", sourceXPlayer.name, weapon.label))
end
end

local _, weaponObject = ESX.GetWeapon(itemName)

if not weaponObject.ammo then return end
if not weaponObject.ammo then return end

local ammoLabel = weaponObject.ammo.label
if weapon.ammo >= itemCount then
Expand All @@ -486,7 +487,7 @@ if not Config.CustomInventory then

if itemCount > xItem.count or xItem.count < 1 then
return xPlayer.showNotification(TranslateCap("imp_invalid_quantity"))
end
end

xPlayer.removeInventoryItem(itemName, itemCount)
local pickupLabel = ("%s [%s]"):format(xItem.label, itemCount)
Expand All @@ -509,7 +510,7 @@ if not Config.CustomInventory then
elseif itemType == "item_weapon" then
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 _, weaponObject = ESX.GetWeapon(itemName)
Expand All @@ -536,9 +537,9 @@ if not Config.CustomInventory then
local xPlayer = ESX.GetPlayerFromId(source)
local count = xPlayer.getInventoryItem(itemName).count

if count < 1 then
return xPlayer.showNotification(TranslateCap("act_imp"))
end
if count < 1 then
return xPlayer.showNotification(TranslateCap("act_imp"))
end

ESX.UseItem(source, itemName)
end)
Expand All @@ -556,8 +557,8 @@ if not Config.CustomInventory then

if pickup.type == "item_standard" then
if not xPlayer.canCarryItem(pickup.name, pickup.count) then
return xPlayer.showNotification(TranslateCap("threw_cannot_pickup"))
end
return xPlayer.showNotification(TranslateCap("threw_cannot_pickup"))
end

xPlayer.addInventoryItem(pickup.name, pickup.count)
success = true
Expand Down
10 changes: 6 additions & 4 deletions [core]/es_extended/server/modules/onesync.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,21 @@ function ESX.OneSync.SpawnVehicle(model, coords, heading, properties, cb)
if vehicleType then
local createdVehicle = CreateVehicleServerSetter(vehicleModel, vehicleType, coords.x, coords.y, coords.z, heading)
local tries = 0
while not DoesEntityExist(createdVehicle) do

while not createdVehicle or createdVehicle == 0 or not GetEntityCoords(createdVehicle) do
Wait(200)
tries = tries + 1
if tries > 10 then
return print("[^1ERROR^7] Unfortunately, this vehicle has not spawned")
if tries > 20 then
return error(("Could not spawn vehicle - ^5%s^7!"):format(model))
end
end

SetEntityOrphanMode(createdVehicle, 2)
local networkId = NetworkGetNetworkIdFromEntity(createdVehicle)
Entity(createdVehicle).state:set("VehicleProperties", vehicleProperties, true)
cb(networkId)
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)
Expand Down

0 comments on commit b5e0474

Please sign in to comment.