code4240 Posted February 19, 2015 Share Posted February 19, 2015 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 https://forums.kleientertainment.com/forums/topic/51198-giving-character-new-stat-wondering-best-way/ Share on other sites More sharing options...
DarkXero Posted February 19, 2015 Share Posted February 19, 2015 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 https://forums.kleientertainment.com/forums/topic/51198-giving-character-new-stat-wondering-best-way/#findComment-614711 Share on other sites More sharing options...
code4240 Posted February 19, 2015 Author Share Posted February 19, 2015 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")endIs there a way to grab the 'damage' variable from the attacked event? Link to comment https://forums.kleientertainment.com/forums/topic/51198-giving-character-new-stat-wondering-best-way/#findComment-614721 Share on other sites More sharing options...
DarkXero Posted February 19, 2015 Share Posted February 19, 2015 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)endSince 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 https://forums.kleientertainment.com/forums/topic/51198-giving-character-new-stat-wondering-best-way/#findComment-614725 Share on other sites More sharing options...
code4240 Posted February 20, 2015 Author Share Posted February 20, 2015 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)endSince 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 https://forums.kleientertainment.com/forums/topic/51198-giving-character-new-stat-wondering-best-way/#findComment-614770 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now