SolarMisae Posted September 16, 2017 Share Posted September 16, 2017 (edited) 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 September 18, 2017 by SolarMisae Link to comment Share on other sites More sharing options...
Lumina Posted September 16, 2017 Share Posted September 16, 2017 I'm not sure, but this mod : http://steamcommunity.com/sharedfiles/filedetails/?id=1135175637 Add a damage reduction to winona. You could maybe look at the code, see how it works, and add a check for monster with shadow tag. Link to comment Share on other sites More sharing options...
ptr Posted September 17, 2017 Share Posted September 17, 2017 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. Quote --TODO: customize these constants --prefab name of your character local CHARACTER_PREFAB = "wickerbottom" --reduce 95% of the original damage local DAMAGE_RESISTENCE = 0.95 AddComponentPostInit("combat",function(inst) if not GLOBAL.TheWorld.ismastersim then return end 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 end -- 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 end return bonus end end) Link to comment Share on other sites More sharing options...
SolarMisae Posted September 18, 2017 Author Share Posted September 18, 2017 (edited) 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 September 18, 2017 by SolarMisae Link to comment Share on other sites More sharing options...
Lumina Posted September 18, 2017 Share Posted September 18, 2017 Try putting this in your modmain. I'm not sure but i think it's a modmain code. Also, if you encounter a problem about a code not working, better to show exactly where you put it. Link to comment Share on other sites More sharing options...
SolarMisae Posted September 18, 2017 Author Share Posted September 18, 2017 (edited) I see, thanks! I will do so in the future. I'll try putting the code in modmain and see how it goes. n.n Edit: Ahh success! It's working flawlessly now. Thanks again to both of you! Edited September 18, 2017 by SolarMisae Link to comment 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