Files
barotrauma-localmods/QuickStackToBag/Lua/Cyka/quickaccess.lua
2025-03-31 12:02:54 +02:00

97 lines
2.7 KiB
Lua

-- luacheck: globals MyModGlobal Character Hook EnsurePatch
local utils = require "Cyka.utils"
local dump = require "Cyka.dump"
Hook.Add("Character_CanInteractWith_Item_Postfix", "YourModName.AllowRemoteInteraction", function()
return true
end)
-- Then patch the CanInteractWith method
Hook.Patch("YourModName", "Barotrauma.Character", "CanInteractWith",
{ "Barotrauma.Item", "System.Single&", "System.Boolean" },
function(_, ptable)
local result = Hook.Call("Character_CanInteractWith_Item_Postfix")
if result == true then
ptable.ReturnValue = true
end
end,
Hook.HookMethodType.After
)
local function tryAccessFabricator()
local items = utils.enqueueAllSubmarineItems({}, function(item)
return item.Prefab.Identifier.Value == "fabricator", item.Prefab.Identifier.Value == "fabricator"
end)
if #items == 0 then
MyModGlobal.debugPrint("No fabricator found")
return
end
if #items > 1 then
MyModGlobal.debugPrint("Multiple fabricators found, using first one")
end
---@type Barotrauma.Item
local fabricator = items[1]
---@type Barotrauma.Items.Components.Fabricator
local fabricatorComponent
for component in fabricator.Components do
if component.Name == "Fabricator" then
fabricatorComponent = component
end
end
if not fabricatorComponent then
MyModGlobal.debugPrint("No fabricator component found")
return
end
local me = Character.Controlled
if not me then
MyModGlobal.debugPrint("No controlled character found")
return
end
MyModGlobal.debugPrint("Selecting fabricator")
-- fabricatorComponent.Select(me)
me.SelectedItem = fabricator
end
local function tryAccessDeconstructor()
local items = utils.enqueueAllSubmarineItems({}, function(item)
return item.Prefab.Identifier.Value == "deconstructor", item.Prefab.Identifier.Value == "deconstructor"
end)
if #items == 0 then
MyModGlobal.debugPrint("No deconstructor found")
return
end
if #items > 1 then
MyModGlobal.debugPrint("Multiple deconstructors found, using first one")
end
---@type Barotrauma.Item
local deconstructor = items[1]
---@type Barotrauma.Items.Components.Deconstructor
local deconstructorComponent
for component in deconstructor.Components do
if component.Name == "Deconstructor" then
deconstructorComponent = component
end
end
if not deconstructorComponent then
MyModGlobal.debugPrint("No deconstructor component found")
return
end
local me = Character.Controlled
if not me then
MyModGlobal.debugPrint("No controlled character found")
return
end
MyModGlobal.debugPrint("Selecting deconstructor")
-- deconstructorComponent.Select(me)
me.SelectedItem = deconstructor
end
return {
tryAccessFabricator = tryAccessFabricator,
tryAccessDeconstructor = tryAccessDeconstructor,
}