Skip to content

Commit

Permalink
fix: save alcohol metadata as it decays
Browse files Browse the repository at this point in the history
  • Loading branch information
TonybynMp4 committed Feb 18, 2024
1 parent a971f68 commit ddc0148
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ local function drunkLoop()
drunkEffect(severity)
end

Wait(1000 * 60 * config.alcoholDecayTime)
Wait(60000 * config.alcoholDecayTime)

if alcoholLevel > 0 then
alcoholLevel -= config.alcoholDecayAmount
Expand Down
8 changes: 8 additions & 0 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,12 @@ end
RegisterNetEvent('QBCore:Server:OnPlayerLoaded', function()
local player = exports.qbx_core:GetPlayer(source)
Player(source).state:set('alcohol', player.PlayerData.metadata.alcohol, true)
end)

AddStateBagChangeHandler('alcohol', nil, function(bagName, key, value)
local source = GetPlayerFromStateBagName(bagName)
if source == 0 then return end
local player = exports.qbx_core:GetPlayer(source)
if not player then return end
player.Functions.SetMetaData('alcohol', value)
end)

0 comments on commit ddc0148

Please sign in to comment.