1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

How to disable hunger?

Discussion in 'Development' started by Kyd, Apr 26, 2017.

  1. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    How can I disable hunger?
     
  2. Jonas

    Jonas Baby Zombie

    Messages:
    192
    Use the PlayerHungerChangeEvent and Cancelled it
     
  3. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Hunger change event is not in pmmp! Dont talk about forks! :facepalm:
     
  4. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
  5. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    I have looked at, but there is constanted only this:
    Code:
    const CAUSE_ATTACK = 1;
    const CAUSE_DAMAGE = 2;
    const CAUSE_MINING = 3;
    const CAUSE_HEALTH_REGEN = 4;
    const CAUSE_POTION = 5;
    const CAUSE_WALKING = 6;
    const CAUSE_SPRINTING = 7;
    const CAUSE_SWIMMING = 8;
    const CAUSE_JUMPING = 9;
    const CAUSE_SPRINT_JUMPING = 10;
    const CAUSE_CUSTOM = 11;
    [CODE]
    what is hunger?
     
  6. KelvinCyaX

    KelvinCyaX Silverfish

    Messages:
    18
    GitHub:
    CyanKelv
    PlayerExhaustEvent means you lose hunger and those were the cause of the hunger change.
     
  7. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Oh thank you I must learn a lot :-D
     
  8. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Used this code and working
    PHP:
    public function onHunger(PlayerExhaustEvent $e){
    if(
    in_array($e->getPlayer()->getLevel()->getFolderName(), $this->levels){
            
    $e->getPlayer()->setFood(20);
    $e->setAmount(0);
    }
    }
        }
     
    Last edited: Apr 26, 2017
  9. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    That code will only set the player's hunger. It would be more effective to just cancel the event
     
    Last edited: Apr 26, 2017
  10. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    yeah just cancel PlayerExhaustEvent.
     
  11. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Ok I cancelled thanks:D
     
  12. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    You meant player's hunger.
     
    jasonwynn10 likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.