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

Eat speed

Discussion in 'Development' started by Kyd, Mar 18, 2017.

  1. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    How would I check how fast is player eating?
     
    Last edited: Mar 18, 2017
  2. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    Are you trying to do fast eating?
    Just like when player eating food,it consume instantly?
     
  3. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    No, I want check how fast player eat
     
  4. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    Ok.Or you are trying to anti-hack?
    Can you do some further detail?I don't understand it
    Normal eating speed is about 1.9 - 2 second(s)
     
  5. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Yes, I trying to anti-hack
     
  6. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    still dosent explain how to check eat speed,
    afaik you may use interact event OR eat event and block if it's firing too fast
     
  7. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Is there any was to check when player start eat?
     
  8. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Yeah, EntityEatItemEvent
     
  9. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    What you can do is measure the time difference between the last consumption and the final consumption.
    PHP:
    /**
    * This is the time interval in seconds.
    * If the player consumes food in less
    * than this time, they will be kicked.
    */
    const EAT_TIME_DIFFERENCE 2;

    private 
    $eatings = [];

    public function 
    onSaturate(PlayerItemConsumeEvent $event){
        
    $player $event->getPlayer();
        if(!isset(
    $this->eatings[$id $player->getId()])){
            
    $this->eatings[$id] = time();
        }else{
            if((
    time() - $this->eatings[$id]) <= self::EAT_TIME_DIFFERENCE){
                
    $eatspeed time() - $this->eatings[$id];//in seconds
                //Player is eating too quickly.
                
    $player->kick("ur gaining weight too quickly");
            }
            
    $this->eatings[$id] = time();
        }
    }
    This might probably be a bad way, I advice you to use microtime instead.
     
    Last edited: Mar 20, 2017
    XdmingXD and HimbeersaftLP like this.
  10. PocketKiller

    PocketKiller Slime

    Messages:
    83
    GitHub:
    iPocket
    lol "gaining weight"
    I wonder how thats hackable since its by the server? or maybe im confused with MCPC stuff...
     
    HimbeersaftLP likes this.
  11. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    Maybe if server dosent care about the speed client eat
     
  12. PocketKiller

    PocketKiller Slime

    Messages:
    83
    GitHub:
    iPocket
    as of how it should work;
    The client sends eating, and the server makes the "timer" for eating and succeed it.
     
  13. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Thank you. I used this code with little edit.
     
  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.