vRP inventoryhud question

Hey guys! I’m developing a new version of the inventory hud and i partially made it work.
The problem is that when i use a function that i made to get all the items on vrp (because the inventories, all of them, work using the function built in the script itself letting you remade all the items twice) and try to get the function to trigger, it gives me this strange function that i don’t know if or how to trigger (see screenshots)


any suggestions?

I’m not sure where you got the function getAllItems, as that is not something that is normally in vRP.

However, you can achieve what you are looking to do with the following:

local data = vRP.getUserDataTable({user_id})
if data and data.inventory then
  for k, v in pairs(data.inventory) do
    local item_name = vRP.getItemName({k})
    local name = tostring(k):gsub("%s+", "_")
  end
end

i made the function myself and it’s working. Ty for your answer. I’ll try it

i saw now your code and i notice that you’re gust getting the name of the item from my inventory. I’m already doing this. I want to know if there’s a way to trigger the function that is stored inside the table of the item to let it do it’s things.

I’m sorry, I misunderstood the first time. You then want to use this function: vRP.getItemChoices(idname)

i found that but still this gives me some tables that unpacked gives me the reference to the function, as index to the for, and the id of the function inside vrp as a string.
This is the code.

the only way that i can think of is to create new choices inside the script and then trigger them as nui returns it’s args

This is how I have the inventory hud I’ve worked on a bit looks like:

RegisterServerEvent("adrp_inventory:useItem")
AddEventHandler("adrp_inventory:useItem",function(args)
	local data = args[1]
	local user_id = vRP.getUserId({source})
	local player = vRP.getUserSource({user_id})
	local name = tostring(data.idname):gsub("_", " ")
	local choices = vRP.getItemChoices({name})
	for k, v in pairs(choices) do
		if k ~= "Give" and k ~= "Trash" then
			if k == "Equip" then
				local arr = splitString(tostring(data.idname), "|")[2]
				if vRP.tryGetInventoryItem({user_id, tostring(data.idname), 1, false}) then
					local weapon = {}
					weapon[tostring(arr)] = {ammo = 0}
					vRPclient.giveWeapons(player,{weapon})
				end
			elseif k == "Load" then
				local arr = splitString(tostring(data.idname), "|")[2]
				local amount = vRP.getInventoryItemAmount({user_id, tostring(data.idname)})
				vRP.prompt({player,"How much? Max : ("..amount..")", "", function(player,value)
					value = parseInt(value)
					vRPclient.getWeapons(player, {}, function(equippedweapons)
						if equippedweapons[arr] ~= nil then
							if vRP.tryGetInventoryItem({user_id, tostring(data.idname), value, false}) then -- give weapon ammo
								local weapons = {}
								weapons[arr] = {ammo = value}
								vRPclient.giveWeapons(player, {weapons,false})
							end
						end
					end)
				end})
			else
				local theFunction = v[1]
				for i=1,data.amount do
					theFunction(player, k)
				end
			end
		end
	end 
end)

you solved the issue and i love you. The only part that i used is the

local theFunction = v[1]
				for i=1,data.amount do
					theFunction(player, k)
				end

just because i don’t think i need else. Thank you so much dude!!

1 Like