Skip to content

Commit

Permalink
make statebag keys constants
Browse files Browse the repository at this point in the history
  • Loading branch information
Manason committed Nov 22, 2023
1 parent 3dfe99f commit 6dfb196
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
8 changes: 3 additions & 5 deletions client/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ local playerState = LocalPlayer.state
---@type table<BodyPartKey, integer?>
Injuries = {}

local BODY_PART_STATE_BAG_PREFIX = 'qbx_medical:injuries:'

for bodyPartKey in pairs(Config.BodyParts) do
local bodyPartStateBag = BODY_PART_STATE_BAG_PREFIX .. bodyPartKey
Injuries[bodyPartKey] = playerState[bodyPartStateBag]
Expand All @@ -22,14 +20,14 @@ function SetInjury(bodyPartKey, severity)
playerState:set(BODY_PART_STATE_BAG_PREFIX .. bodyPartKey, severity, true)
end

BleedLevel = playerState['qbx_medical:bleedLevel'] or 0
BleedLevel = playerState[BLEED_LEVEL_STATE_BAG] or 0

AddStateBagChangeHandler('qbx_medical:bleedLevel', ('player:%s'):format(cache.serverId), function(_, _, value)
AddStateBagChangeHandler(BLEED_LEVEL_STATE_BAG, ('player:%s'):format(cache.serverId), function(_, _, value)
BleedLevel = value
end)

function SetBleedLevel(level)
playerState:set('qbx_medical:bleedLevel', level, true)
playerState:set(BLEED_LEVEL_STATE_BAG, level, true)
end

BleedTickTimer, AdvanceBleedTimer = 0, 0
Expand Down
3 changes: 2 additions & 1 deletion fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ shared_scripts {
'@qbx_core/shared/locale.lua',
'locales/en.lua',
'locales/*.lua',
'config.lua'
'config.lua',
'shared/**/*.lua',
}

client_scripts {
Expand Down
4 changes: 2 additions & 2 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ local playerState

AddEventHandler('QBCore:Server:OnPlayerLoaded', function()
playerState = Player(source).state
playerState:set('qbx_medical:bleedLevel', 0, true)
playerState:set(BLEED_LEVEL_STATE_BAG, 0, true)
for bodyPartKey in pairs(Config.BodyParts) do
playerState:set('qbx_medical:injuries:' .. bodyPartKey, nil, true)
playerState:set(BODY_PART_STATE_BAG_PREFIX .. bodyPartKey, nil, true)
end
end)

Expand Down
2 changes: 2 additions & 0 deletions shared/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BODY_PART_STATE_BAG_PREFIX = 'qbx_medical:injuries:'
BLEED_LEVEL_STATE_BAG = 'qbx_medical:bleedLevel'

0 comments on commit 6dfb196

Please sign in to comment.