mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-04 08:13:21 +00:00
Implemented weapon tint support (desc), closes #477
- Implemented two new xPlayer functions: - .getWeaponTint(weaponName) - .setWeaponTint(weaponName, weaponTintIndex) Thanks to @profex1999 for co authoring this! Co-Authored-By: Andrea Passarini <profex1999@users.noreply.github.com>
This commit is contained in:
co-authored by
Andrea Passarini
parent
8e13cf6613
commit
baa9ca3afc
@@ -375,7 +375,8 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, c
|
||||
name = weaponName,
|
||||
ammo = ammo,
|
||||
label = weaponLabel,
|
||||
components = {}
|
||||
components = {},
|
||||
tintIndex = 0
|
||||
})
|
||||
|
||||
self.triggerEvent('esx:addWeapon', weaponName, ammo)
|
||||
@@ -408,6 +409,30 @@ function CreateExtendedPlayer(player, accounts, inventory, job, loadout, name, c
|
||||
end
|
||||
end
|
||||
|
||||
self.setWeaponTint = function(weaponName, weaponTintIndex)
|
||||
local loadoutNum, weapon = self.getWeapon(weaponName)
|
||||
|
||||
if weapon then
|
||||
local weaponNum, weaponObject = ESX.GetWeapon(weaponName)
|
||||
|
||||
if weaponObject.tints and weaponObject.tints[weaponTintIndex] then
|
||||
self.loadout[loadoutNum].tintIndex = weaponTintIndex
|
||||
self.triggerEvent('esx:setWeaponTint', weaponName, weaponTintIndex)
|
||||
self.triggerEvent('esx:addInventoryItem', weaponObject.tints[weaponTintIndex], false, true)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
self.getWeaponTint = function(weaponName)
|
||||
local loadoutNum, weapon = self.getWeapon(weaponName)
|
||||
|
||||
if weapon then
|
||||
return weapon.tintIndex
|
||||
end
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
self.removeWeapon = function(weaponName, ammo)
|
||||
local weaponLabel
|
||||
|
||||
|
||||
@@ -159,7 +159,7 @@ ESX.GetItemLabel = function(item)
|
||||
end
|
||||
end
|
||||
|
||||
ESX.CreatePickup = function(type, name, count, label, playerId, components)
|
||||
ESX.CreatePickup = function(type, name, count, label, playerId, components, tintIndex)
|
||||
local pickupId = (ESX.PickupId == 65635 and 0 or ESX.PickupId + 1)
|
||||
local xPlayer = ESX.GetPlayerFromId(playerId)
|
||||
|
||||
@@ -173,9 +173,10 @@ ESX.CreatePickup = function(type, name, count, label, playerId, components)
|
||||
|
||||
if type == 'item_weapon' then
|
||||
ESX.Pickups[pickupId].components = components
|
||||
ESX.Pickups[pickupId].tintIndex = tintIndex
|
||||
end
|
||||
|
||||
TriggerClientEvent('esx:createPickup', -1, pickupId, label, playerId, type, name, components)
|
||||
TriggerClientEvent('esx:createPickup', -1, pickupId, label, playerId, type, name, components, tintIndex)
|
||||
ESX.PickupId = pickupId
|
||||
end
|
||||
|
||||
|
||||
+4
-4
@@ -159,9 +159,8 @@ AddEventHandler('es:playerLoaded', function(playerId, player)
|
||||
|
||||
-- Compatibility with old loadouts prior to components update
|
||||
for k,v in ipairs(userData.loadout) do
|
||||
if v.components == nil then
|
||||
v.components = {}
|
||||
end
|
||||
if not v.components then v.components = {} end
|
||||
if not v.tintIndex then v.tintIndex = 0 end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -404,7 +403,7 @@ AddEventHandler('esx:removeInventoryItem', function(type, itemName, itemCount)
|
||||
xPlayer.showNotification(_U('threw_weapon', weapon.label))
|
||||
end
|
||||
|
||||
ESX.CreatePickup('item_weapon', itemName, weapon.ammo, pickupLabel, playerId, weapon.components)
|
||||
ESX.CreatePickup('item_weapon', itemName, weapon.ammo, pickupLabel, playerId, weapon.components, weapon.tintIndex)
|
||||
end
|
||||
end
|
||||
end)
|
||||
@@ -445,6 +444,7 @@ AddEventHandler('esx:onPickup', function(id)
|
||||
else
|
||||
success = true
|
||||
xPlayer.addWeapon(pickup.name, pickup.count)
|
||||
xPlayer.setWeaponTint(pickup.name, pickup.tintIndex)
|
||||
|
||||
for k,v in ipairs(pickup.components) do
|
||||
xPlayer.addWeaponComponent(pickup.name, v)
|
||||
|
||||
Reference in New Issue
Block a user