Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
feat: convert health to math + minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
demxnn committed Feb 20, 2022
1 parent f74b15d commit e50ab07
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@ local playerId = PlayerId()
local GeneralLoop = function()
CreateThread(function()
while ESX.PlayerLoaded do
local ped = PlayerPedId()

local underwaterTime = GetPlayerUnderwaterTimeRemaining(playerId) * 10

local isDriving = IsPedInAnyVehicle(ped, true)
local veh = isDriving and GetVehiclePedIsUsing(ped, false)
local isDriving = IsPedInAnyVehicle(ESX.PlayerData.ped, true)
local veh = isDriving and GetVehiclePedIsUsing(ESX.PlayerData.ped, false)
local speedMultiplier = isDriving and dx.metricSystem and 3.6 or 2.236936

SendNUIMessage({
action = "general",
-- ped
hp = GetEntityHealth(ped) - 100, -- refer to README.md for a better health management
armour = GetPedArmour(ped),
oxygen = IsPedSwimmingUnderWater(ped) and underwaterTime or 100,
hp = (GetEntityHealth(ESX.PlayerData.ped) - 100) * 100 / (GetEntityMaxHealth(ESX.PlayerData.ped) - 100),
armour = GetPedArmour(ESX.PlayerData.ped),
oxygen = IsPedSwimmingUnderWater(ESX.PlayerData.ped) and underwaterTime or 100,
-- vehicles
speedometer = isDriving and
{
Expand All @@ -42,21 +39,16 @@ end

local StatusLoop = function()
CreateThread(function()
local hunger, thirst, stress

while ESX.PlayerLoaded do
local hunger, thirst, stress = false, false, false
local statusReady = false

TriggerEvent('esx_status:getStatus', 'hunger', function(status) hunger = status.val / 10000 end)
TriggerEvent('esx_status:getStatus', 'thirst', function(status) thirst = status.val / 10000 end)
if dx.showStress then
TriggerEvent('esx_status:getStatus', 'stress', function(status) stress = status.val / 10000 end)
end

repeat
statusReady = dx.showStress and hunger and thirst and stress or hunger and thirst
Wait(100)
until statusReady

SendNUIMessage({
action = "status",
-- status
Expand Down

0 comments on commit e50ab07

Please # to comment.