โFirst Time Setup
IF YOU ARE USING OX, TGIANN, OR QS INVENTORY THEN SKIP THIS!!
ox_inventory, tgiann-inventory, and qs-inventory users will automatically get this functionality without additional changes due to the hooks or events that these inventories provide upon use of an item. If you use any of the above inventories and also follow these steps, then your addiction value changes will get doubled, since each item use will trigger two addiction updates
Update to your core script
For anyone not using ox_inventory you'll need to update the UseItem function in your core script to add an extra export. This is so envi-addictions knows when an item has been used and will be able to run the addiction checks upon use. If you do not do this, your addictions will not work!
Navigate to
qb-core/server/functions.luaFind the
QBCore.Functions.UseItemfunctionThis should be around line 504, but could differ depending on your version
Add the following export to the bottom of the function:
exports['envi-addictions']:UsedItem(source, item)For example, if you're using qb-inventory then your updated function should look like this:
function QBCore.Functions.UseItem(source, item) if GetResourceState('qb-inventory') == 'missing' then return end exports['qb-inventory']:UseItem(source, item) -- This might differ depending on what inventory you're using exports['envi-addictions']:UsedItem(source, item) -- MAKE SURE YOU ADD THIS LINE end
Only do this if you are NOT using ox_inventory
Navigate to
[core]/es_extended/server/functions.luaFind the
ESX.UseItemfunctionShould be around line 515
Replace that function with the following:
function ESX.UseItem(source, item, ...) if ESX.Items[item] then local itemCallback = Core.UsableItemsCallbacks[item] if itemCallback then local success, result = pcall(itemCallback, source, item, ...) if not success then return result and print(result) or print(('[^3WARNING^7] An error occured when using item ^5"%s"^7! This was not caused by ESX.'):format(item)) end exports['envi-addictions']:UsedItem(source, item) -- NEWLY ADDED LINE end else print(('[^3WARNING^7] Item ^5"%s"^7 was used but does not exist!'):format(item)) end end
There isn't an equivalent function to update in QBox, since that's pretty much hard coded to use ox_inventory, so if for some reason you switched to a different inventory then you might need to reach out in our discord to get some assistance with that
Last updated