mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 07:03:16 +00:00
Fix crash when another player is picking up an item while we are in pickup ui.
This commit is contained in:
parent
c05c274589
commit
a96a1cda32
3 changed files with 24 additions and 0 deletions
|
@ -23,6 +23,7 @@ ctx.init = function()
|
|||
ctx.events = {}
|
||||
ctx.is_inventory_open = false
|
||||
ctx.rpc_peer_id = nil
|
||||
ctx.is_wand_pickup = false
|
||||
end
|
||||
|
||||
function ctx.dofile_and_add_hooks(path)
|
||||
|
|
|
@ -6,6 +6,8 @@ dofile_once("data/scripts/lib/coroutines.lua")
|
|||
|
||||
local item_sync = {}
|
||||
|
||||
local pending_remove = {}
|
||||
|
||||
function item_sync.ensure_notify_component(ent)
|
||||
local notify = EntityGetFirstComponentIncludingDisabled(ent, "LuaComponent", "ew_notify_component")
|
||||
if notify == nil then
|
||||
|
@ -46,6 +48,10 @@ function item_sync.get_global_item_id(item)
|
|||
end
|
||||
|
||||
function item_sync.remove_item_with_id(g_id)
|
||||
table.insert(pending_remove, g_id)
|
||||
end
|
||||
|
||||
function item_sync.remove_item_with_id_now(g_id)
|
||||
local global_items = EntityGetWithTag("ew_global_item")
|
||||
for _, item in ipairs(global_items) do
|
||||
local i_g_id = item_sync.get_global_item_id(item)
|
||||
|
@ -60,6 +66,12 @@ function item_sync.host_localize_item(gid, peer_id)
|
|||
GamePrint("Item localize for "..gid.." prevented")
|
||||
end
|
||||
ctx.item_prevent_localize[gid] = true
|
||||
|
||||
if table.contains(pending_remove, gid) then
|
||||
GamePrint("Item localize prevented, already taken")
|
||||
return
|
||||
end
|
||||
|
||||
if peer_id ~= ctx.my_id then
|
||||
item_sync.remove_item_with_id(gid)
|
||||
end
|
||||
|
@ -158,6 +170,16 @@ function item_sync.on_world_update_client()
|
|||
remove_client_items_from_world()
|
||||
end
|
||||
|
||||
function item_sync.on_world_update()
|
||||
-- TODO check that we not removing item we are going to pick now, instead of checking if picker gui is open.
|
||||
if not ctx.is_wand_pickup then
|
||||
if #pending_remove > 0 then
|
||||
local g_id = table.remove(pending_remove)
|
||||
item_sync.remove_item_with_id_now(g_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function item_sync.upload(item_data)
|
||||
local item = inventory_helper.deserialize_single_item(item_data)
|
||||
EntityAddTag(item, "ew_global_item")
|
||||
|
|
|
@ -98,6 +98,7 @@ function OnProjectileFiredPost(shooter_id, projectile_id, rng, position_x, posit
|
|||
end
|
||||
|
||||
function OnPausedChanged(paused, is_wand_pickup)
|
||||
ctx.is_wand_pickup = is_wand_pickup
|
||||
local players = EntityGetWithTag("ew_current_player") or {}
|
||||
|
||||
if (players[1]) then
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue