icantevenname Posted December 12, 2022 Share Posted December 12, 2022 I'm trying to give a character the ability to deal more damage to shadow creatures. I've based it off of Werebeaver Woodie's bonus damage to treeguards. local function alicebonusdamagefn(inst, target, damage, weapon) return (target:HasTag("stalker") or target:HasTag("shadowchesspiece") or target:HasTag("shadow")) and 1.5 end And in the master_postinit I have inst.components.combat.bonusdamagefn = alicebonusdamagefn But if I attack anything, the game crashes and the report reads [string "scripts/components/combat.lua"]:545: attempt to preform arithmetic on a boolean value And I have no idea what that means. Any help? Link to comment https://forums.kleientertainment.com/forums/topic/145193-bonus-damage-against-shadows-and-nightmares/ Share on other sites More sharing options...
poolcool2 Posted December 18, 2022 Share Posted December 18, 2022 (edited) I think that when using conditions in a return field the format needs to be: return Condition and TrueResult or FalseResult And I believe that because you are missing the "FalseResult", lua is instead treating the "Condition" as just a normal return value. So I think to fix it you need to instead do: local function alicebonusdamagefn(inst, target, damage, weapon) return (target:HasTag("stalker") or target:HasTag("shadowchesspiece") or target:HasTag("shadow")) and 1.5 or 1 end Using conditions in the return field is still something that I struggle to fully understand, so I may be wrong how that works, but if all else fails you could always use this: local function alicebonusdamagefn(inst, target, damage, weapon) if (target:HasTag("stalker") or target:HasTag("shadowchesspiece") or target:HasTag("shadow")) then return 1.5 -- Note: Return ends the function here and it does not run any code after the if-then statement end return 1 end It's a bit more messy, but I know that it would get your desired result. Edited December 18, 2022 by poolcool2 Change in wording to avoid confusion and clarify something 1 Link to comment https://forums.kleientertainment.com/forums/topic/145193-bonus-damage-against-shadows-and-nightmares/#findComment-1615510 Share on other sites More sharing options...
icantevenname Posted December 19, 2022 Author Share Posted December 19, 2022 The first one works! But it seems to add rather than multiply. Like base damage is 25 but vs. shadows it's 36 or so when I set the value to 10. Link to comment https://forums.kleientertainment.com/forums/topic/145193-bonus-damage-against-shadows-and-nightmares/#findComment-1615558 Share on other sites More sharing options...
poolcool2 Posted December 19, 2022 Share Posted December 19, 2022 13 minutes ago, icantevenname said: The first one works! But it seems to add rather than multiply. Like base damage is 25 but vs. shadows it's 36 or so when I set the value to 10. Indeed, what is returned by the bonus damage function is added to the damage dealt. But if you want it to be a multiplier then you can make use of the damage parameter. Here is how I did it with one of my mods as an example: local function onattack(inst, victem, damage, weapon) local bonus = 0 if victem ~= nil and (victem:HasTag("shadow") or victem:HasTag("stalker")) then bonus = damage * TUNING.WANE_NIGHTMAREDAMAGEBONUS -- By default TUNING.WANE_NIGHTMAREDAMAGEBONUS is 0.3 end return bonus end So if you want your character to do 1.5X total damage to nightmares, you can do this: local function alicebonusdamagefn(inst, target, damage, weapon) return (target:HasTag("stalker") or target:HasTag("shadowchesspiece") or target:HasTag("shadow")) and damage * 0.5 or 0 end 1 Link to comment https://forums.kleientertainment.com/forums/topic/145193-bonus-damage-against-shadows-and-nightmares/#findComment-1615560 Share on other sites More sharing options...
icantevenname Posted December 19, 2022 Author Share Posted December 19, 2022 Figured the solution was adding a * to the left number. Too bad I also did it to the right number and caused an immediate crash. Thanks for all your help! Link to comment https://forums.kleientertainment.com/forums/topic/145193-bonus-damage-against-shadows-and-nightmares/#findComment-1615563 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