Hey,
I wanted to release the stress system which I have also used with my representer. The stress system causes the character to get into stress and the screen to get shaken as some certain processes which also you can determine are done. Similarly It is a system that enables getting rid of the system with some other processes. For instance when a gun is fired your stress level increases but when you smoke it decreases.
I will share below how the system works. It is in your hands to make additions or omittions by protecting the logic behind.
esx_basicneeds/client/main.lua 12-28
AddEventHandler('esx_basicneeds:resetStatus', function()
TriggerEvent('esx_status:set', 'hunger', 500000)
TriggerEvent('esx_status:set', 'thirst', 500000)
TriggerEvent('esx_status:set', 'stress', 100000)
end)
RegisterNetEvent('esx_basicneeds:healPlayer')
AddEventHandler('esx_basicneeds:healPlayer', function()
-- restore hunger & thirst
TriggerEvent('esx_status:set', 'hunger', 1000000)
TriggerEvent('esx_status:set', 'thirst', 1000000)
TriggerEvent('esx_status:set', 'stress', 200000)
-- restore hp
local playerPed = PlayerPedId()
SetEntityHealth(playerPed, GetEntityMaxHealth(playerPed))
end)
esx_basicneeds/client/main.lua 42-114
AddEventHandler('esx_status:loaded', function(status)
TriggerEvent('esx_status:registerStatus', 'hunger', 1000000, '#CFAD0F', function(status)
return true
end, function(status)
status.remove(100)
end)
TriggerEvent('esx_status:registerStatus', 'thirst', 1000000, '#0C98F1', function(status)
return true
end, function(status)
status.remove(75)
end)
TriggerEvent('esx_status:registerStatus', 'stress', 100000, '#cadfff', function(status)
return false
end, function(status)
status.add(20)
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(1000)
local playerPed = PlayerPedId()
local prevHealth = GetEntityHealth(playerPed)
local health = prevHealth
local stressVal = 0
TriggerEvent('esx_status:getStatus', 'hunger', function(status)
if status.val == 0 then
if prevHealth <= 150 then
health = health - 5
else
health = health - 1
end
end
end)
TriggerEvent('esx_status:getStatus', 'thirst', function(status)
if status.val == 0 then
if prevHealth <= 150 then
health = health - 5
else
health = health - 1
end
end
end)
TriggerEvent('esx_status:getStatus', 'stress', function(status)
stressVal = status.val
end)
if health ~= prevHealth then
SetEntityHealth(playerPed, health)
end
if stressVal >= 750000 then
Citizen.Wait(3000)
ShakeGameplayCam('LARGE_EXPLOSION_SHAKE', 0.16)
elseif stressVal >= 700000 then
Citizen.Wait(4000)
ShakeGameplayCam('LARGE_EXPLOSION_SHAKE', 0.12)
elseif stressVal >= 600000 then
Citizen.Wait(5000)
ShakeGameplayCam('LARGE_EXPLOSION_SHAKE', 0.07)
elseif stressVal >= 350000 then
Citizen.Wait(6000)
ShakeGameplayCam('LARGE_EXPLOSION_SHAKE', 0.03)
end
end
end)
end)
If you put this code in basicneeds you’re ready for stress system.
If you want to add stress while do anything, add this code on your resource:
TriggerClientEvent(‘esx_status:add’, source, ‘stress’, 100000)
If you want to remove stress while do anything, add this code on your resource:
TriggerClientEvent(‘esx_status:remove’, source, ‘stress’, 100000)
If you want to display stress bar you can use esx_fwd_ui
Sorry about my bad English, have a good day.