Refactor hunger and thirst retrieval methods
Simplified Framework.GetHunger and Framework.GetThirst functions in both qb-core and qbx_core by using Framework.GetPlayerMetaData instead of accessing player data directly. This improves code readability and consistency.
This commit is contained in:
1 parent
08c3d937d6
commit
f4e5d9485f
2 files changed
+8
-16
No files matched your search
@@ -112,19 +112,15 @@ 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 player = Framework.GetPlayerData()
|
local hunger = Framework.GetPlayerMetaData("hunger") or 0
|
||||||
if not player then return 0 end
|
return math.floor((hunger) + 0.5) or 0
|
||||||
local playerData = player.PlayerData
|
|
||||||
return math.floor((playerData.metadata.hunger) + 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 player = Framework.GetPlayerData()
|
local thirst = Framework.GetPlayerMetaData("thirst") or 0
|
||||||
if not player then return 0 end
|
return math.floor((thirst) + 0.5) or 0
|
||||||
local playerData = player.PlayerData
|
|
||||||
return math.floor((playerData.metadata.thirst) + 0.5) or 0
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---This will get the players identifier (citizenid) etc.
|
---This will get the players identifier (citizenid) etc.
|
||||||
|
|||||||
@@ -71,19 +71,15 @@ 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 player = Framework.GetPlayerData()
|
local hunger = Framework.GetPlayerMetaData("hunger") or 0
|
||||||
if not player then return 0 end
|
return math.floor((hunger) + 0.5) or 0
|
||||||
local playerData = player.PlayerData
|
|
||||||
return math.floor((playerData.metadata.hunger) + 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 player = Framework.GetPlayerData()
|
local thirst = Framework.GetPlayerMetaData("thirst") or 0
|
||||||
if not player then return 0 end
|
return math.floor((thirst) + 0.5) or 0
|
||||||
local playerData = player.PlayerData
|
|
||||||
return math.floor((playerData.metadata.thirst) + 0.5) or 0
|
|
||||||
end
|
end
|
||||||
|
|
||||||
---This will get the players identifier (citizenid) etc.
|
---This will get the players identifier (citizenid) etc.
|
||||||
|
|||||||
Reference in new issue
Block a user