Add GetHunger and GetThirst functions to frameworks

Introduced GetHunger and GetThirst functions to client and server files for es_extended, qb-core, and qbx_core frameworks. These functions return the player's hunger and thirst values rounded to the nearest integer, improving consistency in status retrieval.
This commit is contained in:
MrNewb committed 2025-09-10 11:29:41 -04:00
1 parent 371ee19445
commit 87345fafce
5 files changed
+58 -4

No files matched your search

+18
View File
@@ -124,6 +124,24 @@ Framework.GetPlayerJobData = function()
}
end
---This will get the hunger of a player
---@return number
Framework.GetHunger = function()
local playerData = Framework.GetPlayerData()
if not playerData then return 0 end
local status = playerData.variables.status
return math.floor((status.hunger.percent) + 0.5) or 0
end
---This will get the thirst of a player
---@return number
Framework.GetThirst = function()
local playerData = Framework.GetPlayerData()
if not playerData then return 0 end
local status = playerData.variables.status
return math.floor((status.thirst.percent) + 0.5) or 0
end
--- @description This will return if the player has the specified item in their inventory
--- @param item string
--- @return boolean
+2 -2
View File
@@ -257,7 +257,7 @@ Framework.GetHunger = function(src)
for _, entry in ipairs(status) do
if entry.name == "hunger" then
return math.floor(entry.percent)
return math.floor((entry.percent) + 0.5) or 0
end
end
end
@@ -271,7 +271,7 @@ Framework.GetThirst = function(src)
for _, entry in ipairs(status) do
if entry.name == "thirst" then
return math.floor(entry.percent)
return math.floor((entry.percent) + 0.5) or 0
end
end
end
+18
View File
@@ -109,6 +109,24 @@ Framework.GetItemInfo = function(item)
return repackedTable
end
---This will get the hunger of a player
---@return number
Framework.GetHunger = function()
local player = Framework.GetPlayerData()
if not player then return 0 end
local playerData = player.PlayerData
return math.floor((playerData.metadata.hunger) + 0.5) or 0
end
---This will get the thirst of a player
---@return number
Framework.GetThirst = function()
local player = Framework.GetPlayerData()
if not player then return 0 end
local playerData = player.PlayerData
return math.floor((playerData.metadata.thirst) + 0.5) or 0
end
---This will get the players identifier (citizenid) etc.
---@return string
Framework.GetPlayerIdentifier = function()
+2 -2
View File
@@ -303,7 +303,7 @@ Framework.GetHunger = function(src)
if not player then return end
local playerData = player.PlayerData
local newHunger = (playerData.metadata.hunger or 0)
return newHunger
return math.floor((newHunger) + 0.5) or 0
end
---This will return a boolean if the player is dead or in last stand.
@@ -335,7 +335,7 @@ Framework.GetThirst = function(src)
if not player then return end
local playerData = player.PlayerData
local newThirst = (playerData.metadata.thirst or 0)
return newThirst
return math.floor((newThirst) + 0.5) or 0
end
-- Framework.GetPlayerPhone(src)
+18
View File
@@ -68,6 +68,24 @@ Framework.Notify = function(message, type, time)
return QBox:Notify("Notification", type, time, message)
end
---This will get the hunger of a player
---@return number
Framework.GetHunger = function()
local player = Framework.GetPlayerData()
if not player then return 0 end
local playerData = player.PlayerData
return math.floor((playerData.metadata.hunger) + 0.5) or 0
end
---This will get the thirst of a player
---@return number
Framework.GetThirst = function()
local player = Framework.GetPlayerData()
if not player then return 0 end
local playerData = player.PlayerData
return math.floor((playerData.metadata.thirst) + 0.5) or 0
end
---This will get the players identifier (citizenid) etc.
---@return string
Framework.GetPlayerIdentifier = function()