v1.2 installation
The functions listed below are taken from the default ESX resources, giving you both the original function to search for and the new function with the required changes made. You're best off looking at the changes yourself and modifying your own code so you don't overwrite any existing modifications required by other resources.
FILE: es_extended/client/functions.lua
ESX.ShowInventory
Original:
ESX.ShowInventory = function()
local playerPed = PlayerPedId()
local elements, currentWeight = {}, 0
for k,v in pairs(ESX.PlayerData.accounts) do
if v.money > 0 then
local formattedMoney = _U('locale_currency', ESX.Math.GroupDigits(v.money))
local canDrop = v.name ~= 'bank'
table.insert(elements, {
label = ('%s: <span style="color:green;">%s</span>'):format(v.label, formattedMoney),
count = v.money,
type = 'item_account',
value = v.name,
usable = false,
rare = false,
canRemove = canDrop
})
end
end
for k,v in ipairs(ESX.PlayerData.inventory) do
if v.count > 0 then
currentWeight = currentWeight + (v.weight * v.count)
table.insert(elements, {
label = ('%s x%s'):format(v.label, v.count),
count = v.count,
type = 'item_standard',
value = v.name,
usable = v.usable,
rare = v.rare,
canRemove = v.canRemove
})
end
end
for k,v in ipairs(Config.Weapons) do
local weaponHash = GetHashKey(v.name)
if HasPedGotWeapon(playerPed, weaponHash, false) then
local ammo, label = GetAmmoInPedWeapon(playerPed, weaponHash)
if v.ammo then
label = ('%s - %s %s'):format(v.label, ammo, v.ammo.label)
else
label = v.label
end
table.insert(elements, {
label = label,
count = 1,
type = 'item_weapon',
value = v.name,
usable = false,
rare = false,
ammo = ammo,
canGiveAmmo = (v.ammo ~= nil),
canRemove = true
})
end
end
ESX.UI.Menu.CloseAll()
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'inventory', {
title = _U('inventory', currentWeight, ESX.PlayerData.maxWeight),
align = 'bottom-right',
elements = elements
}, function(data, menu)
menu.close()
local player, distance = ESX.Game.GetClosestPlayer()
local elements = {}
if data.current.usable then
table.insert(elements, {label = _U('use'), action = 'use', type = data.current.type, value = data.current.value})
end
if data.current.canRemove then
if player ~= -1 and distance <= 3.0 then
table.insert(elements, {label = _U('give'), action = 'give', type = data.current.type, value = data.current.value})
end
table.insert(elements, {label = _U('remove'), action = 'remove', type = data.current.type, value = data.current.value})
end
if data.current.type == 'item_weapon' and data.current.canGiveAmmo and data.current.ammo > 0 and player ~= -1 and distance <= 3.0 then
table.insert(elements, {label = _U('giveammo'), action = 'give_ammo', type = data.current.type, value = data.current.value})
end
table.insert(elements, {label = _U('return'), action = 'return'})
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'inventory_item', {
title = data.current.label,
align = 'bottom-right',
elements = elements,
}, function(data1, menu1)
local item, type = data1.current.value, data1.current.type
if data1.current.action == 'give' then
local playersNearby = ESX.Game.GetPlayersInArea(GetEntityCoords(playerPed), 3.0)
if #playersNearby > 0 then
local players, elements = {}, {}
for k,player in ipairs(playersNearby) do
players[GetPlayerServerId(player)] = true
end
ESX.TriggerServerCallback('esx:getPlayerNames', function(returnedPlayers)
for playerId,playerName in pairs(returnedPlayers) do
table.insert(elements, {
label = playerName,
playerId = playerId
})
end
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'give_item_to', {
title = _U('give_to'),
align = 'bottom-right',
elements = elements
}, function(data2, menu2)
local selectedPlayer, selectedPlayerId = GetPlayerFromServerId(data2.current.playerId), data2.current.playerId
playersNearby = ESX.Game.GetPlayersInArea(GetEntityCoords(playerPed), 3.0)
playersNearby = ESX.Table.Set(playersNearby)
if playersNearby[selectedPlayer] then
local selectedPlayerPed = GetPlayerPed(selectedPlayer)
if IsPedOnFoot(selectedPlayerPed) then
if type == 'item_weapon' then
TriggerServerEvent('esx:giveInventoryItem', selectedPlayerId, type, item, nil)
menu2.close()
menu1.close()
else
ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'inventory_item_count_give', {
title = _U('amount')
}, function(data3, menu3)
local quantity = tonumber(data3.value)
if quantity then
TriggerServerEvent('esx:giveInventoryItem', selectedPlayerId, type, item, quantity)
menu3.close()
menu2.close()
menu1.close()
else
ESX.ShowNotification(_U('amount_invalid'))
end
end, function(data3, menu3)
menu3.close()
end)
end
else
ESX.ShowNotification(_U('in_vehicle'))
end
else
ESX.ShowNotification(_U('players_nearby'))
menu2.close()
end
end, function(data2, menu2)
menu2.close()
end)
end, players)
else
ESX.ShowNotification(_U('players_nearby'))
end
elseif data1.current.action == 'remove' then
if IsPedOnFoot(playerPed) then
local dict, anim = 'weapons@first_person@aim_rng@generic@projectile@sticky_bomb@', 'plant_floor'
ESX.Streaming.RequestAnimDict(dict)
if type == 'item_weapon' then
menu1.close()
TaskPlayAnim(playerPed, dict, anim, 8.0, 1.0, 1000, 16, 0.0, false, false, false)
Citizen.Wait(1000)
TriggerServerEvent('esx:removeInventoryItem', type, item)
else
ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'inventory_item_count_remove', {
title = _U('amount')
}, function(data2, menu2)
local quantity = tonumber(data2.value)
if quantity then
menu2.close()
menu1.close()
TaskPlayAnim(playerPed, dict, anim, 8.0, 1.0, 1000, 16, 0.0, false, false, false)
Citizen.Wait(1000)
TriggerServerEvent('esx:removeInventoryItem', type, item, quantity)
else
ESX.ShowNotification(_U('amount_invalid'))
end
end, function(data2, menu2)
menu2.close()
end)
end
end
elseif data1.current.action == 'use' then
TriggerServerEvent('esx:useItem', item)
elseif data1.current.action == 'return' then
ESX.UI.Menu.CloseAll()
ESX.ShowInventory()
elseif data1.current.action == 'give_ammo' then
local closestPlayer, closestDistance = ESX.Game.GetClosestPlayer()
local closestPed = GetPlayerPed(closestPlayer)
local pedAmmo = GetAmmoInPedWeapon(playerPed, GetHashKey(item))
if IsPedOnFoot(closestPed) then
if closestPlayer ~= -1 and closestDistance < 3.0 then
if pedAmmo > 0 then
ESX.UI.Menu.Open('dialog', GetCurrentResourceName(), 'inventory_item_count_give', {
title = _U('amountammo')
}, function(data2, menu2)
local quantity = tonumber(data2.value)
if quantity then
if pedAmmo >= quantity and quantity > 0 then
TriggerServerEvent('esx:giveInventoryItem', GetPlayerServerId(closestPlayer), 'item_ammo', item, quantity)
menu2.close()
menu1.close()
else
ESX.ShowNotification(_U('noammo'))
end
else
ESX.ShowNotification(_U('amount_invalid'))
end
end, function(data2, menu2)
menu2.close()
end)
else
ESX.ShowNotification(_U('noammo'))
end
else
ESX.ShowNotification(_U('players_nearby'))
end
else
ESX.ShowNotification(_U('in_vehicle'))
end
end
end, function(data1, menu1)
ESX.UI.Menu.CloseAll()
ESX.ShowInventory()
end)
end, function(data, menu)
menu.close()
end)
end
Modified:
ESX.ShowInventory = function()
exports["fz-inventory"]:openInventory()
end
FILE: es_extended/server/functions.lua
FILE: es_extended/server/commands.lua
es_extended/server/main.lua
es_extended/server/classes/player.lua
Last updated