Stamina regain.

Hello, I have this little multiplier blueprint that allows my character to sprint.

This is the logic within the character:

and this is the SetComputedMaxWalkSpeed function:

I’m trying to implement stamina, I have the check for stamina already done as you can tell, and I know how I am going to do stamina depletion, but I can’t figure out how I’m going to do stamina regain.

The problem I’m facing is I’m not sure how to get the server to check if a player is not sprinting to allow stamina regain without tanking performance. I could use an Event Tick but I really want to stray away from that. The question is, how would I go about doing that without Event Tick?

I am not sure there is anyway to do it without an event tick. What is your reasoning behind not using event tick?

My main concern was performance, I mean, it’s fine if I have to use one, I was just checking my options to see if anyone knew another way.

Hello,
As regain is in time, tick or delay will be needed. For delay, a custom event with loop / while loop can do it. You have to set it on release / end of each stamina consumer event, and check that it is not ever running. Advantage of delay could be that it is not fired on “is sprinting” true and is a single node added to events.

I think you would be okay using event tick in this instance, I am actually using event tick for an energy regeneration as well. The other option would be to use a delay timer on the client and have that loop until the stamina was full again.

I have tried this myself yet … but it shouldn’t be too difficult to implement. You could always ensure that the server has control by storing a last stamina value on the client that is replicated and thus when the timer completes on the client it sends the server how long it took to recover and that it is complete. The server could then compare the time it took to the value it has stored … check if the calculation was valid and then set the stamina of the player.

The advantage of using a delay timer is that you can control when it should start and stop.

Not sure if this even makes sense … it is like a bit of a brain dump. 8-{

Hi,

just a quick question: Why not use a timer that is set to 1 second and looped, and add stamina with a specific rate in there?

i.e. how i do it in my TopDown Toolkit (Beware, clever marketing here! :wink: )

For setting the timer:

And the actual Logic:

Cheers,

Wow, there are some great options here, I appreciate the feedback and will post some results.

How would I guarantee I am getting the last replicated value and not one tricked by the client? I have just started treading the waters of multi-player so it’s a bit new to me sorry. :o

Well you would know the last value that the client had as well as how long it should take to recover the energy. If you get a request from the client before the time you know it is invalid.

As I say … this is untested and just me throwing it out there.

Oh I see what you’re saying. I was looking at indygoof’s example and it looks great! The only thing I see is the timer is set locally by the client, so would that enable the client to trick the timer into moving faster than it is supposed to? In that case I would have to compare the last replicated value with server.

Well, to be 100% sure, you could do a call that is only executed on the server and set the timer there, instead from the client.
i.e.

Cheers,

Well that’s a lot more cleaver and simple than what I was about to do. Thanks a ton!

I actually have another solution that could work here as well … with a delay. I use it in Kaboom Arena to replenish more bombs and dynamite at a set cycle. This doesn’t use event tick at all and works independently of any timer event or other timing trick.

This also works in Network play without an issue and I have not encountered any issues with my testing.

This is on my Player Character blueprint and happens after I spawn my bomb on all clients.

This is the portion that is wired off the spawn bomb call and it basically has a delay that is wired to a set value, for bombs it is 5 seconds. I pass in the current bomb count as an input to the refresh bombs call and it returns a true/false on whether we should continuing refresh. Typically you won’t refresh when you hit the max bomb count … in this example it is 5.

This is the meat and potatoes of the refresh bombs call, it takes the current bomb count, makes sure the player is not dead and then does a whole bunch of checks to make sure we should continue refreshing bombs or not.

Please feel free to contact me if you need any further information. I am not sure whether this will work for anyone else’ particular project, but I plan on using it in Re-Spawn as well when I get back on to that project.