Jump to content

How to Change Damage Based on Monster


Dryicefox

Recommended Posts

What coding could allow me to change the damage AN ITEM does on a certain monster. Coraline, my revamp mod, originally done by Psycosis, will have pruners that do 2.5x damage to plant-based mobs since they do 17 damage originally and there are very few plant monsters.

 

I do NOT want this to effect the character as it could be used to multiply other weapons for one-shotting.

 

Help will be very much appreciated. Thanks in advanced.

Link to comment
Share on other sites

The first thing I would try is using prefab post-inits to add a unique tag to all plant monsters.

(I'm a tad rusty, but I think it'd be inst.AddTag: "PLANTBEAST" but it's not hard to check.)

 

 

From there, I think you could check if the target has the "PLANTBEAST" tag, on attack, and if it does, apply a damage multiplier of 2.5.

Link to comment
Share on other sites

No, no...

I'm not sure if this is right, but I think you add something like this to your weapon prefab:

local function onattack(inst, attacker, target)if target:HasTag("PLANTBEAST") theninst.components.weapon:SetDamage(TUNING.SPEAR_DAMAGE*2.5)elseinst.components.weapon:SetDamage(TUNING.SPEAR_DAMAGE*1)endend  local function fn(Sim).........    inst.components.Weapon:SetOnAttack( onattack )... end

 

And in your modmain, you would need:

function PlantbeastPostInit( inst )inst:AddTag("PLANTBEAST")end AddPrefabPostInit("lureplant", PlantbeastPostInit)
Link to comment
Share on other sites

local function onattack(inst, attacker, target)if target:HasTag("lureplantbulb") theninst.components.weapon:SetDamage(TUNING.SPEAR_DAMAGE*1.25)elseinst.components.weapon:SetDamage(TUNING.SPEAR_DAMAGE/2)endend    local function fn(Sim).........    inst.components.Weapon:SetOnAttack( onattack )...  end

I think I shall use this, the lure plant bulb already has a tag I can make reference to.

I'll test it later. In the mean time, do you think this will work?

Link to comment
Share on other sites

I would still add the tag through post-init. You're going to want it to affect more than one enemy, and if another plant monster is added, maintenance then becomes as simple as applying the post-init to another prefab.

 

I think it will work... but I don't have it in me to fully research and test it thoroughly. It's untested, and theoretical. About all I can muster before I need to rest.

Link to comment
Share on other sites

@Dryicefox, you could do this:

local PRUNER_VS_PLANT_MULTIPLIER = 2.5local function tag_as_plant(inst)	inst:AddTag("PLANTBEAST")endAddPrefabPostInit("eyeplant", tag_as_plant)AddPrefabPostInit("lureplantbulb", tag_as_plant)AddSimPostInit(function(player)	local combat = player.components.combat	local oldCalcDamage = combat.CalcDamage	combat.CalcDamage = function(self, target, weapon, multiplier)		multiplier = multiplier or self.damagemultiplier or 1		if weapon.prefab == "pruner" and target and target:HasTag("PLANTBEAST") then			multiplier = multiplier*PRUNER_VS_PLANT_MULTIPLIER		end		return oldCalcDamage(self, target, weapon, multiplier)	endend)
Replace "pruner" with the accurate prefab name for it. The above code is untested, but should work.
Link to comment
Share on other sites

@Dryicefox, you could do this:

local PRUNER_VS_PLANT_MULTIPLIER = 2.5local function tag_as_plant(inst)	inst:AddTag("PLANTBEAST")endAddPrefabPostInit("eyeplant", tag_as_plant)AddPrefabPostInit("lureplantbulb", tag_as_plant)AddSimPostInit(function(player)	local combat = player.components.combat	local oldCalcDamage = combat.CalcDamage	combat.CalcDamage = function(self, target, weapon, multiplier)		multiplier = multiplier or self.damagemultiplier or 1		if weapon.prefab == "pruner" and target and target:HasTag("PLANTBEAST") then			multiplier = multiplier*PRUNER_VS_PLANT_MULTIPLIER		end		return oldCalcDamage(self, target, weapon, multiplier)	endend)
Replace "pruner" with the accurate prefab name for it. The above code is untested, but should work.

 

Add this to my modmain.lua, correct?

 

Sorry for such a late reply. RL stuff.

Link to comment
Share on other sites

It is pretty old topic, but...

local function onattack(inst, attacker, target)if target:HasTag("lureplantbulb") then --let's say lureplantinst.components.weapon:SetDamage(TUNING.SPEAR_DAMAGE*1.25) --let's say 50 dmgelseinst.components.weapon:SetDamage(TUNING.SPEAR_DAMAGE/2) --let's say 25 dmgendend

this one does set damage AFTER attack was done. Is it possible to SetDamage before attack?

see comments in code first. if my dmg was 25 and i hit lureplant, i dealt 25 damage to it. but after that, my dmg set to 50. and every new hits i deal 50 dmg to lureplant. is it possible to set before attack? 

Link to comment
Share on other sites

It is pretty old topic, but...

local function onattack(inst, attacker, target)if target:HasTag("lureplantbulb") then --let's say lureplantinst.components.weapon:SetDamage(TUNING.SPEAR_DAMAGE*1.25) --let's say 50 dmgelseinst.components.weapon:SetDamage(TUNING.SPEAR_DAMAGE/2) --let's say 25 dmgendend

this one does set damage AFTER attack was done. Is it possible to SetDamage before attack?

see comments in code first. if my dmg was 25 and i hit lureplant, i dealt 25 damage to it. but after that, my dmg set to 50. and every new hits i deal 50 dmg to lureplant. is it possible to set before attack? 

 

It would be easier to deal the minimum damage per default and hurt the lureplant afterwards again. #outofthebox

Link to comment
Share on other sites

@Amalleus Have you tried Simplex's solution above? It seems to be modifying the damage calculation (which I presume comes before the attack) instead of using the onattack function.

No. i made much easier after a short advice =)

f.e. base damage of weapon is 20. i want to make x3 against mosters (=60)

in function OnAttack: you need to CalcDamage and then GetAttacked (hope it is right name). so i hit mob with 20 and then GetAttacked function increases damage for 40 more if it was monster =)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...