Skip to content

Commit

Permalink
feat: use statebags (#24)
Browse files Browse the repository at this point in the history
* feat: use statebags

* Update main.lua

* Update fxmanifest.lua

* fix: use qbx lib
  • Loading branch information
TonybynMp4 authored Apr 4, 2024
1 parent 5b872ac commit e123880
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
38 changes: 34 additions & 4 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ local cruiseOn = false
local showAltitude = false
local showSeatbelt = false
local nos = 0
local stress = 0
local hunger = 100
local thirst = 100
local playerState = LocalPlayer.state
local stress = playerState.stress or 0
local hunger = playerState.hunger or 100
local thirst = playerState.thirst or 100
local cashAmount = 0
local bankAmount = 0
local nitroActive = 0
Expand Down Expand Up @@ -435,15 +436,29 @@ RegisterNetEvent('hud:client:ToggleAirHud', function()
showAltitude = not showAltitude
end)

---@deprecated Use statebags instead
RegisterNetEvent('hud:client:UpdateNeeds', function(newHunger, newThirst) -- Triggered in qb-core
hunger = newHunger
thirst = newThirst
end)

RegisterNetEvent('hud:client:UpdateStress', function(newStress) -- Add this event with adding stress elsewhere
AddStateBagChangeHandler('hunger', ('player:%s'):format(cache.serverId), function(_, _, value)
hunger = value
end)

AddStateBagChangeHandler('thirst', ('player:%s'):format(cache.serverId), function(_, _, value)
thirst = value
end)

---@deprecated Use statebags instead
RegisterNetEvent('hud:client:UpdateStress', function(newStress)
stress = newStress
end)

AddStateBagChangeHandler('stress', ('player:%s'):format(cache.serverId), function(_, _, value)
stress = value
end)

RegisterNetEvent('hud:client:ToggleShowSeatbelt', function()
showSeatbelt = not showSeatbelt
end)
Expand All @@ -452,11 +467,26 @@ RegisterNetEvent('seatbelt:client:ToggleCruise', function() -- Triggered in smal
cruiseOn = not cruiseOn
end)

---@deprecated Use statebags instead
RegisterNetEvent('hud:client:UpdateNitrous', function(_, nitroLevel, bool)
nos = nitroLevel
nitroActive = bool
end)

qbx.entityStateHandler('nitroFlames', function(veh, netId, value)
local plate = qbx.string.trim(GetVehicleNumberPlateText(veh))
local cachePlate = qbx.string.trim(GetVehicleNumberPlateText(cache.vehicle))
if plate ~= cachePlate then return end
nitroActive = value
end)

qbx.entityStateHandler('nitro', function(veh, netId, value)
local plate = qbx.string.trim(GetVehicleNumberPlateText(veh))
local cachePlate = qbx.string.trim(GetVehicleNumberPlateText(cache.vehicle))
if plate ~= cachePlate then return end
nos = value
end)

RegisterNetEvent('hud:client:UpdateHarness', function(harnessHp)
hp = harnessHp
end)
Expand Down
1 change: 1 addition & 0 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ox_lib 'locale'

shared_scripts {
'@ox_lib/init.lua',
'@qbx_core/modules/lib.lua',
}

client_scripts {
Expand Down

0 comments on commit e123880

Please sign in to comment.