Kirigio Posted September 14, 2021 Share Posted September 14, 2021 (edited) I wanted to see if someone could help me with a little code, which is that when my character has a weapon with the shadow tag, it changes the damage multiplier of the character, let's say 25% more damage, but I have no idea how to do it. I would appreciate if you could help me. Edited September 14, 2021 by Kirigio Link to comment https://forums.kleientertainment.com/forums/topic/133642-help-with-a-custom-weapon-perk/ Share on other sites More sharing options...
Nelzanger Posted September 14, 2021 Share Posted September 14, 2021 (edited) I think you need to "hook" the Equip and Unequip functions of the equippable component. It means you will add your special code behavior to the existing one. In modmain.lua, you would put the following code (keep in mind this has not been tested !) : --You can set the value directly as a parameter or set a new value in TUNING local DAMAGE_MULTIPLIER_CONST = 42 local function EquipOverride(self) local old_Equip = self.Equip self.Equip = function(self, owner, from_ground, ...) -- Check if myself (equippable object) is a shadow item and a weapon if ( self:HasTag("shadow_item") and ( self.equipslot == GLOBAL.EQUIPSLOTS.HAND) ) then -- Add an external damage multiplier when using shadow weapons owner.components.combat.externaldamagemultipliers:SetModifier("your_tag_modifier", DAMAGE_MULTIPLIER_CONST) end -- Return the original behavior so you can still equip items -- unpack allows your override to be "change proof" if Klei changes the original method return values in the future return GLOBAL.unpack{old_Equip(self, owner, from_ground, ...)} end end local function UnequipOverride(self) local old_Unequip = self.Unequip self.Unequip = function(self, owner, ...) if ( self:HasTag("shadow_item") and ( self.equipslot == GLOBAL.EQUIPSLOTS.HAND) ) then -- Clean the effect when unequipping the shadow weapon owner.components.combat.externaldamagemultipliers:RemoveModifier("your_tag_modifier") end return GLOBAL.unpack{old_Unequip(self, owner, ...)} end end AddComponentPostInit("equippable", EquipOverride) AddComponentPostInit("equippable", UnequipOverride) Important note : you should check as well if your damage modifier already exists, otherwise, you could potentially stack modifiers by switching between several shadow weapons. I'm unsure if the modifier would be overwritten every time in that case. (For experienced people, feel free to correct me if I missed something. I'm still new in modding as well.) Edited September 14, 2021 by Nelzanger Replaced tab indents by space indents, because formatting was hideous 1 Link to comment https://forums.kleientertainment.com/forums/topic/133642-help-with-a-custom-weapon-perk/#findComment-1494839 Share on other sites More sharing options...
DecDuck Posted September 16, 2021 Share Posted September 16, 2021 You might also need to check for a mount then apply the modifier there if you want it to affect beefalo Link to comment https://forums.kleientertainment.com/forums/topic/133642-help-with-a-custom-weapon-perk/#findComment-1495218 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