Refactor hunger and thirst retrieval logic

Introduced Framework.GetStatusData to centralize status lookup. Updated GetHunger and GetThirst to use the new function, improving code reuse and maintainability.
This commit is contained in:
MrNewb committed 2025-09-10 11:29:41 -04:00
1 parent 87345fafce
commit cfd746d889
1 file changed
+17 -8
+17 -8
View File
@@ -124,22 +124,31 @@ Framework.GetPlayerJobData = function()
} }
end end
--This is an internal function to get status data
--- @param search string
Framework.GetStatusData = function(search)
local playerData = Framework.GetPlayerData()
local status = playerData.variables.status
for _, entry in ipairs(status) do
if entry.name == search then
return entry.percent or 0
end
end
return 0
end
---This will get the hunger of a player ---This will get the hunger of a player
---@return number ---@return number
Framework.GetHunger = function() Framework.GetHunger = function()
local playerData = Framework.GetPlayerData() local status = Framework.GetStatusData("hunger")
if not playerData then return 0 end return math.floor((status) + 0.5) or 0
local status = playerData.variables.status
return math.floor((status.hunger.percent) + 0.5) or 0
end end
---This will get the thirst of a player ---This will get the thirst of a player
---@return number ---@return number
Framework.GetThirst = function() Framework.GetThirst = function()
local playerData = Framework.GetPlayerData() local status = Framework.GetStatusData("thirst")
if not playerData then return 0 end return math.floor((status) + 0.5) or 0
local status = playerData.variables.status
return math.floor((status.thirst.percent) + 0.5) or 0
end end
--- @description This will return if the player has the specified item in their inventory --- @description This will return if the player has the specified item in their inventory