Sign in to follow this  
Thebrettstoner

Question about damage multiplier.

Recommended Posts

Hello, I have a question. So I want to give my character the ability to give others a damage boost when using a staff item, is there something like "inst.components.locomotor:SetExternalSpeedMultiplier(inst, "mycharacter_speed_mod", 1)" but for damage instead of speed that i could use. ive looked trough the combat.lua component but couldnt find anything that i could use. 

I believe wont be able to use "inst.components.combat.damagemultiplier" because i believe that'l mess up characters like wolfgang and wigfrid (and modded characters). Unless this isnt the case i'd really appriciate the help!

Share this post


Link to post
Share on other sites
Ultroman    725

Combat:AddDamageModifier(key, mod)
The key is a unique string, like "MyModStaffBuff" and mod is a percentage given as e.g. 1.0, where 1.0 gives 100% extra damage.

Share this post


Link to post
Share on other sites
Well-met    5150
16 hours ago, Ultroman said:

Combat:AddDamageModifier(key, mod)
The key is a unique string, like "MyModStaffBuff" and mod is a percentage given as e.g. 1.0, where 1.0 gives 100% extra damage.

this function does not seem to exist.

Closest thing I found is Combat:CalcDamage(target, weapon, multiplier)

Share this post


Link to post
Share on other sites
Ultroman    725

Ah, sorry. I was looking at DS game files. Apologies, m8.

FOR DS:
Combat:AddDamageModifier(key, multiplier)
Combat:RemoveDamageModifier(key)

-- 5% damage increase
player_inst.components.combat:AddDamageModifier("mymodifierkey", 0.05)

-- remove modifier
player_inst.components.combat:RemoveDamageModifier("mymodifierkey")

The 'key' is a unique string, like "MyModStaffBuff", while 'multiplier' is a normalized percentage given as, e.g., 0.3, where 1.0 gives +100% extra damage, 0.0 means no effect, and -0.3 gives -30% damage.

FOR DST:
SourceModifierList:SetModifier(source, multiplier, key)
SourceModifierList:RemoveModifier(source, key)
Function description from Klei code:
Source can be an object or a name. If it is an object, then it will handle removing the multiplier if the object is forcefully removed from the game. Key is optional if you are only going to have one multiplier from a source.

-- 5% damage increase
player_inst.components.combat.externaldamagemultipliers:SetModifier(source_inst, 1.05, "myuniquemodifierkey")

-- remove modifier
player_inst.components.combat.externaldamagemultipliers:RemoveModifier(source_inst, "myuniquemodifierkey")

Since 'source' can also be a name, you can just make sure to give it a unique name:

-- 5% damage increase
player_inst.components.combat.externaldamagemultipliers:SetModifier("myuniquemodifierkey", 1.05)

-- remove modifier
player_inst.components.combat.externaldamagemultipliers:RemoveModifier("myuniquemodifierkey")

 

Edited by Ultroman

Share this post


Link to post
Share on other sites
Well-met    5150

so if I wanted a triple damage against giants (and only giants), would this work?

local function GiantModifier(inst, target)
	if inst:HasTag("character") and target:HasTag("epic") then
	inst.components.combat.externaldamagemultipliers:SetModifier(inst, 3)
	else
	inst.components.combat.externaldamagemultipliers:SetModifier(inst, 1)
	end
end

 

Share this post


Link to post
Share on other sites
Ultroman    725

No. You'd have to do something totally different then. This code sets a permanent multiplier on the damage dealt to anything, and it does not go away until your specifically remove the modifier. What your code snippet does, is set a modifier on a character depending on whether the target has the tag "epic". This modifier will affect any damage done to any target by that character, be it a giant or not.

If you just want your character to deal more damage to giants, do something like this in your character's master_postinit:

local old_CalcDamage = inst.components.combat.CalcDamage

inst.components.combat.CalcDamage = function(self, target, weapon, multiplier, ...)
	local damage = old_CalcDamage(self, target, weapon, multiplier, ...)
	if target:HasTag("epic") then
		damage = damage * 3
	end
	return damage
end

If there needs to be some condition that your character must have active or whatever, you can just add more checks to whether or not the multiplier should be applied. You have the target and you have your character instance there as self.inst

Share this post


Link to post
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
Sign in to follow this