Skip to content

Commit

Permalink
extract stress function
Browse files Browse the repository at this point in the history
  • Loading branch information
TonybynMp4 committed May 6, 2024
1 parent 2c5d1e2 commit 4bb9343
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
3 changes: 2 additions & 1 deletion client/stress.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ CreateThread(function()
TriggerScreenblurFadeOut(1000.0)

if not cache.vehicle and not IsPedRagdoll(cache.ped) and IsPedOnFoot(cache.ped) and not IsPedSwimming(cache.ped) then
SetPedToRagdollWithFall(cache.ped, RagdollTimeout, RagdollTimeout, 1, GetEntityForwardVector(cache.ped), 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
local forwardVec3 = GetEntityForwardVector(cache.ped)
SetPedToRagdollWithFall(cache.ped, RagdollTimeout, RagdollTimeout, 1, forwardVec3.x, forwardVec3.y, forwardVec3.z, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
end

Wait(1000)
Expand Down
3 changes: 2 additions & 1 deletion client/vehicle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ local function vehiclehudloop()
}


-- not ideal, the 1500 doesn't actually equal 150 seconds because of framerate
if config.lowFuelAlert and getVehicleFuelLevel(cache.vehicle) < config.lowFuelAlert then
if alert > 0 then
alert = alert - 1
alert -= 1
else
alert = 1500
qbx.playAudio({
Expand Down
25 changes: 13 additions & 12 deletions server/stress.lua
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
local config = require 'config.server'

RegisterNetEvent('hud:server:GainStress', function(amount)
local function alterStress(source, amount)
local playerState = Player(source).state
local player = exports.qbx_core:GetPlayer(source)
if not player or (config.disablePoliceStress and player.PlayerData.job.type == 'leo') then return end
if not player or (amount > 0 and config.disablePoliceStress and player.PlayerData.job.type == 'leo') then return end

local newStress = playerState.stress + amount
newStress = lib.math.clamp(newStress, 0, 100)

playerState:set("stress", newStress, true)
exports.qbx_core:Notify(source, locale("notify.stress_gain"), 'inform', 2500, nil, nil, {'#141517', '#ffffff'}, 'brain', '#C53030')
end)

RegisterNetEvent('hud:server:RelieveStress', function(amount)
local playerState = Player(source).state
local player = exports.qbx_core:GetPlayer(source)
if not player then return end
if amount > 0 then
exports.qbx_core:Notify(source, locale("notify.stress_gain"), 'inform', 2500, nil, nil, {'#141517', '#ffffff'}, 'brain', '#C53030')
else
exports.qbx_core:Notify(source, locale("notify.stress_removed"), 'inform', 2500, nil, nil, {'#141517', '#ffffff'}, 'brain', '#0F52BA')
end
end

local newStress = playerState.stress - amount
newStress = lib.math.clamp(newStress, 0, 100)
RegisterNetEvent('hud:server:GainStress', function(amount)
alterStress(source, amount)
end)

playerState:set("stress", newStress, true)
exports.qbx_core:Notify(source, locale("notify.stress_removed"), 'inform', 2500, nil, nil, {'#141517', '#ffffff'}, 'brain', '#0F52BA')
RegisterNetEvent('hud:server:RelieveStress', function(amount)
alterStress(source, -amount)
end)

0 comments on commit 4bb9343

Please sign in to comment.