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
+68 -44
View File
@@ -45,25 +45,6 @@ AddEventHandler('esx:setMaxWeight', function(newMaxWeight)
ESX.PlayerData.maxWeight = newMaxWeight
end)
RegisterNetEvent('esx:createMissingPickups')
AddEventHandler('esx:createMissingPickups', function(missingPickups)
for pickupId,v in pairs(missingPickups) do
ESX.Game.SpawnLocalObject('prop_money_bag_01', v.coords, function(obj)
SetEntityAsMissionEntity(obj, true, false)
PlaceObjectOnGroundProperly(obj)
FreezeEntityPosition(obj, true)
pickups[pickupId] = {
id = pickupId,
obj = obj,
label = v.label,
inRange = false,
coords = vector3(v.coords.x, v.coords.y, v.coords.z)
}
end)
end
end)
AddEventHandler('playerSpawned', function()
while not ESX.PlayerLoaded do
Citizen.Wait(1)
@@ -283,26 +264,78 @@ AddEventHandler('esx:spawnVehicle', function(vehicle)
end
end)
RegisterNetEvent('esx:pickup')
AddEventHandler('esx:pickup', function(id, label, player)
local ped = GetPlayerPed(GetPlayerFromServerId(player))
local coords = GetEntityCoords(ped)
local forward = GetEntityForwardVector(ped)
coords = (coords + forward * 2.0)
RegisterNetEvent('esx:createPickup')
AddEventHandler('esx:createPickup', function(pickupId, label, playerId, type, name, components)
local playerPed = GetPlayerPed(GetPlayerFromServerId(playerId))
local entityCoords, forward, pickupObject = GetEntityCoords(playerPed), GetEntityForwardVector(playerPed)
local objectCoords = (entityCoords + forward * 1.0)
ESX.Game.SpawnLocalObject('prop_money_bag_01', coords, function(obj)
SetEntityAsMissionEntity(obj, true, false)
PlaceObjectOnGroundProperly(obj)
FreezeEntityPosition(obj, true)
if type == 'item_weapon' then
ESX.Streaming.RequestWeaponAsset(GetHashKey(name))
pickupObject = CreateWeaponObject(GetHashKey(name), 50, objectCoords, true, 1.0, 0)
pickups[id] = {
id = id,
obj = obj,
label = label,
for k,v in ipairs(components) do
local component = ESX.GetWeaponComponent(name, v)
GiveWeaponComponentToWeaponObject(pickupObject, component.hash)
end
else
ESX.Game.SpawnLocalObject('prop_money_bag_01', objectCoords, function(obj)
pickupObject = obj
end)
while not pickupObject do
Citizen.Wait(10)
end
end
SetEntityAsMissionEntity(pickupObject, true, false)
PlaceObjectOnGroundProperly(pickupObject)
FreezeEntityPosition(pickupObject, true)
pickups[pickupId] = {
id = pickupId,
obj = pickupObject,
label = label,
inRange = false,
coords = objectCoords
}
end)
RegisterNetEvent('esx:createMissingPickups')
AddEventHandler('esx:createMissingPickups', function(missingPickups)
for pickupId,pickup in pairs(missingPickups) do
local pickupObject = nil
if pickup.type == 'item_weapon' then
ESX.Streaming.RequestWeaponAsset(GetHashKey(pickup.name))
pickupObject = CreateWeaponObject(GetHashKey(pickup.name), 50, pickup.coords.x, pickup.coords.y, pickup.coords.z, true, 1.0, 0)
for k,componentName in ipairs(pickup.components) do
local component = ESX.GetWeaponComponent(pickup.name, componentName)
GiveWeaponComponentToWeaponObject(pickupObject, component.hash)
end
else
ESX.Game.SpawnLocalObject('prop_money_bag_01', pickup.coords, function(obj)
pickupObject = obj
end)
while not pickupObject do
Citizen.Wait(10)
end
end
SetEntityAsMissionEntity(pickupObject, true, false)
PlaceObjectOnGroundProperly(pickupObject)
FreezeEntityPosition(pickupObject, true)
pickups[pickupId] = {
id = pickupId,
obj = pickupObject,
label = pickup.label,
inRange = false,
coords = coords
coords = vector3(pickup.coords.x, pickup.coords.y, pickup.coords.z)
}
end)
end
end)
RegisterNetEvent('esx:removePickup')
@@ -311,15 +344,6 @@ AddEventHandler('esx:removePickup', function(id)
pickups[id] = nil
end)
RegisterNetEvent('esx:pickupWeapon')
AddEventHandler('esx:pickupWeapon', function(weaponPickup, weaponName, ammo)
local playerPed = PlayerPedId()
local pickupCoords = GetOffsetFromEntityInWorldCoords(playerPed, 2.0, 0.0, 0.5)
local weaponHash = GetHashKey(weaponPickup)
CreateAmbientPickup(weaponHash, pickupCoords, 0, ammo, 1, false, true)
end)
RegisterNetEvent('esx:deleteVehicle')
AddEventHandler('esx:deleteVehicle', function(radius)
local playerPed = PlayerPedId()
+1
View File
@@ -37,6 +37,7 @@ Locales['br'] = {
['threw_account'] = 'you threw ~g~$%s~s~ ~b~%s~s~',
['threw_weapon'] = 'you threw ~b~%s~s~',
['threw_weapon_ammo'] = 'you threw ~b~%s~s~ with ~o~%sx~s~ bullets',
['threw_weapon_already'] = 'you already carry the same weapon',
['threw_cannot_pickup'] = 'you cannot pickup that because your inventory is full!',
['threw_pickup_prompt'] = 'press ~y~E~s~ to pickup',
-- Salary related
+1
View File
@@ -37,6 +37,7 @@ Locales['cs'] = {
['threw_account'] = 'you threw ~g~$%s~s~ ~b~%s~s~',
['threw_weapon'] = 'you threw ~b~%s~s~',
['threw_weapon_ammo'] = 'you threw ~b~%s~s~ with ~o~%sx~s~ bullets',
['threw_weapon_already'] = 'you already carry the same weapon',
['threw_cannot_pickup'] = 'you cannot pickup that because your inventory is full!',
['threw_pickup_prompt'] = 'press ~y~E~s~ to pickup',
-- Salary related
+1
View File
@@ -37,6 +37,7 @@ Locales['de'] = {
['threw_account'] = 'you threw ~g~$%s~s~ ~b~%s~s~',
['threw_weapon'] = 'you threw ~b~%s~s~',
['threw_weapon_ammo'] = 'you threw ~b~%s~s~ with ~o~%sx~s~ bullets',
['threw_weapon_already'] = 'you already carry the same weapon',
['threw_cannot_pickup'] = 'you cannot pickup that because your inventory is full!',
['threw_pickup_prompt'] = 'press ~y~E~s~ to pickup',
-- Salary related
+1
View File
@@ -37,6 +37,7 @@ Locales['en'] = {
['threw_account'] = 'you threw ~g~$%s~s~ ~b~%s~s~',
['threw_weapon'] = 'you threw ~b~%s~s~',
['threw_weapon_ammo'] = 'you threw ~b~%s~s~ with ~o~%sx~s~ bullets',
['threw_weapon_already'] = 'you already carry the same weapon',
['threw_cannot_pickup'] = 'you cannot pickup that because your inventory is full!',
['threw_pickup_prompt'] = 'press ~y~E~s~ to pickup',
-- Salary related
+1
View File
@@ -37,6 +37,7 @@ Locales['fi'] = {
['threw_account'] = 'you threw ~g~$%s~s~ ~b~%s~s~',
['threw_weapon'] = 'you threw ~y~1x~s~ ~b~%s~s~',
['threw_weapon_ammo'] = 'you threw ~y~1x~s~ ~b~%s~s~ with ~o~%sx~s~ bullets',
['threw_weapon_already'] = 'you already carry the same weapon',
['threw_cannot_pickup'] = 'you cannot pickup that because your inventory is full!',
['threw_pickup_prompt'] = 'press ~y~E~s~ to pickup',
-- Salary related
+1
View File
@@ -37,6 +37,7 @@ Locales['fr'] = {
['threw_account'] = 'vous avez jeté ~g~$%s~s~ ~b~%s~s~',
['threw_weapon'] = 'vous avez jeté ~y~1x~s~ ~b~%s~s~',
['threw_weapon_ammo'] = 'vous avez jeté ~y~1x~s~ ~b~%s~s~ avec ~o~%sx~s~ balles',
['threw_weapon_already'] = 'you already carry the same weapon',
['threw_cannot_pickup'] = 'you cannot pickup that because your inventory is full!',
['threw_pickup_prompt'] = 'press ~y~E~s~ to pickup',
-- Salary related
+1
View File
@@ -37,6 +37,7 @@ Locales['pl'] = {
['threw_account'] = 'wyrzuciłeś/aś ~g~$%s~s~ ~b~%s~s~',
['threw_weapon'] = 'wyrzuciłeś/aś ~b~%s~s~',
['threw_weapon_ammo'] = 'wyrzuciłeś/aś ~b~%s~s~ z ~o~%sx~s~ nabojami',
['threw_weapon_already'] = 'you already carry the same weapon',
['threw_cannot_pickup'] = 'you cannot pickup that because your inventory is full!',
['threw_pickup_prompt'] = 'press ~y~E~s~ to pickup',
-- Salary related
+1
View File
@@ -37,6 +37,7 @@ Locales['sv'] = {
['threw_account'] = 'du kastade ~g~%s SEK~s~ ~b~%s~s~',
['threw_weapon'] = 'du kastade ~b~%s~s~',
['threw_weapon_ammo'] = 'du kastade ~b~%s~s~ med ~o~%sx~s~ skott',
['threw_weapon_already'] = 'du har redan ett sådant vapen på dig',
['threw_cannot_pickup'] = 'du kan inte plocka upp det på grund av att det kommer ej få plats i ditt förråd!',
['threw_pickup_prompt'] = 'tryck ~y~E~s~ för att plocka upp',
-- Salary related
+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