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

How to prevent the regeneration of life

Discussion in 'Development' started by Brian Medina, Apr 19, 2017.

  1. Brian Medina

    Brian Medina Spider Jockey

    Messages:
    27
    GitHub:
    NintendoCore16
    The codes I've tried already none work from 0.16.0
    What could I do
    I use google translate
     
  2. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Can you share what you tried, and what about them didn't work? Did you get any errors? I believe you can just listen for EntityRegainHealthEvent and cancel it.
     
  3. Brian Medina

    Brian Medina Spider Jockey

    Messages:
    27
    GitHub:
    NintendoCore16
    Code:
        public function onRegainHealth(EntityRegainHealthEvent $event){
            $p = $event->getEntity();
            if($p instanceof Player){
                if($event->getRegainReason() === EntityRegainHealthEvent::CAUSE_EATING || $event->getRegainReason() === EntityRegainHealthEvent::CAUSE_CUSTOM || $event->getRegainReason() === EntityRegainHealthEvent::CAUSE_REGEN || $event->getRegainReason() === EntityRegainHealthEvent::CAUSE_SATURATION){
                    $event->setCancelled(true);
                }
            }
        }
     
  4. Brian Medina

    Brian Medina Spider Jockey

    Messages:
    27
    GitHub:
    NintendoCore16
    it does not work
     
  5. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Are there any regain reasons that you don't want to cancel for? You could remove the check if so, and just cancel all regen. Do you get any errors? If you only want to allow one regain reason, for example, CAUSE_MAGIC, You can try this:
    PHP:
     if(!$event->getRegainReason() === EntityRegainHealthEvent::CAUSE_MAGIC) {
       
    $event->setCancelled();
     } 
    How are you testing your code?
     
  6. Brian Medina

    Brian Medina Spider Jockey

    Messages:
    27
    GitHub:
    NintendoCore16
    it does not work
    :/
    Pocketmine is damaged or bad
     
  7. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    put echo statements
     
    Primus likes this.
  8. Brian Medina

    Brian Medina Spider Jockey

    Messages:
    27
    GitHub:
    NintendoCore16
    how do you do that?
     
  9. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    What are you doing to test it?
     
  10. Primus

    Primus Zombie Pigman

    Messages:
    749
    Make sure You've registered listeners and added class paths (damn, I still don't know how to call it because `import` is just not correct). Adding echo or any other thing that can leave mark you can see, should help you to debug your code. It basically tells you if code were execute in that scope. If you don't know how to add an echo statement, stop coding!
     
  11. Brian Medina

    Brian Medina Spider Jockey

    Messages:
    27
    GitHub:
    NintendoCore16
    I put everything in my code >:v
    But the only thing that does not work is regeneration>: v
    It is done but it does not work the events are registered and they are use them well
     
  12. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Is the event and all of your code called? You still haven't said how you are testing the code.
     
  13. Brian Medina

    Brian Medina Spider Jockey

    Messages:
    27
    GitHub:
    NintendoCore16
    I tried damaging the player and it regenerated
    And also with posions and regenerates
     
  14. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    Is any code inside the if statement run?
     
  15. Brian Medina

    Brian Medina Spider Jockey

    Messages:
    27
    GitHub:
    NintendoCore16
    Could give me a code that will cancel feedback to all players?
     
  16. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    corytortoise 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.