Goregonzola Posted January 10, 2021 Share Posted January 10, 2021 (edited) Hey there! Long story short: my custom survivor has a constant Health drain, but if he equips his custom item, he would gain Health instead of losing. My approach was to give a tag to the custom item wielder the time he equips the item, and remove the tag when unequips it. This is the coding I've came up with: character.lua, local master_postinit = function(inst) section: Quote if inst:HasTag("mylamp") then inst.components.health:StartRegen(3, 2) else inst.components.health:StartRegen(-2, 3) end item.lua: Quote local function OnEquip(inst, owner) owner.AnimState:OverrideSymbol("swap_object", "swap_wagiclamp", "swap_wagiclamp") owner.AnimState:Show("ARM_carry") owner.AnimState:Hide("ARM_normal") if owner and owner:HasTag("lamprenter") then inst:AddTag("mylamp") end end local function OnUnequip(inst, owner) owner.AnimState:Hide("ARM_carry") owner.AnimState:Show("ARM_normal") if owner and owner:HasTag("lamprenter") then inst:RemoveTag("mylamp") end end I might've put something in the wrong place, since it crashes the game when I equip the item. Lamprenter is a tag my character always has. I've put the "if" part there, so other survivors don't benefit from the healing, only the custom one. What should I change? Thanks in advance guys! Edited January 10, 2021 by BillTheCipher problem got solved Link to comment Share on other sites More sharing options...
krylincy Posted January 10, 2021 Share Posted January 10, 2021 (edited) Whats your error log? I did something similar with the flower amulet. why are you adding the "mylamp" tag to the lamp (inst) itself and not to the owner? maybe that the problem. before you use "inst.components.health:StartRegen(3, 2)" you should check before if the ist has a component and health "if inst.components ~= nil and inst.components.health ~= nil then" to take care of the client side and owner without health. Edited January 10, 2021 by krylincy Link to comment Share on other sites More sharing options...
SuperMeatGoy Posted January 10, 2021 Share Posted January 10, 2021 the problem is definitely that youre doing "inst:AddTag("mylamp") and not "owner:AddTag("mylamp"). Hope fixing that works Link to comment Share on other sites More sharing options...
Goregonzola Posted January 10, 2021 Author Share Posted January 10, 2021 @krylincy @SuperMeatGoy Thanks for the tips! I've replaced "inst" to "owner", it does not crash now, but it still not restores the character's Health. I'm kinda clueless... Link to comment Share on other sites More sharing options...
-LukaS- Posted January 10, 2021 Share Posted January 10, 2021 I'd say, instead of making your custom item add a tag to your character and that way control the regeneration, make it so that the character itself controls it. For that you could add ListenForEvent("equip") and ListenForEvent("unequip") and add a function that checks whether the item that has been equipped is your custom item. Example: local function OnEquipCustom(inst, data) if data.item.prefab == "customitem" then inst.components.health:StartRegen(3, 2) end end local function OnUnequipCustom(inst, data) if data.item.prefab == "customitem" then inst.components.health:StartRegen(-2, 3) end end inst:ListenForEvent("equip", OnEquipCustom) inst:ListenForEvent("unequip", OnUnequipCustom) 2 Link to comment Share on other sites More sharing options...
Goregonzola Posted January 10, 2021 Author Share Posted January 10, 2021 @IThatGuyI Yeah, this do seems easier than the Tag-thingy. I've tried the coding, it works flawlessly. Much thanks 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