Need help ! Trying to figure out how to create a useable item that transform another

ok so by typing mortar2 it gives it a second task ? I’ll try that !

it doesnt work :confused: i think that mortar2 makes it as if i had to have an item named mortar2 and not a second function :confused:

1 Like

No, it would be another item, but there is no other way for that, you can’t say if you use the item you get for example coke and then if you use it again you get a second item.

ok :slight_smile: i thought there was a way, i did create a second item ! Again thank you so much for your help :slight_smile:

No problem, you are welcome :wink:

i get
restart esx_optionalneeds Stopping resource esx_optionalneeds Creating script environments for esx_optionalneeds Error parsing script @esx_optionalneeds/server/main.lua in resource esx_optionalneeds: @esx_optionalneeds/server/main.lua:55: ‘end’ expected (to close ‘function’ at line 12) near Failed to load script server/main.lua. Started resource esx_optionalneeds

this is my code
ESX.RegisterUsableItem(‘drugscale’, function(source)

local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer.getInventoryItem(‘blunt’).count and xPlayer.getInventoryItem(‘trimmedweed’).count > 0 then
xPlayer.removeInventoryItem(‘blunt’, 1)
xPlayer.removeInventoryItem(‘trimmedweed’, 1)
Citizen.Wait(0)
xPlayer.addInventoryItem(‘weed’, 1)
end
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)

Are they written like this in your script? if so your error is simple, your end doesn’t end your code. That’s why your get this error. Your coding should look like this:

ESX.RegisterUsableItem(‘drugscale’, function(source)
local xPlayer = ESX.GetPlayerFromId(source)

   if xPlayer.getInventoryItem(‘blunt’).count and xPlayer.getInventoryItem(‘trimmedweed’).count > 0 then
              xPlayer.removeInventoryItem(‘blunt’, 1)
               xPlayer.removeInventoryItem(‘trimmedweed’, 1)
              Citizen.Wait(0)
              xPlayer.addInventoryItem(‘weed’, 1)
    end

end)

Here look at this:

1

See how the ‘‘if’’ on line 96 drops a line down to end and the ESX.register drop to end) ?
That’s what you want. The sequence of if the play get this or this item then do this and this have to end and then the whole ‘‘event’’ too :slight_smile:

Also, you’re telling your script that as long as the player gets over 0 opium it can remove 10 and give a powder which makes no sens.

If you want 10 opium removed for a powder you want your line to be
if xPlayer.getInventoryItem(‘opium’).count >= 10 then

Same goes for your blunt and trimmed weed.
if xPlayer.getInventoryItem(‘blunt’).count and xPlayer.getInventoryItem(‘trimmedweed’).count >= 1 then

If you want 10 opium removed for a powder you want your line to be
if xPlayer.getInventoryItem(‘opium’).count >= 10 then

Same goes for your blunt and trimmed weed.
if xPlayer.getInventoryItem(‘blunt’).count and xPlayer.getInventoryItem(‘trimmedweed’).count >= 1 then

hey that worked thaks sorry im new to this fivem stuff
ESX.RegisterUsableItem(‘grinder’, function(source)
local xPlayer = ESX.GetPlayerFromId(source)

if xPlayer.getInventoryItem(‘bluntwraps’).count and xPlayer.getInventoryItem(‘trimmedweed’).count > 0 then
xPlayer.removeInventoryItem(‘bluntwraps’, 1)
xPlayer.removeInventoryItem(‘trimmedweed’, 1)
Citizen.Wait(0)
xPlayer.addInventoryItem(‘blunt’, 3)
end
end)
ESX.RegisterUsableItem(‘grinder’, function(source)
local xPlayer = ESX.GetPlayerFromId(source)

if xPlayer.getInventoryItem(‘rawcones’).count and xPlayer.getInventoryItem(‘trimmedweed’).count > 0 then
xPlayer.removeInventoryItem(‘rawcones’, 1)
xPlayer.removeInventoryItem(‘trimmedweed’, 1)
Citizen.Wait(0)
xPlayer.addInventoryItem(‘weed’, 3)
end
end)
ESX.RegisterUsableItem(‘grinder’, function(source)
local xPlayer = ESX.GetPlayerFromId(source)

if xPlayer.getInventoryItem(‘bluntwraps’).count and xPlayer.getInventoryItem(‘cookies’).count > 0 then
xPlayer.removeInventoryItem(‘bluntwraps’, 1)
xPlayer.removeInventoryItem(‘cookies’, 1)
Citizen.Wait(0)
xPlayer.addInventoryItem(‘blunt1’, 3)
end
end)
ESX.RegisterUsableItem(‘grinder’, function(source)
local xPlayer = ESX.GetPlayerFromId(source)

if xPlayer.getInventoryItem(‘rawcones’).count and xPlayer.getInventoryItem(‘cookies’).count > 0 then
xPlayer.removeInventoryItem(‘rawcones’, 1)
xPlayer.removeInventoryItem(‘cookies’, 1)
Citizen.Wait(0)
xPlayer.addInventoryItem(‘joint’, 3)
end
end)
ESX.RegisterUsableItem(‘grinder’, function(source)
local xPlayer = ESX.GetPlayerFromId(source)

if xPlayer.getInventoryItem(‘bluntwraps’).count and xPlayer.getInventoryItem(‘runtz’).count > 0 then
xPlayer.removeInventoryItem(‘bluntwraps’, 1)
xPlayer.removeInventoryItem(‘runtz’, 1)
Citizen.Wait(0)
xPlayer.addInventoryItem(‘blunt2’, 3)
end
end)
ESX.RegisterUsableItem(‘grinder’, function(source)
local xPlayer = ESX.GetPlayerFromId(source)

if xPlayer.getInventoryItem(‘rawcones’).count and xPlayer.getInventoryItem(‘runtz’).count > 0 then
xPlayer.removeInventoryItem(‘rawcones’, 1)
xPlayer.removeInventoryItem(‘runtz’, 1)
Citizen.Wait(0)
xPlayer.addInventoryItem(‘joint1’, 3)
end
end)

thats my code and no matter what i have on me if i have cones or blunt or anytype of weed it always gives me a joint any ideas on what to change