Probably a simple question but just wondering how you can pull data from an item’s metadata on the client side.
An example of what I’m trying to do. (New to coding and just making a simple script to figure things out)
Server- Sets the metadata
RegisterNetEvent(‘tg_armor:buyvest’, function(playerVest)
exports.ox_inventory:AddItem(source, ‘vest’, 1,
{description = ‘Vest: ‘…playerVest…’’, vest = playerVest}
)
end)
Client- This is where i’m stuck. I’m want to pull the vest metadata from the item and set it as a local.
exports(‘equiparmor’, function()
local playerPed = PlayerPedId()
local playerProp = GetPedDrawableVariation(playerPed, 9)
local playerVest = ???
if playerProp == 0 then
print('not wearing armor')
SetPedComponentVariation(playerPed, 9, playerVest)
return
end
exports('equiparmor', function()
exports.ox_inventory:useItem(data, cb)
if data and data.metadata then
print('Metadata:', json.encode(data.metadata))
else
print('No metadata.')
end
end)
end)
The output should somewhat look like this in your client console
Metadata: {"vest":5,"description":"Vest: 5"}
Make sure you also put the export in the item when used, for example: