YakumoYukari Posted January 9, 2019 Share Posted January 9, 2019 , local function CanTakeItemTweak(inst) local _old = inst.components.container.CanTakeItemInSlot inst.components.container.CanTakeItemInSlot = function(self, item, slot) return _old(self, item, slot) and self.canbeopened end end And put this function in updatebackpack Link to comment Share on other sites More sharing options...
Tesumoto Posted January 9, 2019 Author Share Posted January 9, 2019 9 minutes ago, YakumoYukari said: , local function CanTakeItemTweak(inst) local _old = inst.components.container.CanTakeItemInSlot inst.components.container.CanTakeItemInSlot = function(self, item, slot) return _old(self, item, slot) and self.canbeopened end end And put this function in updatebackpack I don't know why, but it is don't work =( Link to comment Share on other sites More sharing options...
YakumoYukari Posted January 9, 2019 Share Posted January 9, 2019 local function UpdateBackpack(inst) if not GLOBAL.TheWorld.ismastersim then return inst end CanTakeItemTweak(inst) inst:ListenForEvent("itemget", CheckStatus) inst:ListenForEvent("itemlose", CheckStatus) end AddPrefabPostInit("backpack", UpdateBackpack) Did you do like this? local function itself does not run without calling Link to comment Share on other sites More sharing options...
Tesumoto Posted January 9, 2019 Author Share Posted January 9, 2019 (edited) 5 minutes ago, YakumoYukari said: local function UpdateBackpack(inst) if not GLOBAL.TheWorld.ismastersim then return inst end CanTakeItemTweak(inst) inst:ListenForEvent("itemget", CheckStatus) inst:ListenForEvent("itemlose", CheckStatus) end AddPrefabPostInit("backpack", UpdateBackpack) Did you do like this? local function itself does not run without calling local function UpdateBackpack(inst) if not GLOBAL.TheWorld.ismastersim then return inst end local function CheckStatus(inst) if inst.components.container:IsEmpty() then if (inst.components.inventoryitem == nil) then inst:AddComponent("inventoryitem") end inst.components.inventoryitem.cangoincontainer = true elseif not inst.components.container:IsEmpty() then --inst:RemoveComponent("inventoryitem") inst.components.inventoryitem.cangoincontainer = false local function CanTakeItemTweak(inst) local _old = inst.components.container.CanTakeItemInSlot inst.components.container.CanTakeItemInSlot = function(self, item, slot) return _old(self, item, slot) and self.canbeopened end end end end CanTakeItemTweak(inst) inst:ListenForEvent("equipped", CheckStatus) inst:ListenForEvent("itemget", CheckStatus) inst:ListenForEvent("itemlose", CheckStatus) end AddPrefabPostInit("backpack", UpdateBackpack) Edited January 9, 2019 by Tesumoto Link to comment Share on other sites More sharing options...
YakumoYukari Posted January 9, 2019 Share Posted January 9, 2019 CanTakeItemTweak(inst) This should not be executed in the client. Hmm... let me see the full modmain file. Link to comment Share on other sites More sharing options...
Tesumoto Posted January 9, 2019 Author Share Posted January 9, 2019 (edited) 24 minutes ago, YakumoYukari said: CanTakeItemTweak(inst) This should not be executed in the client. Hmm... let me see the full modmain file. modmain.lua Can't use it? self:GetRightClickActions Edited January 9, 2019 by Tesumoto Link to comment Share on other sites More sharing options...
YakumoYukari Posted January 9, 2019 Share Posted January 9, 2019 Done it. Here's the full code. local function CanTakeItemTweak(inst) local _old = inst.components.container.CanTakeItemInSlot inst.components.container.CanTakeItemInSlot = function(self, item, slot) return _old(self, item, slot) and self.canbeopened end end local function CheckStatus(inst) if inst.components.container:IsEmpty() then inst.components.inventoryitem.cangoincontainer = true inst.components.container.canbeopened = true elseif not inst.components.container:IsEmpty() then inst.components.inventoryitem.cangoincontainer = false inst.components.container.canbeopened = false end end local function OnEquipTweak(inst) local _onequip = inst.components.equippable.onequipfn inst.components.equippable.onequipfn = function(inst, owner) _onequip(inst, owner) inst.components.container.canbeopened = true end local _onunequip = inst.components.equippable.onunequipfn inst.components.equippable.onunequipfn = function(inst, owner) _onunequip(inst, owner) inst.components.container.canbeopened = false end end local function UpdateBackpack(inst) if not GLOBAL.TheWorld.ismastersim then return inst end inst:AddComponent("inventoryitem") CanTakeItemTweak(inst) OnEquipTweak(inst) inst:ListenForEvent("itemget", CheckStatus) inst:ListenForEvent("itemlose", CheckStatus) end AddPrefabPostInit("backpack", UpdateBackpack) Don't try things like local GLOBAL. ~~~~ local is the antonym of GLOBAL... Link to comment Share on other sites More sharing options...
Tesumoto Posted January 9, 2019 Author Share Posted January 9, 2019 7 minutes ago, YakumoYukari said: Done it. Here's the full code. local function CanTakeItemTweak(inst) local _old = inst.components.container.CanTakeItemInSlot inst.components.container.CanTakeItemInSlot = function(self, item, slot) return _old(self, item, slot) and self.canbeopened end end local function CheckStatus(inst) if inst.components.container:IsEmpty() then inst.components.inventoryitem.cangoincontainer = true inst.components.container.canbeopened = true elseif not inst.components.container:IsEmpty() then inst.components.inventoryitem.cangoincontainer = false inst.components.container.canbeopened = false end end local function OnEquipTweak(inst) local _onequip = inst.components.equippable.onequipfn inst.components.equippable.onequipfn = function(inst, owner) _onequip(inst, owner) inst.components.container.canbeopened = true end local _onunequip = inst.components.equippable.onunequipfn inst.components.equippable.onunequipfn = function(inst, owner) _onunequip(inst, owner) inst.components.container.canbeopened = false end end local function UpdateBackpack(inst) if not GLOBAL.TheWorld.ismastersim then return inst end inst:AddComponent("inventoryitem") CanTakeItemTweak(inst) OnEquipTweak(inst) inst:ListenForEvent("itemget", CheckStatus) inst:ListenForEvent("itemlose", CheckStatus) end AddPrefabPostInit("backpack", UpdateBackpack) Don't try things like local GLOBAL. ~~~~ local is the antonym of GLOBAL... Game crashed and I don't see any error. I don't know why, but... This don't work alone: inst:AddComponent("inventoryitem") Need this full code: if (inst.components.inventoryitem == nil) then inst:AddComponent("inventoryitem") end It is too difficult to write the conditions so that it is impossible to put items in the backpack only when it is in the inventory and the chest? Now you can’t put anything in backpack when it on ground. If this is too difficult, then you probably shouldn't try. Link to comment Share on other sites More sharing options...
YakumoYukari Posted January 9, 2019 Share Posted January 9, 2019 Working fine with me though, Link to comment Share on other sites More sharing options...
Tesumoto Posted January 9, 2019 Author Share Posted January 9, 2019 1 minute ago, YakumoYukari said: Working fine with me though, And I add "CheckStatus(inst)" in "local function UpdateBackpack(inst)" =) A little problem, if you put the first item in a backpack, then you can't put the second item in backpack .-. But I think, I can fix it, maybe =) I think this final beta code: local function CanTakeItemTweak(inst) local _old = inst.components.container.CanTakeItemInSlot inst.components.container.CanTakeItemInSlot = function(self, item, slot) return _old(self, item, slot) and self.canbeopened end end local function CheckStatus(inst) if inst.components.container:IsEmpty() then inst.components.inventoryitem.cangoincontainer = true elseif not inst.components.container:IsEmpty() then inst.components.inventoryitem.cangoincontainer = false end end local function OnEquipTweak(inst) local _onequip = inst.components.equippable.onequipfn inst.components.equippable.onequipfn = function(inst, owner) _onequip(inst, owner) inst.components.container.canbeopened = true end local _onunequip = inst.components.equippable.onunequipfn inst.components.equippable.onunequipfn = function(inst, owner) _onunequip(inst, owner) inst.components.container.canbeopened = false end end local function UpdateBackpack(inst) if not GLOBAL.TheWorld.ismastersim then return inst end if (inst.components.inventoryitem == nil) then inst:AddComponent("inventoryitem") end inst.components.container.canbeopened = false CanTakeItemTweak(inst) CheckStatus(inst) OnEquipTweak(inst) inst:ListenForEvent("itemget", CheckStatus) inst:ListenForEvent("itemlose", CheckStatus) end AddPrefabPostInit("backpack", UpdateBackpack) This work fine. Thank you very much, you helped me a lot. Maybe in the future I will try to improve this code a little, but for now I think enough =) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now