1. 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!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Hunger manipulation

Discussion in 'Requests' started by Azternaut, Mar 21, 2017.

  1. Azternaut

    Azternaut Member

    Joined:
    Feb 3, 2017
    Messages:
    15
    Likes Received:
    2
    Category: Gameplay

    Suggested name: SimpleHungerEdit

    What I want:
    Make hunger bar last longer, the purpose of the skript is for skywars/skyblock
    decreasing but a little longer! :emoji_grinning:

    Ideas for commands:
    - none

    Ideas for permissions:
    - none

    When I'd like it by: I think it will be a simple skript, if you're an expert you can make this only 5 minute or less :emoji_bow:
     
  2. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,106
    Likes Received:
    150
    Code (Skript):
    1. set the player's food level to 10
    I think you can do the rest :emoji_wink:
     
  3. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,106
    Likes Received:
    150
    here a simple code what you request, improve it by yourself.

    Code (Skript):
    1. on hunger meter change:
    2.     if {FOOD::%player%} is false:
    3.         cancel event
    4.        
    5. Every 30 second:
    6.     set {FOOD::%player%} to true
    7.     set set the player's food level to 9
    8.     set {FOOD::%player%} to false
     
  4. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,106
    Likes Received:
    150
    This should work well :emoji_slight_smile: with /hunger speed <number> you can change the speed of the hungering

    0 = no hungering
    0.1 = every 10 second one hunger less
    1= 1 Hunger lose per second

    Code (Skript):
    1. Command /hunger [<text>] [<text>]
    2.     Trigger:
    3.         If arg 1 is "speed":
    4.             Set {hunger.speed} to arg 2
    5.             Message "Hunger speed set to %arg 2% on this server."
    6.             Stop
    7.  
    8. Every second:
    9.     Loop all players:
    10.         Set {foodlvl.%loop-player%} to 10 - {hunger.speed}
    11.         set the loop-player's food level to {_foodlvl}
     
  5. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,106
    Likes Received:
    150
    Ummm, what if player is do running or do something that spend hunger bar?
    it would be unfair right?
     
  6. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,106
    Likes Received:
    150
    Use this condition
    Code (Skript):
    1. player is sprinting:
    maybe like this,
    Code (Skript):
    1. Command /hunger [<text>] [<text>]
    2.     Trigger:
    3.         If arg 1 is "speed":
    4.             Set {hunger.speed} to arg 2
    5.             Message "Hunger speed set to %arg 2% on this server."
    6.             Stop
    7.         If arg 1 is "sprint"
    8.             set {hunger.sprint} to arg 2
    9.             message "Hunger sprint speed set to %arg 2% on this server."
    10.             stop
    11.  
    12. Every second:
    13.     Loop all players:
    14.         Set {foodlvl.%loop-player%} to 10 - {hunger.speed}
    15.         set the loop-player's food level to {_foodlvl}
    16.         if player is sprinting:
    17.             Set {foodlvl.%loop-player%} to 10 - {hunger.sprint}
    18.             Set the loop-player's food level to {_foodlvl}
     
  7. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,106
    Likes Received:
    150
    Maybe you can just double it while sprinting:

    Code (Skript):
    1. Command /hunger [<text>]
    2.     Trigger:
    3.         If arg 1 is set:
    4.             Set {hunger.speed} to arg 1
    5.             Message "Hunger speed set to %{hunger.speed}% Hunger levels per second on this server."
    6.             Stop
    7.         Else:
    8.             Message "Use /hunger <amount> to set the hunger speed on this server (in hunger levels per second)"
    9.             Stop
    10.  
    11. Every second:
    12.     Loop all players:
    13.         Set {cfoodlvl.%loop-player%} to player's food level
    14.         Set {foodlvl.%loop-player%} to  {cfoodlvl.%loop-player%} - {hunger.speed}
    15.         If player is sprinting:
    16.             set the loop-player's food level to {foodlvl.%loop-player%} - {hunger.speed}
    17.         Else:
    18.             Set the loop-player's food level to {foodlvl.%loop-player%}
    19.  
    20. On Hunger meter Change:
    21.     Cancel event
    But there are plenty of problems:
    - effect hunger doesn't effect the hunger level of player
    - make its blocking itself because of the on hunger meter change
     
  8. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,106
    Likes Received:
    150
    may can make own hunger effect?

    Code (Skript):
    1. damage player by 1 hearts
     
  9. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,106
    Likes Received:
    150
    You can check if the player has got the effect hunger and multiply the hunger *4 or so :emoji_slight_smile:
     
  10. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,106
    Likes Received:
    150
    Or with a bit of basic math you could do the following:
    Code (Skript):
    1.  
    2. options:
    3.     scale: 100 #A scale of 100 instead of 20
    4.  
    5. on hunger meter change:
    6.     set player's food level to (player's food level*2) / 20 * {@scale}
    7.  
    8.  
     
  11. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,106
    Likes Received:
    150
    Ok now lets imagine the player has a food level of 10:

    (10*2) / 20*100 = 0.02

    So the player has now got 0.02 hunger bars? Or am I wrong?
     
  12. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,106
    Likes Received:
    150
    The Skript food level (and some others) expression returns the a number in a scale of 10 and that's why I am multiplying it. So, if the player has 10 of health as you said then it should be:
    Code (Text):
    1.  
    2. (5 * 2) / 20 * 100 =>
    3. 10 / 20 * 100 =>
    4. 0.5 * 100 = 50
    5.  
     
  13. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,106
    Likes Received:
    150
    I fucked up the math....
     
  14. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,106
    Likes Received:
    150
    I did something wrong though, as the hunger cannot be greater than 20 the hunger will never change
    Here the fixed code:
    Code (Skript):
    1. options:
    2.     scale: 100
    3.  
    4. on join:
    5.     {hungerScale::%player%} isn't set
    6.     set {hungerScale::%player%} to {@scale}
    7.  
    8. on hunger meter change:
    9.     set {hungerScale::%player%} to player's food level / 10 * {@scale}
    10.     set player's food level to {hungerScale::%player%}
     
    • Winner Winner x 2
  15. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,106
    Likes Received:
    150
    Whoa thanks everyone for the script :emoji_smile:
     
Loading...