Initial support for weapon components

This commit is contained in:
ElPumpo
2018-12-29 02:10:37 +01:00
parent e5124676be
commit caec057954
5 changed files with 118 additions and 62 deletions
+38 -19
View File
@@ -380,20 +380,14 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, l
end
self.addWeapon = function(weaponName, ammo)
local weaponLabel = weaponName
for i=1, #Config.Weapons, 1 do
if Config.Weapons[i].name == weaponName then
weaponLabel = Config.Weapons[i].label
break
end
end
local weaponLabel = ESX.GetWeaponLabel(weaponName)
if not self.hasWeapon(weaponName) then
table.insert(self.loadout, {
name = weaponName,
ammo = ammo,
label = weaponLabel
name = weaponName,
ammo = ammo,
label = weaponLabel,
components = {}
})
end
@@ -401,18 +395,20 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, l
TriggerClientEvent('esx:addInventoryItem', self.source, {label = weaponLabel}, 1)
end
self.removeWeapon = function(weaponName, ammo)
local weaponLabel = weaponName
self.addWeaponComponent = function(weaponName, weaponComponent)
local loadoutNum, weapon = self.getWeapon(weaponName)
table.insert(self.loadout[loadoutNum].components, weaponComponent)
for i=1, #Config.Weapons, 1 do
if Config.Weapons[i].name == weaponName then
weaponLabel = Config.Weapons[i].label
break
end
end
TriggerClientEvent('esx:addWeaponComponent', self.source, weaponName, weaponComponent)
end
self.removeWeapon = function(weaponName, ammo)
local weaponLabel
for i=1, #self.loadout, 1 do
if self.loadout[i].name == weaponName then
weaponLabel = self.loadout[i].label
table.remove(self.loadout, i)
break
end
@@ -422,6 +418,19 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, l
TriggerClientEvent('esx:removeInventoryItem', self.source, {label = weaponLabel}, 1)
end
self.removeWeaponComponent = function(weaponName, weaponComponent)
local loadoutNum, weapon = self.getWeapon(weaponName)
for i=1, #self.loadout[loadoutNum].components, 1 do
if self.loadout[loadoutNum].components.name == weaponComponent then
table.remove(self.loadout[loadoutNum].components, i)
break
end
end
TriggerClientEvent('esx:removeWeaponComponent', self.source, weaponName, weaponComponent)
end
self.hasWeapon = function(weaponName)
for i=1, #self.loadout, 1 do
if self.loadout[i].name == weaponName then
@@ -432,5 +441,15 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, l
return false
end
self.getWeapon = function(weaponName)
for i=1, #self.loadout, 1 do
if self.loadout[i].name == weaponName then
return i, self.loadout[i]
end
end
return nil
end
return self
end