Need some insight as why the below two triggers don’t work inside a SetTimeout. They work perfectly fine outside of it.
TriggerClientEvent('esx_status:add', source, 'thirst', 300000)
TriggerClientEvent('coffeemachine:onDrink', source)
The triggers in the context of the script. Its for a vending machine that I want the dispensed item to be used right away.
RegisterServerEvent('coffeemachine:buyItem')
AddEventHandler('coffeemachine:buyItem', function(price)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local limit = xPlayer.getInventoryItem('coffee').limit
local qtty = xPlayer.getInventoryItem('coffee').count
if xPlayer.getMoney() >= price then
if qtty < limit then
SetTimeout(5000, function()
xPlayer.removeMoney(price)
TriggerClientEvent('esx:showNotification', _source, _U('bought') .. price .. '$~s~.')
-- xPlayer.addInventoryItem('coffee', 1)
end)
SetTimeout(7000, function()
TriggerClientEvent('esx_status:add', source, 'thirst', 300000)
TriggerClientEvent('coffeemachine:onDrink', source)
TriggerClientEvent('esx:showNotification', source, _U('use_coffee'))
-- xPlayer.removeInventoryItem('coffee', 1)
end)
else
TriggerClientEvent('esx:showNotification', _source, _U('max_item'))
end
else
TriggerClientEvent('esx:showNotification', _source, _U('not_enough'))
end
end)
The Triggers in question also don’t work in the first SetTimeout.