Jump to content

Giving character new stat- wondering best way


Recommended Posts

I'm trying to give my custom character a new statistic, which I refer to as stress.

 

This character is a tank that does light aoe damage for the purpose of staggering enemies and drawing aggro. In order to function against swarms of enemies, she has to be resistant to being staggered herself. By staggered I'm referring to the hit animation that interrupts whatever you were doing when you take damage.

 

Now, I'm not asking how to change the hit state. I've made a custom stategraph that is a duplicate of SGWilson and commented out the line that starts this state, and it works properly. What I want to do is give this character a 'stress' stat that counts the amount of damage taken in a short period of time, and allows her to be staggered if it goes too high. It will be an int that is constantly draining the way hunger does. Thus, if she takes a lot of damage in a very short amount of time, she will be affected. This is meant to work for both huge swarms of enemies, and for enemies that have very high damage (deerclops).

 

I've declared the new variable as 'local stress = 0' in the character prefab, but I'm not sure where to go from there. My assumption is that I would use DoTaskPeriodically() to lower the stat, but I don't really know how it works or where it is in the code, or if there's a better way for dealing with something that's just an integer.

Link to comment
Share on other sites

You can use a DoPeriodicTask attached to your character like:

local stress = 0inst:DoPeriodicTask(1, function()   if stress > 0 then      stress = stress - 1   endend)

To reduce stress each second it goes by.

 

However, I would make stress a component, in the way firebug is. So that when it updates, you can make it go down if and only if the time reached 0, and it resets each time damage is taken, so that stress doesn't go down constantly.

 

If you play with many variables and periodic tasks, you can emulate the component, it's up to you.

Link to comment
Share on other sites

You can use a DoPeriodicTask attached to your character like:

local stress = 0inst:DoPeriodicTask(1, function()   if stress > 0 then      stress = stress - 1   endend)

To reduce stress each second it goes by.

 

However, I would make stress a component, in the way firebug is. So that when it updates, you can make it go down if and only if the time reached 0, and it resets each time damage is taken, so that stress doesn't go down constantly.

 

If you play with many variables and periodic tasks, you can emulate the component, it's up to you.

 

Okay, I've made a component.

 

I've made an event listener for "attacked" that looks like this:

local function onAttacked()		print("attacked")end

Is there a way to grab the 'damage' variable from the attacked event?

 

Link to comment
Share on other sites

That is no event listener on itself.

 

However, if I assume you did:

inst.components.combat:SetOnHit(onAttacked)

Then, onAttacked can be:

local function onAttacked(inst, attacker, damage)end

Since those are the arguments that are passed when onhitfn (the function that is given by SetOnHit) is called in the combat component.

Link to comment
Share on other sites

That is no event listener on itself.

 

However, if I assume you did:

inst.components.combat:SetOnHit(onAttacked)

Then, onAttacked can be:

local function onAttacked(inst, attacker, damage)end

Since those are the arguments that are passed when onhitfn (the function that is given by SetOnHit) is called in the combat component.

 

Welp, that worked. Thanks for the help.

 

Link to comment
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
 Share

×
  • Create New...