Dunket Posted February 6, 2018 Share Posted February 6, 2018 Hello there. I'm trying to create an item that when a character is at low sanity will have a chance to block damage taken. Is this possible? Thanks in advance for any help! Link to comment https://forums.kleientertainment.com/forums/topic/87210-coding-help-making-item-have-a-chance-to-block-damage-when-at-low-sanity/ Share on other sites More sharing options...
Aquaterion Posted February 7, 2018 Share Posted February 7, 2018 modmain.lua AddComponentPostInit("combat", function(self) local oldGetAttacked = self.GetAttacked function self:GetAttacked(attacker, damage, weapon, stimuli) --25% sanity or lower --40% chance to actually trigger if self.inst:HasTag("insanity_blocker") and self.inst.components.sanity and self.inst.components.sanity:GetPercentWithPenalty() <= (25/100) and math.random() < (40/100) then damage = 0.01 --use this if u want to still do the attacked animation --return false --use this if u want to skip the attacked animation end return oldGetAttacked(self, attacker, damage, weapon, stimuli) end end) When you make your equippable item, make it add the tag "insanity_blocker" when equipped, and remove the tag when unequipped. the values 25 and 40 can be changed to anything to your liking. Read the comments for any other adjustments Link to comment https://forums.kleientertainment.com/forums/topic/87210-coding-help-making-item-have-a-chance-to-block-damage-when-at-low-sanity/#findComment-1000711 Share on other sites More sharing options...
Dunket Posted February 7, 2018 Author Share Posted February 7, 2018 Thank you! Link to comment https://forums.kleientertainment.com/forums/topic/87210-coding-help-making-item-have-a-chance-to-block-damage-when-at-low-sanity/#findComment-1000811 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