Jump to content

Increase Damage Multiplier upon killing an enemy.


Recommended Posts

As the title says, I'm trying to make a character who's damage multiplier goes up whenever they kill an enemy. Similar to how Wigfrid gains stats.

I tried using code provided by Finerlobster in another thread, but I don't understand how it's supposed to look. I'm really new at all this, and seeing the code in a straight line like this:

inst:ListenForEvent("entity_death", function(wrld, data) 	if data.cause == inst.prefab then		local delta = 10 -- amount		inst.components.health:DoDelta(delta)		inst.components.sanity:DoDelta(delta)		inst.components.hunger:DoDelta(delta)	endend, GetWorld())

makes no sense to me. Can someone show me what it's supposed to look like when added to notepad++, as well as what local section it should go under? I currently have it under "local function onattack(inst)".

thanks in advance.

EDIT:

Currently I have it set up like this:

local function onattack(inst)
    inst:ListenForEvent("entity_death", onattack)

    if data.cause == inst.prefab then
     local delta = 10 -- amount
     inst.components.comcat.damagemultiplier:DoDelta(delta)
    end 
end

 

Link to comment
Share on other sites

inst:ListenForEvent("onkillother", function(inst, data)
     inst.components.combat.damagemultiplier = inst.components.combat.damagemultiplier + .1
end

inst.OnSave = function(inst, data)
    data.mult = inst.components.combat.damagemultiplier
end

inst.OnLoad = function(inst, data)
    inst.components.combat.damagemultiplier = data.mult or 1
end

This code does the following:

  1. When the character kills something ("onkillother") , they gain 10% damage (this could be based on the victim's health, etc.)
  2. When the game saves, the current multiplier gets saved.
  3. When the game loads, the multiplier gets set to the saved value. If there is no saved value, it will default to 100%
Link to comment
Share on other sites

2 minutes ago, TheScareCr0we said:

One more thing, does this go under local function onattack, or should it go under the one where the base stats and such are located?

base stats, you won't need "local function onattack" with this code.

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...