Jump to content

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

 

Edited by TheScareCr0we
additional information
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%

Thank you very much! I'll add it ass soon as I fix the error with his speach.lua

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?

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.

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