Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hunger and thirst states desynced from metadata #457

Closed
Demigod916 opened this issue Apr 23, 2024 · 4 comments
Closed

hunger and thirst states desynced from metadata #457

Demigod916 opened this issue Apr 23, 2024 · 4 comments
Labels
bug Something isn't working need repro This bug report needs confirmation

Comments

@Demigod916
Copy link
Contributor

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 Demigod916 added bug Something isn't working need repro This bug report needs confirmation labels Apr 23, 2024
@Demigod916
Copy link
Contributor Author

fix manason pls

@Demigod916
Copy link
Contributor Author

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
Copy link
Contributor Author

Demigod916 commented Apr 23, 2024

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
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working need repro This bug report needs confirmation
Projects
Status: Done
Development

No branches or pull requests

3 participants