Skip to content

Commit

Permalink
fix(server/events): remove threads from handler (#583)
Browse files Browse the repository at this point in the history
  • Loading branch information
solareon authored Sep 25, 2024
1 parent 945dbd0 commit 07528de
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
10 changes: 4 additions & 6 deletions server/events.lua
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,10 @@ local function playerStateBagCheck(bagName, meta, value)
if not value then return end
local plySrc = GetPlayerFromStateBagName(bagName)
if not plySrc then return end
CreateThread(function()
local player = QBX.Players[plySrc]
if not player then return end
if player.PlayerData.metadata[meta] == value and Player(plySrc).state[meta] == value then return end
player.Functions.SetMetaData(meta, value)
end)
local player = QBX.Players[plySrc]
if not player then return end
if player.PlayerData.metadata[meta] == value then return end
player.Functions.SetMetaData(meta, value)
end

---@diagnostic disable-next-line: param-type-mismatch
Expand Down
31 changes: 17 additions & 14 deletions server/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -669,26 +669,29 @@ function CreatePlayer(playerData, Offline)
function self.Functions.SetMetaData(meta, val)
if not meta or type(meta) ~= 'string' then return end

if (meta == 'hunger' or meta == 'thirst' or meta == 'stress') then
val = lib.math.clamp(val, 0, 100)
if not self.Offline then
Player(self.PlayerData.source).state:set(meta, val, true)
end
end

if (meta == 'dead' or meta == 'inlaststand') and not self.Offline then
Player(self.PlayerData.source).state:set('canUseWeapons', not val, true)
end

local oldVal = self.PlayerData.metadata[meta]
self.PlayerData.metadata[meta] = val
self.Functions.UpdatePlayerData()
if meta == 'inlaststand' or meta == 'isdead' then
self.Functions.Save()
end

if not self.Offline then
local playerState = Player(self.PlayerData.source).state
TriggerClientEvent('qbx_core:client:onSetMetaData', self.PlayerData.source, meta, oldVal, val)
TriggerEvent('qbx_core:server:onSetMetaData', meta, oldVal, val, self.PlayerData.source)

if (meta == 'hunger' or meta == 'thirst' or meta == 'stress') then
val = lib.math.clamp(val, 0, 100)
if playerState[meta] ~= val then
playerState:set(meta, val, true)
end
end

if (meta == 'dead' or meta == 'inlaststand') then
playerState:set('canUseWeapons', not val, true)
end
end

if meta == 'inlaststand' or meta == 'isdead' then
self.Functions.Save()
end
end

Expand Down

0 comments on commit 07528de

Please sign in to comment.