SrCheddar Posted April 4, 2025 Share Posted April 4, 2025 Can someone help me? I'm making a mod that adds a helmet, and I want it to be unbreakable so it doesn't disappear when it reaches 0% of health and I want it to be repairable with wood materials. Link to comment https://forums.kleientertainment.com/forums/topic/165213-help-for-a-custom-helmet-mod/ Share on other sites More sharing options...
Merkyrrie Posted April 6, 2025 Share Posted April 6, 2025 There's two good options for making it repairable, I think. You can either do it a little more in-depth with use of a custom action OR you can make use of the fact that wood is technically food and instead do what the Eye Mask and Shield of Terror do with the eater component. I believe the latter will cause it to show 'Feed' as the action name when "repairing" the helmet, which would be the main downside to the otherwise much easier solution. Link to comment https://forums.kleientertainment.com/forums/topic/165213-help-for-a-custom-helmet-mod/#findComment-1811066 Share on other sites More sharing options...
oregu Posted April 7, 2025 Share Posted April 7, 2025 (edited) hmm... i modified forgerepairable to work like the repairable component if you have "materialrepairable" to be true. this is to make sure you dont accidentally have a forgerepairable material with the same name as a regular repairable material. but you can remove that check if you want, because it might break already existing forgerepair compatability. modmain Spoiler for k,v in pairs(GLOBAL.MATERIALS) do -- componentactions makes a check for materials being in the FORGEMATERIALS table, so we must add those materials to that table GLOBAL.FORGEMATERIALS[k] = v end local function OnSuccess(self, target, doer) -- Delete the item after it's used if self.inst.components.finiteuses then self.inst.components.finiteuses:Use(1) elseif self.inst.components.stackable then self.inst.components.stackable:Get():Remove() else self.inst:Remove() end if self.onrepaired ~= nil then self.onrepaired(self.inst, target, doer) end return true end local function ComponentPercentTests(self, target, doer, value, ...) -- If the percent is >= 100% dont do anything (it's supposed to be under 100%) local next = GLOBAL.next --GLOBAL.c_announce(value) for k,v in next,{...} do if target.components[v] then local CurrentPercent = target.components[v].GetPercent and target.components[v]:GetPercent() if type(CurrentPercent) == "number" and CurrentPercent < 1 then target.components[v]:SetPercent(math.clamp(CurrentPercent + value, 0, 1)) return OnSuccess(self, target, doer) end end end end AddPrefabPostInitAny(function(inst) -- regular repair materials can now try to forgerepair using their repair material if inst.components.repairer and not inst.components.forgerepair then local repairer = inst.components.repairer local value = repairer.finiteusesrepairvalue > 0 and repairer.finiteusesrepairvalue / 100 -- trying to automatically convert repairvalues to forgerepair values or repairer.healthrepairvalue > 0 and repairer.healthrepairvalue / 100 or repairer.workrepairvalue > 0 and repairer.workrepairvalue / 4 or repairer.perishrepairpercent > 0 and repairer.perishrepairpercent or 1 inst:AddComponent"forgerepair" inst.components.forgerepair.OnRepair = function(self, target, doer) return ComponentPercentTests(self, target, doer, value, "armor", "finiteuses", "fueled") end inst.components.forgerepair:SetRepairMaterial(inst.components.repairer.repairmaterial) inst.components.forgerepair:SetOnRepaired(function(inst, target, doer) doer:PushEvent"repair" end) end end) AddComponentPostInit("forgerepairable", function(self) -- if materialrepairable is true then materials will be accepted local function MaterialRepairCheck(self, doer, item) if not self.materialrepairable and item.components.repairer and item.components.repairer.repairmaterial == self.repairmaterial then return false end end local _Repair = self.Repair -- prior forgerepairable check self.Repair = function(self, doer, item, ...) local material_result = MaterialRepairCheck(self, doer, item) if material_result ~= nil then return material_result else return _Repair(self, doer, item, ...) end end end) in your prefab file Spoiler -- This is around what my relevant forgerepair functions look like local function SetupEquippable(inst) inst:AddComponent("equippable") inst.components.equippable.equipslot = EQUIPSLOTS.HEAD inst.components.equippable:SetOnEquip(OnEquip) inst.components.equippable:SetOnUnequip(OnUnequip) end local function OnBroken(inst) if inst.components.equippable then inst:RemoveComponent"equippable" --inst.AnimState:PlayAnimation("broken") --inst.components.floater:SetSwapData(SWAP_DATA_BROKEN) inst:AddTag("broken") inst.components.inspectable.nameoverride = "BROKEN_FORGEDITEM" end end local function OnRepaired(inst) if not inst.components.equippable then SetupEquippable(inst) --inst.AnimState:PlayAnimation("anim") --inst.components.floater:SetSwapData(SWAP_DATA) inst:RemoveTag("broken") inst.components.inspectable.nameoverride = nil end end -- Somewhere below SetPristine and armor component SetupEquippable(inst) MakeForgeRepairable(inst, MATERIALS.WOOD, OnBroken, OnRepaired) -- refer to already existing forgerepairable prefabs, like voidcloth_boomerang inst.components.forgerepairable.materialrepairable = true Edited April 8, 2025 by oregu Link to comment https://forums.kleientertainment.com/forums/topic/165213-help-for-a-custom-helmet-mod/#findComment-1811225 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