From 39306c2ad667c8838ba3c92d530be1be94dc5092 Mon Sep 17 00:00:00 2001 From: Arctos2win <116841243+Arctos2win@users.noreply.github.com> Date: Thu, 18 Jan 2024 14:44:22 +0100 Subject: [PATCH 1/5] Rewrite LoadESXPlayer --- [core]/es_extended/server/main.lua | 389 +++++++++++++---------------- 1 file changed, 174 insertions(+), 215 deletions(-) diff --git a/[core]/es_extended/server/main.lua b/[core]/es_extended/server/main.lua index 91b25bc71..3bc984d06 100644 --- a/[core]/es_extended/server/main.lua +++ b/[core]/es_extended/server/main.lua @@ -122,252 +122,211 @@ if not Config.Multichar then end) end -function loadESXPlayer(identifier, playerId, isNew) +function loadESXPlayer(identifier, playerId, isNew) local userData = { - accounts = {}, - inventory = {}, - job = {}, - loadout = {}, - playerName = GetPlayerName(playerId), - weight = 0, - metadata = {} - } - local result = MySQL.prepare.await(loadPlayer, { identifier }) - local job, grade, jobObject, gradeObject = result.job, tostring(result.job_grade) - local foundAccounts, foundItems = {}, {} - - -- Accounts - if result.accounts and result.accounts ~= '' then - local accounts = json.decode(result.accounts) - - for account, money in pairs(accounts) do - foundAccounts[account] = money - end - end - - for account, data in pairs(Config.Accounts) do - if data.round == nil then - data.round = true - end - local index = #userData.accounts + 1 - userData.accounts[index] = { - name = account, - money = foundAccounts[account] or Config.StartingAccountMoney[account] or 0, - label = data.label, - round = data.round, - index = index - } - end - - -- Job - if ESX.DoesJobExist(job, grade) then - jobObject, gradeObject = ESX.Jobs[job], ESX.Jobs[job].grades[grade] - else + accounts = {}, + inventory = {}, + loadout = {}, + playerName = GetPlayerName(playerId), + weight = 0, + metadata = {}, + + firstName = 'John', + lastName = 'Doe', + dateofbirth = '01/01/2000', + height = 120, + skin = { sex = 'm' }, + sex = 'm', + group = 'user', + identifier = identifier, + dead = false + } + + local result = MySQL.prepare.await(loadPlayer, { identifier }) + + -- Accounts + local accounts = result.accounts + accounts = accounts and accounts ~= '' and json.decode(accounts) or {} + + for account, data in pairs(Config.Accounts) do + data.round = data.round or data.round == nil + + local index = #userData.accounts + 1 + userData.accounts[index] = { + name = account, + money = accounts[account] or Config.StartingAccountMoney[account] or 0, + label = data.label, + round = data.round, + index = index + } + end + + -- Job + local job, grade = result.job, tostring(result.job_grade) + + if not ESX.DoesJobExist(job, grade) then print(('[^3WARNING^7] Ignoring invalid job for ^5%s^7 [job: ^5%s^7, grade: ^5%s^7]'):format(identifier, job, grade)) - job, grade = 'unemployed', '0' - jobObject, gradeObject = ESX.Jobs[job], ESX.Jobs[job].grades[grade] - end - - userData.job.id = jobObject.id - userData.job.name = jobObject.name - userData.job.label = jobObject.label - - userData.job.grade = tonumber(grade) - userData.job.grade_name = gradeObject.name - userData.job.grade_label = gradeObject.label - userData.job.grade_salary = gradeObject.salary - - userData.job.skin_male = {} - userData.job.skin_female = {} - - if gradeObject.skin_male then - userData.job.skin_male = json.decode(gradeObject.skin_male) - end - if gradeObject.skin_female then - userData.job.skin_female = json.decode(gradeObject.skin_female) - end - - -- Inventory - if not Config.OxInventory then - if result.inventory and result.inventory ~= '' then - local inventory = json.decode(result.inventory) - - for name, count in pairs(inventory) do - local item = ESX.Items[name] - - if item then - foundItems[name] = count - else - print(('[^3WARNING^7] Ignoring invalid item ^5"%s"^7 for ^5"%s^7"'):format(name, identifier)) - end - end - end - - for name, item in pairs(ESX.Items) do - local count = foundItems[name] or 0 - if count > 0 then - userData.weight = userData.weight + (item.weight * count) - end - - table.insert(userData.inventory, - { - name = name, - count = count, - label = item.label, - weight = item.weight, - usable = Core.UsableItemsCallbacks[name] ~= nil, - rare = item.rare, - canRemove = item.canRemove - }) - end + job, grade = 'unemployed', '0' + end + + jobObject, gradeObject = ESX.Jobs[job], ESX.Jobs[job].grades[grade] + + userData.job = { + id = jobObject.id, + name = jobObject.name, + label = jobObject.label, + + grade = tonumber(grade), + grade_name = gradeObject.name, + grade_label = gradeObject.label, + grade_salary = gradeObject.salary, + + skin_male = gradeObject.skin_male and json.decode(gradeObject.skin_male) or {}, + skin_female = gradeObject.skin_female and json.decode(gradeObject.skin_female) or {} + } + + -- Inventory + if result.inventory and result.inventory ~= '' then + if not Config.OxInventory then + local inventory = json.decode(result.inventory) + + for name, count in pairs(inventory) do + local item = ESX.Items[name] + + if count > 0 then + userData.weight += (item.weight * count) + end + + table.insert(userData.inventory, + { + name = name, + count = count, + label = item.label, + weight = item.weight, + usable = Core.UsableItemsCallbacks[name] ~= nil, + rare = item.rare, + canRemove = item.canRemove + }) + end + + table.sort(userData.inventory, function(a, b) + return a.label < b.label + end) + else + userData.inventory = json.decode(result.inventory) + end + end + + -- Group + + if result.group then + if result.group == 'superadmin' then + userData.group = 'admin' + print("[^3WARNING^7] ^5Superadmin^7 detected, setting group to ^5admin^7") + else + userData.group = result.group + end + end + + -- Loadout + if not Config.OxInventory then + if result.loadout and result.loadout ~= '' then + local loadout = json.decode(result.loadout) + + for name, weapon in pairs(loadout) do + local label = ESX.GetWeaponLabel(name) + + if label then + weapon.components = weapon.components or {} + weapon.tintIndex = weapon.tintIndex or 0 + + table.insert(userData.loadout, + { + name = name, + ammo = weapon.ammo, + label = label, + components = weapon.components, + tintIndex = weapon.tintIndex + }) + end + end + end + end + + -- Position + userData.coords = json.decode(result.position) or Config.DefaultSpawns[math.random(#Config.DefaultSpawns)] - table.sort(userData.inventory, function(a, b) - return a.label < b.label - end) - else - if result.inventory and result.inventory ~= '' then - userData.inventory = json.decode(result.inventory) - else - userData.inventory = {} - end + -- Skin + if result.skin and result.skin ~= '' then + userData.skin = json.decode(result.skin) end - -- Group - if result.group then - if result.group == "superadmin" then - userData.group = "admin" - print("[^3WARNING^7] ^5Superadmin^7 detected, setting group to ^5admin^7") - else - userData.group = result.group - end - else - userData.group = 'user' + -- Metadata + if result.metadata and result.metadata ~= '' then + local metadata = json.decode(result.metadata) + userData.metadata = metadata end - -- Loadout - if not Config.OxInventory then - if result.loadout and result.loadout ~= '' then - local loadout = json.decode(result.loadout) + -- xPlayer creation - for name, weapon in pairs(loadout) do - local label = ESX.GetWeaponLabel(name) - - if label then - if not weapon.components then - weapon.components = {} - end - if not weapon.tintIndex then - weapon.tintIndex = 0 - end + local xPlayer = CreateExtendedPlayer(playerId, identifier, userData.group, userData.accounts, userData.inventory, userData.weight, userData.job, userData.loadout, userData.playerName, userData.coords, userData.metadata) + ESX.Players[playerId] = xPlayer + Core.playersByIdentifier[identifier] = xPlayer - table.insert(userData.loadout, - { - name = name, - ammo = weapon.ammo, - label = label, - components = weapon.components, - tintIndex = weapon.tintIndex - }) - end - end - end - end + -- Identity + if result.firstname and result.firstname ~= '' then + userData.firstName = result.firstname + userData.lastName = result.lastname - -- Position - userData.coords = json.decode(result.position) or Config.DefaultSpawns[math.random(#Config.DefaultSpawns)] + xPlayer.set('firstName', result.firstname) + xPlayer.set('lastName', result.lastname) - -- Skin - if result.skin and result.skin ~= '' then - userData.skin = json.decode(result.skin) - else - if userData.sex == 'f' then - userData.skin = { sex = 1 } - else - userData.skin = { sex = 0 } - end - end + userData.playerName = userData.firstName .. ' ' .. userData.lastName + xPlayer.name = userData.playerName - -- Identity - if result.firstname and result.firstname ~= '' then - userData.firstname = result.firstname - userData.lastname = result.lastname - userData.playerName = userData.firstname .. ' ' .. userData.lastname if result.dateofbirth then userData.dateofbirth = result.dateofbirth + xPlayer.set('dateofbirth', result.dateofbirth) end if result.sex then userData.sex = result.sex + xPlayer.set('sex', result.sex) end if result.height then userData.height = result.height + xPlayer.set('height', result.height) end - end + end - if result.metadata and result.metadata ~= '' then - local metadata = json.decode(result.metadata) - userData.metadata = metadata - end - - local xPlayer = CreateExtendedPlayer(playerId, identifier, userData.group, userData.accounts, userData.inventory, userData.weight, userData.job, userData.loadout, userData.playerName, userData.coords, userData.metadata) - ESX.Players[playerId] = xPlayer - Core.playersByIdentifier[identifier] = xPlayer - - if userData.firstname then - xPlayer.set('firstName', userData.firstname) - xPlayer.set('lastName', userData.lastname) - if userData.dateofbirth then - xPlayer.set('dateofbirth', userData.dateofbirth) - end - if userData.sex then - xPlayer.set('sex', userData.sex) - end - if userData.height then - xPlayer.set('height', userData.height) - end - end - --saved player health and armor in metadata - local ped = GetPlayerPed(xPlayer.source) - if ped then + -- Save player health and armor in metadata + local ped = GetPlayerPed(xPlayer.source) + if ped then xPlayer.setMeta('health', xPlayer.getMeta('health') or GetEntityHealth(ped)) xPlayer.setMeta('armor', xPlayer.getMeta('armor') or GetPedArmour(ped)) - end + end + + TriggerEvent('esx:playerLoaded', playerId, xPlayer, isNew) + + userData.maxWeight = xPlayer.getMaxWeight() + money = xPlayer.getMoney() + xPlayer.triggerEvent('esx:playerLoaded',userData, isNew, userData.skin) - TriggerEvent('esx:playerLoaded', playerId, xPlayer, isNew) - - xPlayer.triggerEvent('esx:playerLoaded', - { - accounts = xPlayer.getAccounts(), - coords = userData.coords, - identifier = xPlayer.getIdentifier(), - inventory = xPlayer.getInventory(), - job = xPlayer.getJob(), - loadout = xPlayer.getLoadout(), - maxWeight = xPlayer.getMaxWeight(), - money = xPlayer.getMoney(), - sex = xPlayer.get("sex") or "m", - firstName = xPlayer.get("firstName") or "John", - lastName = xPlayer.get("lastName") or "Doe", - dateofbirth = xPlayer.get("dateofbirth") or "01/01/2000", - height = xPlayer.get("height") or 120, - dead = false, - metadata = xPlayer.getMeta() - }, isNew, - userData.skin) - - if not Config.OxInventory then + if not Config.OxInventory then xPlayer.triggerEvent('esx:createMissingPickups', Core.Pickups) else exports.ox_inventory:setPlayerInventory(xPlayer, userData.inventory) - if isNew then - for account, money in pairs(Config.StartingAccountMoney) do - if account == 'money' or account == 'black_money' then - exports.ox_inventory:AddItem(playerId, account, money) - end - end + local shared = json.decode(GetConvar('inventory:accounts', '["money"]')) + + for i=1, #shared do + local account = Config.StartingAccountMoney[shared[i]] + if account then + exports.ox_inventory:AddItem(playerId, shared[i], account) + end + end end end - xPlayer.triggerEvent('esx:registerSuggestions', Core.RegisteredCommands) + xPlayer.triggerEvent('esx:registerSuggestions', Core.RegisteredCommands) print(('[^2INFO^0] Player ^5"%s"^0 has connected to the server. ID: ^5%s^7'):format(xPlayer.getName(), playerId)) end From 55ec231f292fee2947b17c19c49969f7f69b3f32 Mon Sep 17 00:00:00 2001 From: Arctos2win <116841243+Arctos2win@users.noreply.github.com> Date: Mon, 22 Jan 2024 23:26:04 +0100 Subject: [PATCH 2/5] Update main.lua --- [core]/es_extended/server/main.lua | 274 +++++++++++++---------------- 1 file changed, 124 insertions(+), 150 deletions(-) diff --git a/[core]/es_extended/server/main.lua b/[core]/es_extended/server/main.lua index 3bc984d06..cb8143295 100644 --- a/[core]/es_extended/server/main.lua +++ b/[core]/es_extended/server/main.lua @@ -122,132 +122,121 @@ if not Config.Multichar then end) end -function loadESXPlayer(identifier, playerId, isNew) - local userData = { - accounts = {}, - inventory = {}, - loadout = {}, - playerName = GetPlayerName(playerId), - weight = 0, - metadata = {}, - - firstName = 'John', - lastName = 'Doe', - dateofbirth = '01/01/2000', - height = 120, - skin = { sex = 'm' }, - sex = 'm', - group = 'user', - identifier = identifier, +function loadESXPlayer(identifier, playerId, isNew) + local userData = { + accounts = {}, + inventory = {}, + loadout = {}, + weight = 0, + identifier = identifier, + firstName = 'John', + lastName = 'Doe', + dateofbirth = '01/01/2000', + height = 120, dead = false - } + } - local result = MySQL.prepare.await(loadPlayer, { identifier }) + local result = MySQL.prepare.await(loadPlayer, {identifier}) - -- Accounts - local accounts = result.accounts - accounts = accounts and accounts ~= '' and json.decode(accounts) or {} + -- Accounts + local accounts = result.accounts + accounts = (accounts and accounts ~= '') and json.decode(accounts) or {} for account, data in pairs(Config.Accounts) do data.round = data.round or data.round == nil - local index = #userData.accounts + 1 + local index = #userData.accounts + 1 userData.accounts[index] = { - name = account, - money = accounts[account] or Config.StartingAccountMoney[account] or 0, - label = data.label, - round = data.round, - index = index + name = account, + money = accounts[account] or Config.StartingAccountMoney[account] or + 0, + label = data.label, + round = data.round, + index = index } - end + end -- Job local job, grade = result.job, tostring(result.job_grade) - if not ESX.DoesJobExist(job, grade) then - print(('[^3WARNING^7] Ignoring invalid job for ^5%s^7 [job: ^5%s^7, grade: ^5%s^7]'):format(identifier, job, grade)) + if not ESX.DoesJobExist(job, grade) then + print( + ('[^3WARNING^7] Ignoring invalid job for ^5%s^7 [job: ^5%s^7, grade: ^5%s^7]'):format( + identifier, job, grade)) job, grade = 'unemployed', '0' - end + end jobObject, gradeObject = ESX.Jobs[job], ESX.Jobs[job].grades[grade] - - userData.job = { - id = jobObject.id, - name = jobObject.name, - label = jobObject.label, - - grade = tonumber(grade), - grade_name = gradeObject.name, - grade_label = gradeObject.label, - grade_salary = gradeObject.salary, - skin_male = gradeObject.skin_male and json.decode(gradeObject.skin_male) or {}, - skin_female = gradeObject.skin_female and json.decode(gradeObject.skin_female) or {} + userData.job = { + id = jobObject.id, + name = jobObject.name, + label = jobObject.label, + + grade = tonumber(grade), + grade_name = gradeObject.name, + grade_label = gradeObject.label, + grade_salary = gradeObject.salary, + + skin_male = gradeObject.skin_male and json.decode(gradeObject.skin_male) or + {}, + skin_female = gradeObject.skin_female and + json.decode(gradeObject.skin_female) or {} } - -- Inventory - if result.inventory and result.inventory ~= '' then - if not Config.OxInventory then - local inventory = json.decode(result.inventory) - - for name, count in pairs(inventory) do - local item = ESX.Items[name] - - if count > 0 then - userData.weight += (item.weight * count) - end - - table.insert(userData.inventory, - { - name = name, - count = count, - label = item.label, - weight = item.weight, - usable = Core.UsableItemsCallbacks[name] ~= nil, - rare = item.rare, - canRemove = item.canRemove - }) - end - - table.sort(userData.inventory, function(a, b) - return a.label < b.label - end) - else - userData.inventory = json.decode(result.inventory) - end - end - - -- Group - - if result.group then - if result.group == 'superadmin' then - userData.group = 'admin' - print("[^3WARNING^7] ^5Superadmin^7 detected, setting group to ^5admin^7") - else - userData.group = result.group + -- Inventory + if not Config.OxInventory then + local inventory = (result.inventory and result.inventory ~= '') and json.decode(result.inventory) or {} + + for name, item in pairs(ESX.Items) do + local count = inventory[name] or 0 + userData.weight += (count * item.weight) + + userData.inventory[#userData.inventory + 1] = { + name = name, + count = count, + label = item.label, + weight = item.weight, + usable = Core.UsableItemsCallbacks[name] ~= nil, + rare = item.rare, + canRemove = item.canRemove + } end + table.sort(userData.inventory, function(a, b) + return a.label < b.label + end) + elseif result.inventory and result.inventory ~= '' then + userData.inventory = json.decode(result.inventory) + end + + -- Group + if result.group then + if result.group == "superadmin" then + userData.group = "admin" + print("[^3WARNING^7] ^5Superadmin^7 detected, setting group to ^5admin^7") + else + userData.group = result.group + end + else + userData.group = 'user' end -- Loadout - if not Config.OxInventory then - if result.loadout and result.loadout ~= '' then + if not Config.OxInventory then + if result.loadout and result.loadout ~= '' then local loadout = json.decode(result.loadout) for name, weapon in pairs(loadout) do local label = ESX.GetWeaponLabel(name) if label then - weapon.components = weapon.components or {} - weapon.tintIndex = weapon.tintIndex or 0 - - table.insert(userData.loadout, - { - name = name, + userData.loadout[#userData.loadout + 1] = { + name = name, ammo = weapon.ammo, - label = label, - components = weapon.components, - tintIndex = weapon.tintIndex - }) + label = label, + components = weapon.components or {}, + tintIndex = weapon.tintIndex or 0 + } end end end @@ -257,77 +246,62 @@ function loadESXPlayer(identifier, playerId, isNew) userData.coords = json.decode(result.position) or Config.DefaultSpawns[math.random(#Config.DefaultSpawns)] -- Skin - if result.skin and result.skin ~= '' then - userData.skin = json.decode(result.skin) - end - + userData.skin = (result.skin and result.skin ~= '') and json.decode(result.skin) or { sex = userData.sex == 'f' and 1 or 0} + -- Metadata - if result.metadata and result.metadata ~= '' then - local metadata = json.decode(result.metadata) - userData.metadata = metadata - end - - -- xPlayer creation + userData.metadata = (result.metadata and result.metadata ~= '') and json.decode(result.metadata) or {} - local xPlayer = CreateExtendedPlayer(playerId, identifier, userData.group, userData.accounts, userData.inventory, userData.weight, userData.job, userData.loadout, userData.playerName, userData.coords, userData.metadata) + -- xPlayer Creation + local xPlayer = CreateExtendedPlayer(playerId, identifier, userData.group, userData.accounts, userData.inventory, userData.weight, userData.job, userData.loadout, GetPlayerName(playerId), userData.coords, userData.metadata) ESX.Players[playerId] = xPlayer - Core.playersByIdentifier[identifier] = xPlayer - - -- Identity - if result.firstname and result.firstname ~= '' then - userData.firstName = result.firstname - userData.lastName = result.lastname + Core.playersByIdentifier[identifier] = xPlayer - xPlayer.set('firstName', result.firstname) - xPlayer.set('lastName', result.lastname) + -- Identity + if result.firstname and result.firstname ~= '' then + userData.firstName = result.firstname + userData.lastName = result.lastname - userData.playerName = userData.firstName .. ' ' .. userData.lastName - xPlayer.name = userData.playerName + xPlayer.set('firstName', result.firstname) + xPlayer.set('lastName', result.lastname) + xPlayer.setName(('%s %s'):format(result.firstname, result.lastname)) - if result.dateofbirth then - userData.dateofbirth = result.dateofbirth + if result.dateofbirth then + userData.dateofbirth = result.dateofbirth xPlayer.set('dateofbirth', result.dateofbirth) - end - if result.sex then - userData.sex = result.sex + end + if result.sex then + userData.sex = result.sex xPlayer.set('sex', result.sex) - end - if result.height then - userData.height = result.height + end + if result.height then + userData.height = result.height xPlayer.set('height', result.height) - end - end - - -- Save player health and armor in metadata - local ped = GetPlayerPed(xPlayer.source) - if ped then - xPlayer.setMeta('health', xPlayer.getMeta('health') or GetEntityHealth(ped)) - xPlayer.setMeta('armor', xPlayer.getMeta('armor') or GetPedArmour(ped)) + end end TriggerEvent('esx:playerLoaded', playerId, xPlayer, isNew) - - userData.maxWeight = xPlayer.getMaxWeight() - money = xPlayer.getMoney() - xPlayer.triggerEvent('esx:playerLoaded',userData, isNew, userData.skin) + userData.money = xPlayer.getMoney() + userData.maxWeight = xPlayer.getMaxWeight() + xPlayer.triggerEvent('esx:playerLoaded', userData, isNew, userData.skin) if not Config.OxInventory then - xPlayer.triggerEvent('esx:createMissingPickups', Core.Pickups) - else - exports.ox_inventory:setPlayerInventory(xPlayer, userData.inventory) - if isNew then + xPlayer.triggerEvent('esx:createMissingPickups', Core.Pickups) + else + exports.ox_inventory:setPlayerInventory(xPlayer, userData.inventory) + if isNew then local shared = json.decode(GetConvar('inventory:accounts', '["money"]')) - for i=1, #shared do - local account = Config.StartingAccountMoney[shared[i]] - if account then - exports.ox_inventory:AddItem(playerId, shared[i], account) - end - end - end - end + for i = 1, #shared do + local name = shared[i] + local account = Config.StartingAccountMoney[name] + if account then + exports.ox_inventory:AddItem(playerId, name, account) + end + end + end + end xPlayer.triggerEvent('esx:registerSuggestions', Core.RegisteredCommands) - print(('[^2INFO^0] Player ^5"%s"^0 has connected to the server. ID: ^5%s^7'):format(xPlayer.getName(), playerId)) + print(('[^2INFO^0] Player ^5"%s"^0 has connected to the server. ID: ^5%s^7'):format(xPlayer.getName(), playerId)) end AddEventHandler('chatMessage', function(playerId, _, message) From 0b01cfd287881285b2ed34845e348397defe5911 Mon Sep 17 00:00:00 2001 From: Arctos2win <116841243+Arctos2win@users.noreply.github.com> Date: Wed, 24 Jan 2024 21:14:41 +0100 Subject: [PATCH 3/5] change handling of ox inventory config --- [core]/es_extended/client/common.lua | 4 +--- [core]/es_extended/server/common.lua | 10 +++++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/[core]/es_extended/client/common.lua b/[core]/es_extended/client/common.lua index e18f2884b..0a3fcbeb9 100644 --- a/[core]/es_extended/client/common.lua +++ b/[core]/es_extended/client/common.lua @@ -2,9 +2,7 @@ exports('getSharedObject', function() return ESX end) -if GetResourceState('ox_inventory') ~= 'missing' then - Config.OxInventory = true -end +Config.OxInventory = GetResourceState('ox_inventory'):find('start') and true AddEventHandler("esx:getSharedObject", function() local Invoke = GetInvokingResource() diff --git a/[core]/es_extended/server/common.lua b/[core]/es_extended/server/common.lua index 1f87bf3b4..9d60a35c9 100644 --- a/[core]/es_extended/server/common.lua +++ b/[core]/es_extended/server/common.lua @@ -23,11 +23,11 @@ exports('getSharedObject', function() return ESX end) -if GetResourceState('ox_inventory') ~= 'missing' then - Config.OxInventory = true - Config.PlayerFunctionOverride = 'OxInventory' - SetConvarReplicated('inventory:framework', 'esx') - SetConvarReplicated('inventory:weight', Config.MaxWeight * 1000) +if GetResourceState('ox_inventory'):find('start') then + Config.OxInventory = true + Config.PlayerFunctionOverride = 'OxInventory' + SetConvarReplicated('inventory:framework', 'esx') + SetConvarReplicated('inventory:weight', Config.MaxWeight * 1000) end local function StartDBSync() From e7654914e3141f2c51fb3665c936bab9562f6ced Mon Sep 17 00:00:00 2001 From: Arctos2win <116841243+Arctos2win@users.noreply.github.com> Date: Wed, 24 Jan 2024 21:19:13 +0100 Subject: [PATCH 4/5] don't save player when not spawned --- [core]/es_extended/server/common.lua | 5 +++++ [core]/es_extended/server/functions.lua | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/[core]/es_extended/server/common.lua b/[core]/es_extended/server/common.lua index 9d60a35c9..4a41cd922 100644 --- a/[core]/es_extended/server/common.lua +++ b/[core]/es_extended/server/common.lua @@ -14,6 +14,11 @@ Core.playersByIdentifier = {} Core.vehicleTypesByModel = {} + +RegisterNetEvent('esx:onPlayerSpawn', function() + ESX.Players[source].spawned = true +end) + AddEventHandler("esx:getSharedObject", function() local Invoke = GetInvokingResource() print(("[^1ERROR^7] Resource ^5%s^7 Used the ^5getSharedObject^7 Event, this event ^1no longer exists!^7 Visit https://documentation.esx-framework.org/tutorials/tutorials-esx/sharedevent for how to fix!"):format(Invoke)) diff --git a/[core]/es_extended/server/functions.lua b/[core]/es_extended/server/functions.lua index 87751761f..510be1ed1 100644 --- a/[core]/es_extended/server/functions.lua +++ b/[core]/es_extended/server/functions.lua @@ -171,6 +171,10 @@ local function updateHealthAndArmorInMetadata(xPlayer) end function Core.SavePlayer(xPlayer, cb) + if not xPlayer.spawned then + return cb and cb() + end + updateHealthAndArmorInMetadata(xPlayer) local parameters = { json.encode(xPlayer.getAccounts(true)), From 66379330c01305eb0ca009e3884d1490fc2a504d Mon Sep 17 00:00:00 2001 From: Arctos2win <116841243+Arctos2win@users.noreply.github.com> Date: Wed, 24 Jan 2024 22:22:07 +0100 Subject: [PATCH 5/5] fix player bugging in ground collision at spawn --- [core]/es_extended/client/main.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/[core]/es_extended/client/main.lua b/[core]/es_extended/client/main.lua index 82d2e7459..2e4e1a66a 100644 --- a/[core]/es_extended/client/main.lua +++ b/[core]/es_extended/client/main.lua @@ -52,7 +52,9 @@ AddEventHandler('esx:playerLoaded', function(xPlayer, isNew, skin) ESX.PlayerLoaded = true while ESX.PlayerData.ped == nil do Wait(20) end - + + while not HasCollisionLoadedAroundEntity(ESX.PlayerData.ped) do Wait(0) end + if Config.EnablePVP then SetCanAttackFriendly(ESX.PlayerData.ped, true, false) NetworkSetFriendlyFireOption(true)