PotterLee Posted March 11, 2017 Share Posted March 11, 2017 I need helps with my mod Pageable Backpack . When I run a game without cave , it worked well. When I run a game with cave enabled,some code doesn't work. I use "AddComponentPostInit("container", modContainer)" to rewrite some function about take/swap items in container slot, but these function worked like I never rewrote them. local function modContainer( self ) local old_TakeActiveItemFromAllOfSlot = self.TakeActiveItemFromAllOfSlot local old_SwapActiveItemWithSlot = self.SwapActiveItemWithSlot local old_MoveItemFromAllOfSlot = self.MoveItemFromAllOfSlot ----------------------------------------- local containers = require("containers") -- -------rewite function-------- self.TakeActiveItemFromAllOfSlot = function ( self, slot ) local item = self:GetItemInSlot(slot) if item == nil then return end if item.prefab == "qh_button" then item.components.page:NextPage() return end if item.prefab == "sx_button" then return end old_TakeActiveItemFromAllOfSlot(self, slot) end --------- self.SwapActiveItemWithSlot = function ( self, slot ) local item = self:GetItemInSlot(slot) if item == nil then return end if item.prefab == "qh_button" then item.components.page:NextPage() return end if item.prefab == "sx_button" then return end old_SwapActiveItemWithSlot(self, slot) end --------- self.MoveItemFromAllOfSlot = function ( self, slot, container ) local item = self:GetItemInSlot(slot) if item == nil then return end if item.prefab == "qh_button" then item.components.page:NextPage() return end if item.prefab == "sx_button" then return end old_MoveItemFromAllOfSlot(self, slot, container) end --------- --------- end modmain.lua Link to comment Share on other sites More sharing options...
PotterLee Posted March 11, 2017 Author Share Posted March 11, 2017 (edited) Maybe I should do something with container_replica,lua but how? Please ... Edited March 11, 2017 by PotterLee Link to comment Share on other sites More sharing options...
PotterLee Posted March 11, 2017 Author Share Posted March 11, 2017 I test agin , even if run game without cave , when one is not the host of the game, this mod doesn't work. How to solve it ,or how can I rewirte functions in replica? Link to comment Share on other sites More sharing options...
PotterLee Posted March 25, 2017 Author Share Posted March 25, 2017 .... Link to comment Share on other sites More sharing options...
Serpens Posted March 25, 2017 Share Posted March 25, 2017 (edited) Don't have time to look at your problem, but if your question is "how to mod replicas", maybe this code about builder component replica is helpful: -- builder mod for client AddClassPostConstruct("components/builder_replica", function(self) local _CanLearn = self.CanLearn self.CanLearn = function(self, recname) local recipe = GLOBAL.GetValidRecipe(recname) if recipe~=nil and not recipetestfn(recname,recipe,self.inst) then -- add a custom recipetestfn test return false else return _CanLearn(self, recname) end end end) Edited March 25, 2017 by Serpens 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