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

Init player state resource #1

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
19 changes: 9 additions & 10 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"Lua.runtime.nonstandardSymbol": ["/**/", "`", "+=", "-=", "*=", "/="],
"Lua.runtime.version": "Lua 5.4",
"Lua.diagnostics.globals": [
"lib",
"cache",
"locale",
"MySQL",
"QBX",
"qbx"
]
"Lua.runtime.nonstandardSymbol": ["/**/", "`", "+=", "-=", "*=", "/="],
"Lua.runtime.version": "Lua 5.4",
"Lua.diagnostics.globals": [
"lib",
"cache",
"QBX",
],
"editor.tabSize": 2,
"files.trimTrailingWhitespace": true
}
20 changes: 20 additions & 0 deletions client.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--- @class CLStateManager
local CLStateManager = require 'modules.statemanager.client'

local stateManager = CLStateManager:new()
stateManager:init()

local function addToState(stateId, value)
return lib.callback.await('qbx_playerstates:server:addToState', false, stateId, value)
end
exports('AddToState', addToState)

local function clearState(stateId)
return lib.callback.await('qbx_playerstates:server:clearState', false, stateId)
end
exports('ClearState', clearState)

local function clearAllStates()
return lib.callback.await('qbx_playerstates:server:clearAllStates', false)
end
exports('ClearAllStates', clearAllStates)
20 changes: 20 additions & 0 deletions client/hunger.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
local hungerConfig = require 'config.states.hunger'
local hungerEffectData = hungerConfig.effectData
if not hungerEffectData then return end

local statusInterval = hungerEffectData.statusInterval
local decreaseHealthRange = hungerEffectData.decreaseHealthRange

CreateThread(function()
while true do
Wait(statusInterval)
if LocalPlayer.state.isLoggedIn and not LocalPlayer.state.isDead then
local hunger = LocalPlayer.state.hunger or hungerConfig.value.default
if hunger <= 0 then
local currentHealth = GetEntityHealth(cache.ped)
local decreaseThreshold = math.random(decreaseHealthRange.min, decreaseHealthRange.max)
SetEntityHealth(cache.ped, currentHealth - decreaseThreshold)
end
end
end
end)
34 changes: 34 additions & 0 deletions client/painkiller.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
local painDisabled = false

local function disablePain()
if not painDisabled then
painDisabled = true
exports.qbx_medical:DisableDamageEffects()
lib.notify({description = 'Painkillers effects have started'})
end
end

local function enablePain()
if painDisabled then
painDisabled = false
exports.qbx_medical:EnableDamageEffects()
lib.notify({description = 'Painkillers effects have ended'})
end
end

CreateThread(function()
while true do
Wait(10 * 1000)
if LocalPlayer.state.isLoggedIn and not LocalPlayer.state.isDead then
if LocalPlayer.state.painkiller then
if LocalPlayer.state.painkiller > 0 then
disablePain()
else
enablePain()
end
else
enablePain()
end
end
end
end)
144 changes: 144 additions & 0 deletions client/stress.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
-- Stress Gain : Speeding
local stressConfig = require 'config.states.stress'
local stressData = stressConfig.effectData or {}

local stressSpeed = stressData.stressSpeed
local speedStressRange = stressData.speedStressRange
local speedStressInterval = stressData.speedStressInterval

local function isSpeedStressWhitelistedJob()
local playerJob = QBX.PlayerData.job.name
for _, v in pairs(stressData.speedStressWhitlistedJobs) do
if playerJob == v then
return true
end
end
return false
end

CreateThread(function()
while true do
if LocalPlayer.state.isLoggedIn and not isSpeedStressWhitelistedJob() and not LocalPlayer.state.isDead then
if cache.vehicle then
local vehClass = GetVehicleClass(cache.vehicle)
local speed = GetEntitySpeed(cache.vehicle)
if vehClass ~= 13 and vehClass ~= 14 and vehClass ~= 15 and vehClass ~= 16 and vehClass ~= 21 then
if speed >= stressSpeed then
exports.qbx_playerstates:AddToState('stress', math.random(speedStressRange.min, speedStressRange.max))
end
end
end
end
Wait(speedStressInterval)
end
end)

-- Stress Gain : Shooting
local hasWeapon = false
local whitelistedWeapons = stressData.whitelistedWeapons
local stressChance = stressData.stressChance
local weaponStressRange = stressData.weaponStressRange

local function isWhitelistedWeaponStress(weapon)
if weapon then
for _, v in pairs(whitelistedWeapons) do
if
type(v) == 'string' and
type(weapon) == 'string' and
weapon:lower() == v:lower()
then
return true
end
end
end
return false
end

local function startWeaponStressThread(weapon)
if isWhitelistedWeaponStress(weapon) then return end
hasWeapon = true
CreateThread(function()
while hasWeapon and not LocalPlayer.state.isDead do
if IsPedShooting(cache.ped) then
if math.random() <= stressChance then
exports.qbx_playerstates:AddToState('stress', math.random(weaponStressRange.min, weaponStressRange.max))
end
end
Wait(0)
end
end)
end

AddEventHandler('ox_inventory:currentWeapon', function(currentWeapon)
hasWeapon = false
Wait(0)
if not currentWeapon then return end
startWeaponStressThread(currentWeapon.name)
end)

