Skip to content

Commit

Permalink
Merge branch 'main' into lastLoggedOut
Browse files Browse the repository at this point in the history
  • Loading branch information
TonybynMp4 authored Mar 7, 2024
2 parents 8fec446 + d5d0f98 commit 40f2e44
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
9 changes: 5 additions & 4 deletions client/main.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
local config = require('config.client')
local sharedConfig = require('config.shared')
local alcoholLevel = LocalPlayer.state.alcohol or 0
local playerWalk
local playerState = LocalPlayer.state
local alcoholLevel = playerState.alcohol or 0
local playerWalk

local function resetEffect()
exports.scully_emotemenu:setWalk(playerWalk or 'move_m@casual@a')
Expand Down Expand Up @@ -102,7 +102,8 @@ lib.callback.register('consumables:client:DrinkAlcohol', function(params)
end)

AddStateBagChangeHandler('alcohol', ('player:%s'):format(cache.serverId), function(_, _, value)
if alcoholLevel <= 0 and value > 0 then
if type(value) ~= 'number' then return end
if (not alcoholLevel or alcoholLevel <= 0) and value > 0 then
alcoholLevel = value
SetTimeout(config.delayEffect, drunkLoop)
return
Expand All @@ -127,4 +128,4 @@ AddEventHandler('onResourceStart', function(resource)
resetEffect()
end
end
end)
end)
4 changes: 2 additions & 2 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ game 'gta5'
description 'qbx_alcoholism'
authors 'Tonybyn_Mp4'
repository 'https://github.com/TonybynMp4/qbx_alcoholism'
version '1.0.0'
version '1.0.1'

shared_scripts {
'@ox_lib/init.lua',
Expand All @@ -25,4 +25,4 @@ files {
}

lua54 'yes'
use_experimental_fxv2_oal 'yes'
use_experimental_fxv2_oal 'yes'
13 changes: 6 additions & 7 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,12 @@ for alcohol, params in pairs(config.alcoholItems) do
local drank = lib.callback.await('consumables:client:DrinkAlcohol', source, { anim = params.anim, prop = params.prop, stressRelief = params.stressRelief})
if not drank then return end
if not exports.ox_inventory:RemoveItem(source, item.name, 1, nil, item.slot) then return end
local sustenance = playerState.thirst + math.random(params.min, params.max)
playerState:set('thirst', sustenance, true)
local sustenance = player.PlayerData.metadata.thirst + math.random(params.min, params.max)
player.Functions.SetMetaData('thirst', sustenance)

local alcoholTolerance = player.PlayerData.metadata.alcoholTolerance or 0
-- you can build tolerance to reduce up to 50% of the alcohol level
local newAlcohol = playerState.alcohol + ((params.alcoholLevel / 2) * (1 - alcoholTolerance)) + (params.alcoholLevel / 2)
local newAlcohol = (playerState.alcohol or 0) + ((params.alcoholLevel / 2) * (1 - alcoholTolerance)) + (params.alcoholLevel / 2)

playerState:set('alcohol', newAlcohol, true)
player.Functions.SetMetaData('alcohol', newAlcohol)
Expand All @@ -34,8 +33,6 @@ for alcohol, params in pairs(config.alcoholItems) do
exports.qbx_core:Notify(source, 'You feel like you can handle your liquor better now', 'success')
end

playerState:set('stress', playerState.stress - math.random(params.stressRelief.min, params.stressRelief.max), true)

TriggerClientEvent('hud:client:UpdateNeeds', source, player.PlayerData.metadata.thirst, sustenance)
end)
end
Expand Down Expand Up @@ -91,13 +88,15 @@ RegisterNetEvent('QBCore:Client:OnPlayerUnload', function()
local player = exports.qbx_core:GetPlayer(source)
if not player then return end
player.Functions.SetMetaData('alcohol', Player(source).state.alcohol)
Player(source).state:set('alcohol', 0, true)
end)

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

0 comments on commit 40f2e44

Please sign in to comment.