#hunger and thirst
1 messages · Page 1 of 1 (latest)
Hi. Check qb-hud ( most probably ) search for hunger and thirst and anything related to damage while thirsty or hungry. Anyhow Ill give a solution a bit later when I get to my pc.
i tried that but i can´t find nothing related with damage in qb-hud
Alright, if you could hang on for a bit and Ill send you a full code which youll just copy and paste.
Just tell me, how default are your qb resources?
In about an hour or so. Stay tuned
Ill be on in a few minutes
i think i found it
CreateThread(function()
while true do
Wait(1000)
if LocalPlayer.state['isLoggedIn'] then
if QBCore.Functions.GetPlayerData().metadata['hunger'] <= 0 or QBCore.Functions.GetPlayerData().metadata['thirst'] <= 0 then
local ped = PlayerPedId()
local currentHealth = GetEntityHealth(ped)
SetEntityHealth(ped, currentHealth - math.random(5, 10))
end
end
end
end)
qb-core/client/loops.lua ?
Based on your code, just copy and overwrite it with this:
CreateThread(function()
while true do
Wait(1000)
if LocalPlayer.state['isLoggedIn'] then
local ped = PlayerPedId()
local playerData = QBCore.Functions.GetPlayerData()
local hunger = playerData.metadata['hunger'] or 100
local thirst = playerData.metadata['thirst'] or 100
local currentHealth = GetEntityHealth(ped)
if hunger <= 0 or thirst <= 0 then
if currentHealth > 120 then
SetEntityHealth(ped, currentHealth - math.random(5, 10))
end
end
end
end
end)
This should make your idea what you are looking for
If hunger is 0 and thirst 0 , the health starts dropping to 10% , or in other words 20hp. Stays that way. The only way for them to die is to take damage from gunshot and other stuff.
Let me know if it works so we can mark this post as resolved.
@vital hollow is working! Thanks!
Good, glad we've done this. Enjoy and happy coding 🙂 👏
one more think
Yes?
if i want to change instead of 10% (20hp) for 50% (100hp) what i have to change? just to understand
I'll write you down a little table so you remember:
Health Limit 10 % ----> currentHealth > 120
Health Limit 25% -----> currentHealth > 150
Health Limit 50% -----> currentHealth > 150
Health Limit 75 % ----> currentHealth > 175
The formula for this would be :
healthLimit = 100 + (200 * DesiredPercentage)