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

fix: move stress back to client #74

Merged
merged 1 commit into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions client/consumables.lua
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ local function smokeWeed()
end

lib.callback.register('consumables:client:Eat', function(itemName)
local item = sharedConfig.consumables.food[itemName]
if lib.progressBar({
duration = 5000,
label = 'Eating...',
Expand All @@ -149,12 +150,12 @@ lib.callback.register('consumables:client:Eat', function(itemName)
mouse = false,
combat = true
},
anim = sharedConfig.consumables.food[itemName].anim or {
anim = item.anim or {
clip = 'mp_player_int_eat_burger',
dict = 'mp_player_inteat@burger',
flag = 49
},
prop = sharedConfig.consumables.food[itemName].prop or {
prop = item.prop or {
{
model = 'prop_cs_burger_01',
bone = 18905,
Expand All @@ -163,6 +164,7 @@ lib.callback.register('consumables:client:Eat', function(itemName)
}
}
}) then -- if completed
TriggerServerEvent('hud:server:RelieveStress', math.random(item.stressRelief.min, item.stressRelief.max))
return true
else -- if canceled
exports.qbx_core:Notify('Canceled...', 'error')
Expand All @@ -171,6 +173,7 @@ lib.callback.register('consumables:client:Eat', function(itemName)
end)

lib.callback.register('consumables:client:Drink', function(itemName)
local item = sharedConfig.consumables.drink[itemName]
if lib.progressBar({
duration = 5000,
label = 'Drinking...',
Expand All @@ -182,12 +185,12 @@ lib.callback.register('consumables:client:Drink', function(itemName)
mouse = false,
combat = true
},
anim = sharedConfig.consumables.drink[itemName].anim or {
anim = item.anim or {
clip = 'loop_bottle',
dict = 'mp_player_intdrink',
flag = 49
},
prop = sharedConfig.consumables.drink[itemName].prop or {
prop = item.prop or {
{
model = 'prop_ld_flow_bottle',
bone = 18905,
Expand All @@ -196,6 +199,7 @@ lib.callback.register('consumables:client:Drink', function(itemName)
}
}
}) then -- if completed
TriggerServerEvent('hud:server:RelieveStress', math.random(item.stressRelief.min, item.stressRelief.max))
return true
else -- if canceled
exports.qbx_core:Notify('Canceled...', 'error')
Expand All @@ -204,6 +208,7 @@ lib.callback.register('consumables:client:Drink', function(itemName)
end)

lib.callback.register('consumables:client:DrinkAlcohol', function(itemName)
local item = sharedConfig.consumables.alcohol[itemName]
if lib.progressBar({
duration = math.random(3000, 6000),
label = 'Drinking liquor...',
Expand All @@ -215,12 +220,12 @@ lib.callback.register('consumables:client:DrinkAlcohol', function(itemName)
mouse = false,
combat = true
},
anim = sharedConfig.consumables.alcohol[itemName].anim or {
anim = item.anim or {
clip = 'loop_bottle',
dict = 'mp_player_intdrink',
flag = 49
},
prop = sharedConfig.consumables.alcohol[itemName].prop or {
prop = item.prop or {
{
model = 'prop_amb_beer_bottle',
bone = 18905,
Expand All @@ -229,7 +234,8 @@ lib.callback.register('consumables:client:DrinkAlcohol', function(itemName)
}
}
}) then -- if completed
alcoholCount += sharedConfig.consumables.alcohol[itemName].alcoholLevel or 1
TriggerServerEvent('hud:server:RelieveStress', math.random(item.stressRelief.min, item.stressRelief.max))
alcoholCount += item.alcoholLevel or 1
if alcoholCount > 1 and alcoholCount < 4 then
TriggerEvent('evidence:client:SetStatus', 'alcohol', 200)
elseif alcoholCount >= 4 then
Expand Down
24 changes: 0 additions & 24 deletions server/consumables.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ for alcohol, params in pairs(sharedConfig.consumables.alcohol) do
local sustenance = player.PlayerData.metadata.thirst + math.random(params.min, params.max)
player.Functions.SetMetaData('thirst', sustenance)

if not params.stressRelief then
params.stressRelief = {
min = 1,
max = 4
}
end
TriggerEvent('hud:server:RelieveStress', source, math.random(params.stressRelief.min, params.stressRelief.max))

TriggerClientEvent('hud:client:UpdateNeeds', source, player.PlayerData.metadata.thirst, sustenance)
end)
end
Expand All @@ -36,14 +28,6 @@ for drink, params in pairs(sharedConfig.consumables.drink) do
local sustenance = player.PlayerData.metadata.thirst + math.random(params.min, params.max)
player.Functions.SetMetaData('thirst', sustenance)

if not params.stressRelief then
params.stressRelief = {
min = 1,
max = 4
}
end
TriggerEvent('hud:server:RelieveStress', source, math.random(params.stressRelief.min, params.stressRelief.max))

TriggerClientEvent('hud:client:UpdateNeeds', source, player.PlayerData.metadata.thirst, sustenance)
end)
end
Expand All @@ -60,14 +44,6 @@ for food, params in pairs(sharedConfig.consumables.food) do
local sustenance = player.PlayerData.metadata.hunger + math.random(params.min, params.max)
player.Functions.SetMetaData('hunger', sustenance)

if not params.stressRelief then
params.stressRelief = {
min = 1,
max = 4
}
end
TriggerEvent('hud:server:RelieveStress', source, math.random(params.stressRelief.min, params.stressRelief.max))

TriggerClientEvent('hud:client:UpdateNeeds', source, player.PlayerData.metadata.hunger, sustenance)
end)
end
Expand Down
Loading