Implemented ESX weapon drops with components support, closes #421

This commit is contained in:
ElPumpo
2020-01-04 01:33:12 +01:00
parent 2f75152457
commit fdabf80657
11 changed files with 97 additions and 51 deletions
+7 -3
View File
@@ -160,7 +160,7 @@ ESX.GetItemLabel = function(item)
end
end
ESX.CreatePickup = function(type, name, count, label, playerId)
ESX.CreatePickup = function(type, name, count, label, playerId, components)
local pickupId = (ESX.PickupId == 65635 and 0 or ESX.PickupId + 1)
local xPlayer = ESX.GetPlayerFromId(playerId)
@@ -169,10 +169,14 @@ ESX.CreatePickup = function(type, name, count, label, playerId)
name = name,
count = count,
label = label,
coords = xPlayer.getCoords()
coords = xPlayer.getCoords(),
}
TriggerClientEvent('esx:pickup', -1, pickupId, label, playerId)
if type == 'item_weapon' then
ESX.Pickups[pickupId].components = components
end
TriggerClientEvent('esx:createPickup', -1, pickupId, label, playerId, type, name, components)
ESX.PickupId = pickupId
end
+14 -4
View File
@@ -390,15 +390,14 @@ AddEventHandler('esx:removeInventoryItem', function(type, itemName, itemCount)
elseif type == 'item_weapon' then
if xPlayer.hasWeapon(itemName) then
local weaponNum, weapon = xPlayer.getWeapon(itemName)
local weaponPickup = 'PICKUP_' .. string.upper(itemName)
xPlayer.removeWeapon(itemName)
local pickupLabel = ('~y~%s~s~ [~g~%s~s~ ammo]'):format(weapon.label, weapon.ammo)
ESX.CreatePickup('item_weapon', itemName, weapon.ammo, pickupLabel, playerId, weapon.components)
if weapon.ammo > 0 then
TriggerClientEvent('esx:pickupWeapon', playerId, weaponPickup, itemName, weapon.ammo)
xPlayer.showNotification(_U('threw_weapon_ammo', weapon.label, weapon.ammo))
else
-- workaround for CreateAmbientPickup() giving 30 rounds of ammo when you drop the weapon with 0 ammo
TriggerClientEvent('esx:pickupWeapon', playerId, weaponPickup, itemName, 1)
xPlayer.showNotification(_U('threw_weapon', weapon.label))
end
end
@@ -435,6 +434,17 @@ AddEventHandler('esx:onPickup', function(id)
elseif pickup.type == 'item_account' then
success = true
xPlayer.addAccountMoney(pickup.name, pickup.count)
elseif pickup.type == 'item_weapon' then
if xPlayer.hasWeapon(pickup.name) then
xPlayer.showNotification(_U('threw_weapon_already'))
else
success = true
xPlayer.addWeapon(pickup.name, pickup.count)
for k,v in ipairs(pickup.components) do
xPlayer.addWeaponComponent(pickup.name, v)
end
end
end
if success then