Jump to content

[ Need Help!] Changing a Tool into a Healing Item


WaddleDee

Recommended Posts

So I'm trying to create a character mod, but I have absolutely no idea what to do, coding-wise. I need help!

What I want to do is add a second function to a sewing kit for my character, which would be the ability to heal the character (and them only) while using up  the kit's durability once per use. Is that possible, and if so, how could it be done? Keep in mind that I'm a noob, so simple explainations, please! Thank you.

Link to comment
Share on other sites

@WaddleDee, a good starting point would be the basic sample character in this mod.

 

As for the healing item, you'll need to make a new custom prefab (see the sample prefab in the above mod).

Add these in the create function ( "local function fn(Sim)" ).

-- Makes the item able to heal youinst:AddComponent("healer")inst.components.healer:SetHealthAmount(TUNING.HEALING_MED)local uses = 10-- You can also use TUNING.YOUR_ITEM_USES instead of 10-- but you'll have to define that somewhere first-- What happens when it's all used uplocal function onfinished(inst)    inst:Remove()end-- Makes the item have a finite number of usesinst:AddComponent("finiteuses")inst.components.finiteuses:SetOnFinished(onfinished)inst.components.finiteuses:SetMaxUses(uses)inst.components.finiteuses:SetUses(uses)

Edit: Sorry, I misread your question. Modifying the sewing kit to only heal a specific character sounds tedious. But it should be possible.

 

 

Edit 2: To modify the sewing kit, put this in your modmain.

-- Function that will modify the sewingkit prefab-- "inst" refers to the instance of the sewing kitlocal function sewing_postinit(inst)    -- Makes the item able to heal    inst:AddComponent("healer")    inst.components.healer:SetHealthAmount(TUNING.HEALING_MED)    -- Changes the healing function so it doesn't remove the item after one use    inst.components.healer.Heal = function(self, target)        -- Checks if the target is your character, and if it is able to use a healer        if target.prefab == "your_character_prefab" and target.components.health then            -- Heal the target by the amount set earlier.            target.components.health:DoDelta(self.health,false,self.inst.prefab)            -- Signal that the item was used once            self.components.finiteuses:Use(1)            return true        end    endend-- Runs the function above after sewingkit is initializedAddPrefabPostInit("sewingkit", sewing_postinit)

Remember to change your_character_prefab accordingly.

 

Edit 3: Added comments to show what the code does.

Also note, the first code will not work as "healer" removes the item once it's used, unless the "Heal" function is modified.

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...