Jump to content

Bonus Damage Against Shadows and Nightmares


Recommended Posts

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
Share on other sites

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 by poolcool2
Change in wording to avoid confusion and clarify something
  • Thanks 1
Link to comment
Share on other sites

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

 

  • Thanks 1
Link to comment
Share on other sites

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

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...