DarkKreepe Posted February 11, 2022 Share Posted February 11, 2022 Dear PZ Developers, Can you refactor the character's health panel? At the moment, it is absolutely unavailable for modding and causes incompatibility between mods. To add your own action when clicking on a body part, you need to completely copy the file and make a kinda "proxy" Now all actions are local. Example: local HApplyBandage = BaseHandler:derive("HApplyBandage") function ISHealthPanel:doBodyPartContextMenu(bodyPart, x, y) local playerNum = self.otherPlayer and self.otherPlayer:getPlayerNum() or self.character:getPlayerNum() local context = ISContextMenu.get(playerNum, x + self:getAbsoluteX(), y + self:getAbsoluteY()); local handlers = {} table.insert(handlers, HRemoveBandage:new(self, bodyPart)) table.insert(handlers, HApplyPlantain:new(self, bodyPart)) table.insert(handlers, HApplyComfrey:new(self, bodyPart)) table.insert(handlers, HApplyGarlic:new(self, bodyPart)) table.insert(handlers, HApplyBandage:new(self, bodyPart)) table.insert(handlers, HDisinfect:new(self, bodyPart)) table.insert(handlers, HStitch:new(self, bodyPart)) table.insert(handlers, HRemoveStitch:new(self, bodyPart)) table.insert(handlers, HRemoveGlass:new(self, bodyPart)) table.insert(handlers, HSplint:new(self, bodyPart)) table.insert(handlers, HRemoveSplint:new(self, bodyPart)) table.insert(handlers, HRemoveBullet:new(self, bodyPart)) table.insert(handlers, HCleanBurn:new(self, bodyPart)) And this part looks very strange. Code duplication function ISHealthPanel:dropItemsOnBodyPart(bodyPart, items) local handlers = {} table.insert(handlers, HRemoveBandage:new(self, bodyPart)) table.insert(handlers, HApplyPlantain:new(self, bodyPart)) table.insert(handlers, HApplyComfrey:new(self, bodyPart)) table.insert(handlers, HApplyGarlic:new(self, bodyPart)) -- CleanBurn before ApplyBandage because a bandage can be used to clean a burn table.insert(handlers, HCleanBurn:new(self, bodyPart)) table.insert(handlers, HApplyBandage:new(self, bodyPart)) table.insert(handlers, HDisinfect:new(self, bodyPart)) table.insert(handlers, HStitch:new(self, bodyPart)) table.insert(handlers, HRemoveStitch:new(self, bodyPart)) table.insert(handlers, HRemoveGlass:new(self, bodyPart)) table.insert(handlers, HSplint:new(self, bodyPart)) table.insert(handlers, HRemoveSplint:new(self, bodyPart)) table.insert(handlers, HRemoveBullet:new(self, bodyPart)) for _,handler in ipairs(handlers) do for _,item in ipairs(items) do handler:checkItem(item) end if handler:dropItems(items) then break end end end Can you make handlers public? Or context: function ISHealthPanel:doBodyPartContextMenu(bodyPart, x, y) ... local context = ISContextMenu.get(playerNum, x + self:getAbsoluteX(), y + self:getAbsoluteY()); ... Is it possible to add your own actions correctly? If so, how to do it better? If not, how fast can you fix it? Link to comment Share on other sites More sharing options...
Planet Algol Posted February 11, 2022 Share Posted February 11, 2022 local ISHealthPanel_Old_doBodyPartContextMenu = ISHealthPanel.doBodyPartContextMenu function ISHealthPanel:doBodyPartContextMenu(bodyPart, x, y) local playerNum = self.otherPlayer and self.otherPlayer:getPlayerNum() or self.character:getPlayerNum() ISHealthPanel_Old_doBodyPartContextMenu(self, bodyPart, x, y) local context = getPlayerContextMenu(playerNum); local handlers = {} table.insert(handlers, H_Algol_Syringe:new(self, bodyPart)) self:checkItems(handlers) for _,handler in ipairs(handlers) do handler:addToMenu(context) end end This code works for my own mods that add new health panel actions. DarkKreepe 1 Link to comment Share on other sites More sharing options...
DarkKreepe Posted February 12, 2022 Author Share Posted February 12, 2022 1 hour ago, Planet Algol said: local ISHealthPanel_Old_doBodyPartContextMenu = ISHealthPanel.doBodyPartContextMenu function ISHealthPanel:doBodyPartContextMenu(bodyPart, x, y) local playerNum = self.otherPlayer and self.otherPlayer:getPlayerNum() or self.character:getPlayerNum() ISHealthPanel_Old_doBodyPartContextMenu(self, bodyPart, x, y) local context = getPlayerContextMenu(playerNum); local handlers = {} table.insert(handlers, H_Algol_Syringe:new(self, bodyPart)) self:checkItems(handlers) for _,handler in ipairs(handlers) do handler:addToMenu(context) end end This code works for my own mods that add new health panel actions. Thank you. This is a good solution 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