make chest logic a bit more general

This commit is contained in:
bgkillas 2024-11-18 08:26:26 -05:00
parent edb4a4ccde
commit f0f90c2b59

View file

@ -20,26 +20,21 @@ local dead_entities = {}
function rpc.open_chest(gid) function rpc.open_chest(gid)
local ent = item_sync.find_by_gid(gid) local ent = item_sync.find_by_gid(gid)
if ent ~= nil then local file
local name = EntityGetFilename(ent) for _, com in ipairs(EntityGetComponent(ent, "LuaComponent")) do
local file local f = ComponentGetValue2(com, "script_item_picked_up")
if name == "data/entities/items/pickup/utility_box.xml" then if f ~= nil then
file = "data/scripts/items/utility_box.lua" file = f
end break
if name == "data/entities/items/pickup/chest_random_super.xml" then
file = "data/scripts/items/chest_random_super.lua"
end
if name == "data/entities/items/pickup/chest_random.xml" then
file = "data/scripts/items/chest_random.lua"
end
if file ~= nil then
EntityAddComponent2(ent, "LuaComponent", {
script_source_file = file,
execute_on_added = true,
call_init_function = true,
})
end end
end end
if file ~= nil then
EntityAddComponent2(ent, "LuaComponent", {
script_source_file = file,
execute_on_added = true,
call_init_function = true,
})
end
end end
util.add_cross_call("ew_chest_opened", function(chest_id) util.add_cross_call("ew_chest_opened", function(chest_id)
@ -223,13 +218,6 @@ function item_sync.make_item_global(item, instant, give_authority_to)
}) })
end end
local name = EntityGetName(item)
if name == "$item_utility_box"
or name == "$item_chest_treasure"
or name == "$item_chest_treasure_super" then
end
ctx.item_prevent_localize[gid] = false ctx.item_prevent_localize[gid] = false
rpc.item_globalize(item_data) rpc.item_globalize(item_data)
end) end)