Thought I would share this since I’ve seen it asked here and there.
Please note the animation sucks and im sure this could be greatly improved but it does work.
I’ll update this when I’ve improved it.
Requirements:
esx_basicneeds
linden-inventory (only if using this inventory of course, you may have a diff requirement)
Step #1: Follow this for adding stress system:
Add the following in esx_basicneeds\server\main.lua:
ESX.RegisterUsableItem('cigarette', function(source)
local xPlayer = ESX.GetPlayerFromId(source)
xPlayer.removeInventoryItem('cigarette', 1)
TriggerClientEvent('esx_status:remove', source, 'stress', 100000)
TriggerClientEvent('esx_basicneeds:onSmoke', source)
xPlayer.showNotification(_U('used_cigarette'))
end)
Add the following to esx_basicneeds\client\main.lua:
RegisterNetEvent('esx_basicneeds:onSmoke')
AddEventHandler('esx_basicneeds:onSmoke', function(prop_name)
if not IsAnimated then
prop_name = prop_name or 'ng_proc_cigarette01a'
IsAnimated = true
Citizen.CreateThread(function()
local playerPed = PlayerPedId()
local x,y,z = table.unpack(GetEntityCoords(playerPed))
local prop = CreateObject(GetHashKey(prop_name), x, y, z + 0.2, true, true, true)
local boneIndex = GetPedBoneIndex(playerPed, 18905)
AttachEntityToEntity(prop, playerPed, boneIndex, 0.12, 0.028, 0.001, 10.0, 175.0, 0.0, true, true, false, true, 1, true)
ESX.Streaming.RequestAnimDict('amb@world_human_aa_smoke@male@idle_a', function()
TaskStartScenarioInPlace(playerPed, 'WORLD_HUMAN_SMOKING', 0, false)
Citizen.Wait(3000)
IsAnimated = false
ClearPedSecondaryTask(playerPed)
DeleteObject(prop)
end)
end)
end
end)
For linden-inventory users:
linden_inventory\shared\items.lua:
['cigarette'] = {
removeStress = 200000,
animDict = 'amb@world_human_aa_smoke@male@idle_a',
anim = 'idle_a',
model = 'ng_proc_cigarette01a',
coords = { x = 0.03, y = 0.0, z = 0.02 },
rotation = { x = 0.0, y = -13.5, z = -1.5 },
useTime = 2500,
event = 'linden_inventory:cigarette'
},
linden_inventory\client\main.lua:
if data.stress then
TriggerEvent('esx_status:add', 'stress', data.stress)
end
if data.removeStress then
TriggerEvent('esx_status:remove', 'stress', data.removeStress)
end