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(statebags): wait for entity ID to exsist in network #255

Merged
merged 4 commits into from
Nov 16, 2023
Merged
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
8 changes: 5 additions & 3 deletions modules/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -369,11 +369,13 @@ else
function GetEntityAndNetIdFromBagName(bagName) -- luacheck: ignore
local netId = tonumber(bagName:gsub('entity:', ''), 10)

lib.waitFor(function()
return NetworkDoesEntityExistWithNetworkId(netId)
local idExist = lib.waitFor(function()
local netIdExist = NetworkDoesEntityExistWithNetworkId(netId)

if netIdExist then return netIdExist end
end, ('statebag timed out while awaiting entity creation! (%s)'):format(bagName), 10000)

local entity = NetworkDoesEntityExistWithNetworkId(netId) and NetworkGetEntityFromNetworkId(netId) or 0
local entity = idExist and NetworkGetEntityFromNetworkId(netId) or 0

if entity == 0 then
lib.print.error(('statebag received invalid entity! (%s)'):format(bagName))
Expand Down
Loading