Qbox-project / qbx_core

http://qbox-project.github.io
Other
45 stars 109 forks source link

hunger and thirst states desynced from metadata #457

Closed Demigod916 closed 1 month ago

Demigod916 commented 2 months ago

Summary

hunger and thirst states desynced from metadata

Reproduction

  1. log in
  2. have a script affect your hunger/thirst through setMetadata
  3. wait
  4. die

Expected behavior

state and metadata synced for backwards compat.

Actual behavior

dies while hunger and thirst are not empty on hud using metadata

Additional context

assume that this can be fixed with a onMetaChange handler in the core

Current Version

v1.11.0

Custom Resources

.

Demigod916 commented 2 months ago

fix manason pls

Demigod916 commented 2 months ago
AddEventHandler('qbx_core:server:onSetMetaData', function(key, _, new, source)
    if key == 'hunger' or key == 'thirst' or key == 'stress' then
        Player(source).state:set(key, new, true)
    end
end)
Demigod916 commented 2 months ago

nvm looks like the state is being synced in the self.Functions.SetMetaData. but still experiencing the desynced values between metadata and state for status. will work on a repro

Demigod916 commented 2 months ago
local PlayerState = LocalPlayer.state

CreateThread(function ()
    while true do
        print("ON LOOP")
        lib.print.info("STATE:", "HUNGER:", PlayerState.hunger)
        lib.print.info("STATE:", "THIRST:", PlayerState.thirst)

        lib.print.info("META:", "HUNGER:", QBX.PlayerData.metadata.hunger)
        lib.print.info("META:", "THIRST:", QBX.PlayerData.metadata.thirst)
        Wait(500)
        print("========================================================")
    end
end)

RegisterCommand('addhunger', function ()
    TriggerServerEvent('consumables:server:addHunger', QBX.PlayerData.metadata.hunger + 1000) --- this event just sets the hunger using setMetaData function
end)

RegisterCommand('addthirst', function ()
    TriggerServerEvent('consumables:server:addThirst', QBX.PlayerData.metadata.thirst + 1000)--- this event just sets the thirst using setMetaData function
end)

RegisterNetEvent('hud:client:UpdateNeeds', function (hunger, thirst)
    print("ON UPDATE")
    lib.print.info("STATE:", "HUNGER:", PlayerState.hunger)
    lib.print.info("STATE:", "THIRST:", PlayerState.thirst)

    lib.print.info("META:", "HUNGER:", QBX.PlayerData.metadata.hunger)
    lib.print.info("META:", "THIRST:", QBX.PlayerData.metadata.thirst)
    print("========================================================")
end)

here is a repro and then also i made a pr #459