I’m trying to figure out how to create an item that will transform another. For example … If i’d like to use rolling paper to roll up weed and give a joint. A useable item from the inventory HUD…
I’m pretty new at scripting and all that so i’m quite lost ! and i looked for tutorials or help but all i find is how to add basic need items like food and drinks that u can consume.
At first i tried to modify the code for those basicneeds items in an attempt. Here’s what i tried:
ESX.RegisterUsableItem(‘rollingpaper’, function(source)
local xPlayer = ESX.GetPlayerFromId(source)
But yeaahh … that didn’t work and i dont really know what else i’d need to add in client files etc… If someone can refer me to a guide or give me an example that i could modify it would be amazing
What exactly didn’t work with this? If esx is not nil and you have the items in your database and inventory it should remove the weed and rolling paper then give you a joint, although its prob best to add some checks to make sure you have these items in your inventory before trying to remove them. I could try help you with that if you would like?
That’d be awesome ! And i just couldnt use the item at all, nothing happened. I’ve set that code in the basic needs script tho … maybe i have to make a script only for that? but then i have no clue what to put as a client file, server file and ressource etc :o
There so here’s what i wrote. I only wrote this in the server.lua of the optional needs script. I don’t know if i gotta add something in the client?
So as you can see my items exist already in the server. If i slide the mortar to the ‘’ use ‘’ button in inventory hud then nothing happens and i get no db or client errors it just does nothing at all
Thats the whole server file. Like i said, i added the mortar part to esx_optionalneeds … Should i make a whole script just for the use of the mortar ? Since its not a drink or a food to go in basic or optional needs? I added what you said at the top but it still doesnt work
ESX.RegisterUsableItem('mortar', function(source)
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer.getInventoryItem('cocaleaves').count > 0 then
xPlayer.removeInventoryItem('cocaleaves', 1)
Citizen.Wait(0)
xPlayer.addInventoryItem('cocapowder', 1)
end
end)
oh ! i’d need the mortar for multiple items i tried to duplicate the script with the items changed but that gave me an error and this doesnt seem to work:
ESX.RegisterUsableItem(‘mortar’, function(source)
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer.getInventoryItem('cocaleaves').count > 0 then
xPlayer.removeInventoryItem('cocaleaves', 10)
Citizen.Wait(0)
xPlayer.addInventoryItem('cocapowder', 1)
or else
if xPlayer.getInventoryItem('opium').count > 0 then
xPlayer.removeInventoryItem('opium', 10)
Citizen.Wait(0)
xPlayer.addInventoryItem('poppypowder', 1)
end
ESX.RegisterUsableItem(‘mortar’, function(source)
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer.getInventoryItem(‘cocaleaves’).count > 0 then
xPlayer.removeInventoryItem(‘cocaleaves’, 10)
Citizen.Wait(0)
xPlayer.addInventoryItem(‘cocapowder’, 1)
ESX.RegisterUsableItem(‘mortar2’, function(source)
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer.getInventoryItem(‘opium’).count > 0 then
xPlayer.removeInventoryItem(‘opium’, 10)
Citizen.Wait(0)
xPlayer.addInventoryItem(‘poppypowder’, 1)
end
end)