-- Stress Effects --

local minForShaking = stressData.minForShaking
local blurIntensity = stressData.blurIntensity
local effectInterval = stressData.effectInterval

local function getBlurIntensity(stresslevel)
for _, v in pairs(blurIntensity) do
if stresslevel >= v.min and stresslevel <= v.max then
return v.intensity
end
end
return 1500
end

local function getEffectInterval(stresslevel)
for _, v in pairs(effectInterval) do
if stresslevel >= v.min and stresslevel <= v.max then
return v.timeout
end
end
return 60000
end

CreateThread(function()
while true do
if LocalPlayer.state.isLoggedIn and not LocalPlayer.state.isDead and not LocalPlayer.state.onEffect then
local stress = LocalPlayer.state.stress or stressConfig.value.default
local effectWaitInterval = getEffectInterval(stress)
if stress >= stressConfig.value.max then
LocalPlayer.state.onEffect = true
local blurIntensityInterval = getBlurIntensity(stress)
local fallRepeat = math.random(2, 4)
local ragdollTimeout = fallRepeat * 1750
TriggerScreenblurFadeIn(1000.0)
Wait(blurIntensityInterval)
TriggerScreenblurFadeOut(1000.0)
if not IsPedRagdoll(cache.ped) and IsPedOnFoot(cache.ped) and not IsPedSwimming(cache.ped) then
local forwardVector = GetEntityForwardVector(cache.ped)
SetPedToRagdollWithFall(cache.ped, ragdollTimeout, ragdollTimeout, 1, forwardVector.x, forwardVector.y, forwardVector.z, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
end
Wait(1000)
for _ = 1, fallRepeat, 1 do
Wait(750)
DoScreenFadeOut(200)
Wait(1000)
DoScreenFadeIn(200)
TriggerScreenblurFadeIn(1000.0)
Wait(blurIntensityInterval)
TriggerScreenblurFadeOut(1000.0)
end
LocalPlayer.state.onEffect = false
elseif stress >= minForShaking then
LocalPlayer.state.onEffect = true
local blurIntensityInterval = getBlurIntensity(stress)
TriggerScreenblurFadeIn(1000.0)
Wait(blurIntensityInterval)
TriggerScreenblurFadeOut(1000.0)
LocalPlayer.state.onEffect = false
end
Wait(effectWaitInterval)
else
Wait(1000)
end
end
end)
20 changes: 20 additions & 0 deletions client/thirst.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
local thirstConfig = require 'config.states.thirst'
local thirstEffectData = thirstConfig.effectData
if not thirstEffectData then return end

local statusInterval = thirstEffectData.statusInterval
local decreaseHealthRange = thirstEffectData.decreaseHealthRange

CreateThread(function()
while true do
Wait(statusInterval)
if LocalPlayer.state.isLoggedIn and not LocalPlayer.state.isDead then
local thirst = LocalPlayer.state.thirst or thirstConfig.value.default
if thirst <= 0 then
local currentHealth = GetEntityHealth(cache.ped)
local decreaseThreshold = math.random(decreaseHealthRange.min, decreaseHealthRange.max)
SetEntityHealth(cache.ped, currentHealth - decreaseThreshold)
end
end
end
end)
19 changes: 19 additions & 0 deletions config/shared.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
--- @type table<string, PlayerStateConfig>
local allStates = {}
-- numeric
allStates.stress = require 'config.states.stress'
allStates.hunger = require 'config.states.hunger'
allStates.thirst = require 'config.states.thirst'
allStates.painkiller = require 'config.states.painkiller'

-- boolean
allStates.dead = require 'config.states.dead'
allStates.cuff = require 'config.states.cuff'

-- custom
allStates.escort = require 'config.states.escort'
allStates.escorted = require 'config.states.escorted'
allStates.carry = require 'config.states.carry'
allStates.carried = require 'config.states.carried'

return allStates
62 changes: 62 additions & 0 deletions config/states/carried.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
--- @type PlayerStateConfig
return {
id = 'carried',
label = 'Carried',
fields = { stateBag = 'carriedBy' },
permanent = false,
value = {
default = nil,
},
notification = {
up = {
id = 'state-carried-up-notif',
title = 'Carried',
description = 'You are being carried',
duration = 2000,
icon = 'user-friends',
iconColor = '#4CAF50',
style = {
backgroundColor = '#141517',
color = '#FFFFFF',
},
value = 1,
},
down = {
id = 'state-carried-down-notif',
title = 'Carried',
description = 'You are no longer being carried',
duration = 2000,
icon = 'user-large-slash',
iconColor = '#C53030',
style = {
backgroundColor = '#141517',
color = '#FFFFFF',
},
value = -1,
},
},
disable = {
condition = function(value)
return value ~= nil and value
end,
keys = {
0, 7, 20, 24, 25, 26, 29, 30, 32, 33, 34, 35, 44,
45, 46, 47, 48, 49, 59, 74, 75, 77, 140, 141, 142,
144, 145, 185, 199, 244, 251, 246, 303, 323,
},
emotes = true,
radio = true,
phone = true,
inventory = true,
},
forcedAnimations = {
{
condition = function(value)
return value ~= nil and value
end,
dict = 'nm',
name = 'firemans_carry',
flag = 1,
}
},
}
Loading
Loading