mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-02 11:18:53 +00:00
Only add weapon component once, check if player has weapon
This commit is contained in:
+3
-3
@@ -107,7 +107,7 @@ AddEventHandler('esx:restoreLoadout', function()
|
||||
|
||||
for j=1, #ESX.PlayerData.loadout[i].components, 1 do
|
||||
local weaponComponent = ESX.PlayerData.loadout[i].components[j]
|
||||
local componentHash = ESX.GetWeaponComponentHash(weaponName, weaponComponent)
|
||||
local componentHash = ESX.GetWeaponComponent(weaponName, weaponComponent).hash
|
||||
|
||||
GiveWeaponComponentToPed(playerPed, weaponHash, componentHash)
|
||||
end
|
||||
@@ -192,7 +192,7 @@ RegisterNetEvent('esx:addWeaponComponent')
|
||||
AddEventHandler('esx:addWeaponComponent', function(weaponName, weaponComponent)
|
||||
local playerPed = PlayerPedId()
|
||||
local weaponHash = GetHashKey(weaponName)
|
||||
local componentHash = ESX.GetWeaponComponentHash(weaponName, weaponComponent)
|
||||
local componentHash = ESX.GetWeaponComponent(weaponName, weaponComponent).hash
|
||||
|
||||
GiveWeaponComponentToPed(playerPed, weaponHash, componentHash)
|
||||
end)
|
||||
@@ -218,7 +218,7 @@ RegisterNetEvent('esx:removeWeaponComponent')
|
||||
AddEventHandler('esx:removeWeaponComponent', function(weaponName, weaponComponent)
|
||||
local playerPed = PlayerPedId()
|
||||
local weaponHash = GetHashKey(weaponName)
|
||||
local componentHash = ESX.GetWeaponComponentHash(weaponName, weaponComponent)
|
||||
local componentHash = ESX.GetWeaponComponent(weaponName, weaponComponent).hash
|
||||
|
||||
RemoveWeaponComponentFromPed(playerPed, weaponHash, componentHash)
|
||||
end)
|
||||
|
||||
@@ -397,6 +397,11 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, l
|
||||
|
||||
self.addWeaponComponent = function(weaponName, weaponComponent)
|
||||
local loadoutNum, weapon = self.getWeapon(weaponName)
|
||||
|
||||
if self.hasWeaponComponent(weaponName, weaponComponent) then
|
||||
return
|
||||
end
|
||||
|
||||
table.insert(self.loadout[loadoutNum].components, weaponComponent)
|
||||
|
||||
TriggerClientEvent('esx:addWeaponComponent', self.source, weaponName, weaponComponent)
|
||||
@@ -414,12 +419,18 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, l
|
||||
end
|
||||
end
|
||||
|
||||
TriggerClientEvent('esx:removeWeapon', self.source, weaponName, ammo)
|
||||
TriggerClientEvent('esx:removeInventoryItem', self.source, {label = weaponLabel}, 1)
|
||||
if weaponLabel then
|
||||
TriggerClientEvent('esx:removeWeapon', self.source, weaponName, ammo)
|
||||
TriggerClientEvent('esx:removeInventoryItem', self.source, {label = weaponLabel}, 1)
|
||||
end
|
||||
end
|
||||
|
||||
self.removeWeaponComponent = function(weaponName, weaponComponent)
|
||||
local loadoutNum, weapon = self.getWeapon(weaponName)
|
||||
|
||||
if not weapon then
|
||||
return
|
||||
end
|
||||
|
||||
for i=1, #self.loadout[loadoutNum].components, 1 do
|
||||
if self.loadout[loadoutNum].components.name == weaponComponent then
|
||||
@@ -431,6 +442,22 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, l
|
||||
TriggerClientEvent('esx:removeWeaponComponent', self.source, weaponName, weaponComponent)
|
||||
end
|
||||
|
||||
self.hasWeaponComponent = function(weaponName, weaponComponent)
|
||||
local loadoutNum, weapon = self.getWeapon(weaponName)
|
||||
|
||||
if not weapon then
|
||||
return false
|
||||
end
|
||||
|
||||
for i=1, #weapon.components, 1 do
|
||||
if weapon.components[i] == weaponComponent then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
self.hasWeapon = function(weaponName)
|
||||
for i=1, #self.loadout, 1 do
|
||||
if self.loadout[i].name == weaponName then
|
||||
|
||||
@@ -33,7 +33,7 @@ ESX.GetWeaponLabel = function(weaponName)
|
||||
end
|
||||
end
|
||||
|
||||
ESX.GetWeaponComponentHash = function(weaponName, weaponComponent)
|
||||
ESX.GetWeaponComponent = function(weaponName, weaponComponent)
|
||||
weaponName = string.upper(weaponName)
|
||||
local weapons = ESX.GetWeaponList()
|
||||
|
||||
@@ -41,7 +41,7 @@ ESX.GetWeaponComponentHash = function(weaponName, weaponComponent)
|
||||
if weapons[i].name == weaponName then
|
||||
for j=1, #weapons[i].components, 1 do
|
||||
if weapons[i].components[j].name == weaponComponent then
|
||||
return weapons[i].components[j].hash
|
||||
return weapons[i].components[j]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user