chaosdc123 Posted July 15, 2017 Share Posted July 15, 2017 (edited) I am trying to get this code to work, while it does, one part of the code just wont work AddComponentPostInit("combat", function(Combat)-- place in modmain local OldCalcDamage = Combat.CalcDamage Combat.CalcDamage = function(self, target, weapon, ...) local old_damage = nil local crit = 1 --crit chance (e.g. this is 50%) local critdmg = 50 --crit damage (x2) if math.random() <= crit and target and self.inst.prefab == "esctemplate" then --change to your prefab if weapon then -- if its a weapon old_damage = weapon.components.weapon.damage weapon.components.weapon.damage = old_damage * critdmg inst.components.talker:Say("CRIT") else -- if we attack with something not using the weapon component old_damage = self.defaultdamage self.defaultdamage = old_damage * critdmg inst.components.talker:Say("CRIT") end end local ret = OldCalcDamage(self, target, weapon, ...)-- returning crit damage if old_damage then-- reseting back to non crit damage if weapon then weapon.components.weapon.damage = old_damage else self.defaultdamage = old_damage end end return ret end Does anyone have a fix to my little problem? the code works if i remove "inst.components.talker:Say("CRIT") " plz HELP Edited July 15, 2017 by chaosdc123 Link to comment Share on other sites More sharing options...
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 account
Already have an account? Sign in here.Sign In Now