So I’m still a beginner and I’m creating an FPS game with health and armor mechanics.
I’ve coded an armor regeneration feature and a damage function already but what I want is to create a delay between taking damage and the armor beginning to regenerate.
Basically i want the armor to start regenerating only if the player has not received damage in the last 3 secs.
I’ve uploaded a screenshot of both codes.
I appreciate the help.
What about using a gate node for the regeneration and close this each time, damage is taken while starting a timer of 3 seconds as well, after which the gate gets opened again? Let’s see if can create an example.
Instead of Tick with a Delay, I prefer to create my own looping timer.
Hey @ImDomo. Here I wrote an example code for you. You shouldn’t be adding a delay in the Tick function, that is prone to error. Instead I set a Timer each time the character receives damage. By saving the timer handle you prevent the same method from being called twice and just override the previous timer each time you receive damage. Also adding a boolean so that you know when to regenerate armor so you can do it in the tick function.
Hope this helps
@kribbeck I’ve recreated your method but when i take damage, it just doesn’t regen at all.
Any idea why?
@herb64 I’m trying to emulate your example, but what does the exec in the first Set Timer lead to?
@ImDomo That’s just the rest of processing from beginplay. In your case, the HUD creation for example. As said, that timer just replaces the Tick function with delay. Instead of your code, I just added some print statements for demonstration. And the K key is to simulate a damage event.
@herb64 Gotcha
I’m still playing around with your example, but the Open / Close of the gate is giving me some problems, i can’t get it to work.
I’ve sent some screenshots again, do you see any problem of anything I’m missing?
Sorry if I sound like a complete noob, cuz I am
So i unchecked the start closed box, so now it does regen, but the regen doesnt stop when I take damage
Try to uncheck the “Start Closed” in the Gate - it should start opened
yes i just did that, but now it regens while taking damage
Ah, you found it. Actually, you should not need the branch with taking damage. The TookDamage event just should run starting the timer and close the gate, so that after timer is run, the get gets reopened
Got it
But how do i link the TookDamage custom event to the Take Damage function?
I think i was asleep when the teacher was talking about that lol
From your takedamage function you can simply call the event after applying values. So each Take Damage function call will close the gate, suppress regenerates by this and trigger the timer for reopening the gate
What about calling the Take Damage Event from within the Function TakeDamage5%. I assume, the TakeDamage5% is the function that originally is called when damage is applied, not the Custom Event, so that custom event has to be called from here.
something (here my k key) calls the function TakeDamage5%.
and within that function, you do your processing and then call the custom event TakeDamage to run all that trigger stuff