[RELEASE] Stress System with basicneeds

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.

20 Likes

Thats great dude.But how to display stress?

2 Likes

does not require a database to save the stress you have when leaving and when you come back have the same?

I dont think it will effect anything.

work with esx_status like a drunk

I have seen on several servers, that stress has it different in plan, that it goes up little by little and when you reach 100% the character gets with the depressed animation, and to lower the stress you have to go places I specify on the map, for example you go to a bar, while you are in a bar the stress goes down, you can also lower it if you smoke drugs or drink

Another serious thing, can it be shown as in the image?
image

I have seen this code before and tried to deploy it with the UI you mentioned however stress just sits at a quarter of an inch and doesn’t move despite adding the code to add stress

You can set it up.See the topic.

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)

how can i add mythic notify ?

Removed drunk and changed drunk text with stress.Works now.

If you want to remove stress while do anything, add this code on your resource ı dont understood realy

I want it reduced when smoking

I want it to increase when you eat something.
hamburger

how can ı do ?

I have added that too, it just didn’t work. I scrapped the files a few days ago. I will probably try again soon

Refer to your basicneeds folder if i remember right. There you will see the code for how water and food work. Just copy and paste, adjust it for what item you want and the effects you want

1 Like

If you want to reduce stress when you smoke, you have to put this in the smoking code

TriggerClientEvent (‘esx_status: remove’, source, ‘stress’, 100000)

If you want stress to increase when you eat put this code in the eating code

TriggerClientEvent (‘esx_status: add’, source, ‘stress’, 100000)

1 Like

Example for remove stress:

ESX.RegisterUsableItem('yakutka', function(source)

    local xPlayer = ESX.GetPlayerFromId(source)

    xPlayer.removeInventoryItem('yakutka', 1)

    TriggerClientEvent('esx_status:add', source, 'thirst', 50000)
	TriggerClientEvent('esx_status:remove', source, 'stress', 75000)
    TriggerClientEvent('esx_basicneeds:onDrink', source)    

end)
2 Likes

and where would something like that above get entered at?

1 Like

because when I drink water the stress increases? If I do not have it set, I put it as you put it here in the forum, when nothing happens, but if I drink water it increases

esx_fwd_ui.rar (1.4 KB) I just added stress bar… if you need u can take it :wink:

1 Like

Yeah! i love you!

harikasın reis dominodan selamlar . başarılarının devamını dilerim