Jump to content

[Solved] How to make a character take reduced damage from certain mobs?

Recommended Posts

I'm pretty new to mod characters, and while I've figured out how to do (most) of what I wanted on my own through searching, I can't seem to find the code (if there is one)  to make a character take reduced damage from specific mobs. I'd want this character to take 25% less damage from shadow monsters. Thanks in advance. n_n

Edited by SolarMisae
Link to comment
Share on other sites

The mod above actually done by "health.abosrb". You can see how it works in Health:DoDelta function. But it is difficult to do tag filtering as the cause parameter can be a string. So, I suggest the following code, and it is server-only.



--TODO: customize these constants
--prefab name of your character
local CHARACTER_PREFAB = "wickerbottom"
--reduce 95% of the original damage

    if not GLOBAL.TheWorld.ismastersim then
    local oldbonusdamagefn = inst.bonusdamagefn
    inst.bonusdamagefn = function(attacker, target, damage, weapon)
        local bonus = 0
        if oldbonusdamagefn then
            bonus = oldbonusdamagefn(attacker, target, damage, weapon) or 0
        -- things above are just for compatibility
        -- notice that shadow chesspieces has no "shadow" or "shadowcreature" tag
        if target.prefab == CHARACTER_PREFAB and (attacker:HasTag("shadow") or attacker:HasTag("shadowchesspiece")) then
            bonus = bonus - (damage + bonus) * DAMAGE_RESISTENCE
        return bonus



Link to comment
Share on other sites

First, thanks for the response! Any help is welcome and looking at the code helps understand it more. However, I keep crashing before character select. Image of crash screen included. 

Forgive me if I've done something very obviously wrong, putting stuff in the wrong places etc, I'm entirely new mods for this game and don't understand the code well. I pasted your code into my character's .lua file, and the only change I made was to first line of the code by switching "wickerbottom" with "wythe." Is there more I have to modify in the code itself or a different place I am to put this code? Since I am new to this forgive me if I ask to have it explained to me like I am 5. ;;


Edited by SolarMisae
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

  • Create New...