mirror of
https://github.com/qbcore-fivem/qb-core.git
synced 2026-08-28 17:01:16 +00:00
optimize(loops): use core playerdata
This commit is contained in:
+7
-6
@@ -1,23 +1,24 @@
|
||||
CreateThread(function()
|
||||
while true do
|
||||
Wait(0)
|
||||
local sleep = 0
|
||||
if LocalPlayer.state.isLoggedIn then
|
||||
Wait((1000 * 60) * QBCore.Config.UpdateInterval)
|
||||
sleep = (1000 * 60) * QBCore.Config.UpdateInterval
|
||||
TriggerServerEvent('QBCore:UpdatePlayer')
|
||||
end
|
||||
Wait(sleep)
|
||||
end
|
||||
end)
|
||||
|
||||
CreateThread(function()
|
||||
while true do
|
||||
Wait(QBCore.Config.StatusInterval)
|
||||
local PlayerData = QBCore.Functions.GetPlayerData()
|
||||
if LocalPlayer.state.isLoggedIn then
|
||||
if (PlayerData.metadata['hunger'] <= 0 or PlayerData.metadata['thirst'] <= 0) and (not PlayerData.metadata['isdead']) then
|
||||
if (QBCore.PlayerData.metadata['hunger'] <= 0 or QBCore.PlayerData.metadata['thirst'] <= 0) and not QBCore.PlayerData.metadata['isdead'] then
|
||||
local ped = PlayerPedId()
|
||||
local currentHealth = GetEntityHealth(ped)
|
||||
SetEntityHealth(ped, currentHealth - math.random(5, 10))
|
||||
local decreaseTreshold = math.random(5, 10)
|
||||
SetEntityHealth(ped, currentHealth - decreaseTreshold)
|
||||
end
|
||||
end
|
||||
Wait(QBCore.Config.StatusInterval)
|
||||
end
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user