Sprinting Stamina

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

BrownMee

Active Member
Apr 16, 2018
126
6
18
23
Any better code for this?

Code:
on every 1 seconds:
    loop all players:
        loop-players is sprinting
        if {lvl.stamina.%loop-players%} is 0:
            subtract 1 from loop-player's hunger level
        if {lvl.stamina.%loop-players%} is 1:
            wait a sec
            subtract 1 from loop-player's hunger level
        if {lvl.stamina.%loop-players%} is 2:
            subtract 1 from loop-player's hunger level
        if {lvl.stamina.%loop-players%} is 3:
            subtract 1 from loop-player's hunger level
            
on every 5 seconds:
    loop all players:
        if {lvl.stamina.%loop-players%} is 0:
            loop-players is not sprinting
            add 1 to loop-player's hunger level
        if {lvl.stamina.%loop-players%} is 1:
            loop-players is not sprinting
            add 1.5 to loop-player's hunger level
        if {lvl.stamina.%loop-players%} is 2:
            loop-players is not sprinting
            add 2 to loop-player's hunger level
        if {lvl.stamina.%loop-players%} is 3:
            loop-players is not sprinting
            add 2.5 to loop-player's hunger level

Using on every event im afraid it will lag the server
 
you can use on sprint toggle
also instead of putting "if "i recommend you to use "else if"
 
you can use on sprint toggle
also instead of putting "if "i recommend you to use "else if"
Tried that but it only detects when u toggle sprint. So it can only deduct the hunger 1 time.
[doublepost=1603015604,1603014076][/doublepost]
you can use on sprint toggle
also instead of putting "if "i recommend you to use "else if"
any other idea? I tried my best working with sprint toggle. Doesnt works.

I want it when player sprint it start draining the hunger bar. If stop it doesnt drain
 
so i think looping is the best way
2 loops of every 1 and 5 seconds shouldn't lag the server at all
 
Code:
on every 1 seconds:
    loop all players:
        loop-players is sprinting
        if {lvl.stamina.%loop-players%} is 0:
            subtract 1 from loop-player's hunger level
        if {lvl.stamina.%loop-players%} is 1:
            wait a sec
            subtract 1 from loop-player's hunger level
        else if {lvl.stamina.%loop-players%} is 2:
            subtract 1 from loop-player's hunger level
        else if {lvl.stamina.%loop-players%} is 3:
            subtract 1 from loop-player's hunger level
          
on every 5 seconds:
    loop all players:
        else if {lvl.stamina.%loop-players%} is 0:
            loop-players is not sprinting
            add 1 to loop-player's hunger level
        else if {lvl.stamina.%loop-players%} is 1:
            loop-players is not sprinting
            add 1.5 to loop-player's hunger level
        else if {lvl.stamina.%loop-players%} is 2:
            loop-players is not sprinting
            add 2 to loop-player's hunger level
        else if {lvl.stamina.%loop-players%} is 3:
            loop-players is not sprinting
            add 2.5 to loop-player's hunger level
its the one you made but with else if
 
Status
Not open for further replies.