feat: sync player data inv & loadout

This commit is contained in:
Kenshin13
2025-08-13 13:46:44 +02:00
parent 2c285e1d09
commit 216f648482
3 changed files with 60 additions and 0 deletions
@@ -196,6 +196,25 @@ if not Config.CustomInventory then
end
end)
ESX.SecureNetEvent("esx:addLoadoutItem", function(weaponName, weaponLabel, ammo)
table.insert(ESX.PlayerData.loadout, {
name = weaponName,
ammo = ammo,
label = weaponLabel,
components = {},
tintIndex = 0,
})
end)
ESX.SecureNetEvent("esx:removeLoadoutItem", function(weaponName, weaponLabel)
for i = 1, #ESX.PlayerData.loadout do
if ESX.PlayerData.loadout[i].name == weaponName then
table.remove(ESX.PlayerData.loadout, i)
break
end
end
end)
RegisterNetEvent("esx:addWeapon", function()
error("event ^5'esx:addWeapon'^1 Has Been Removed. Please use ^5xPlayer.addWeapon^1 Instead!")
end)
+39
View File
@@ -48,6 +48,45 @@ if not IsDuplicityVersion() then -- Only register this event for the client
ESX.PlayerData = {}
end)
if not ESX.GetConfig("CustomInventory") then
ESX.SecureNetEvent("esx:addInventoryItem", function(item, count, showNotification)
for k, v in ipairs(ESX.PlayerData.inventory) do
if v.name == item then
ESX.PlayerData.inventory[k].count = count
break
end
end
end)
ESX.SecureNetEvent("esx:removeInventoryItem", function(item, count, showNotification)
for i = 1, #ESX.PlayerData.inventory do
if ESX.PlayerData.inventory[i].name == item then
ESX.PlayerData.inventory[i].count = count
break
end
end
end)
ESX.SecureNetEvent("esx:addLoadoutItem", function(weaponName, weaponLabel, ammo)
table.insert(ESX.PlayerData.loadout, {
name = weaponName,
ammo = ammo,
label = weaponLabel,
components = {},
tintIndex = 0,
})
end)
ESX.SecureNetEvent("esx:removeLoadoutItem", function(weaponName, weaponLabel)
for i = 1, #ESX.PlayerData.loadout do
if ESX.PlayerData.loadout[i].name == weaponName then
table.remove(ESX.PlayerData.loadout, i)
break
end
end
end)
end
local external = { { "Class", "class.lua" }, { "Point", "point.lua" } }
for i = 1, #external do
local module = external[i]
@@ -580,6 +580,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
GiveWeaponToPed(GetPlayerPed(self.source), joaat(weaponName), ammo, false, false)
self.triggerEvent("esx:addInventoryItem", weaponLabel, false, true)
self.triggerEvent("esx:addLoadoutItem", weaponName, weaponLabel, ammo)
end
end
@@ -692,6 +693,7 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
if weaponLabel then
self.triggerEvent("esx:removeInventoryItem", weaponLabel, false, true)
self.triggerEvent("esx:removeLoadoutItem", weaponName, weaponLabel)
end
end