How do I create a stamina system using the hunger bar?

Solution 1:

you should reset the objective every time you applied the hunger effect, like so:

/effect @a[score_staminaUsage_min=1] minecraft:hunger 1 1 true
/scoreboard players set @a[score_staminaUsage_min=1] staminaUsage 0

same for the staminaUsageAir.

this way you can give the hunger effect only when a player sprints or jumps.


Here is another tip: if you're okay with your player regenerating hunger whenever he's not loosing, you could for example put this command on a clock:

/effect @a minecraft:saturation 1 0

this will regenerate half a cone each time it is activated (20 times a second: full bar in one second. once per second: full bar in 40 seconds).
then just put the hunger effect above it while they run (with a high amplifier, like 200) and bam, system complete.