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

how to make creative mode can't hit player?

Discussion in 'Development' started by padrone, Jan 10, 2018.

  1. padrone

    padrone Witch

    Messages:
    69
    GitHub:
    padreon
    how to make creative mode can't hit player?
     
  2. HyGlobalHD

    HyGlobalHD Spider Jockey

    Messages:
    25
    GitHub:
    HyGlobalHD
    from your question, you ask 'how to make creative mode can't hit player?'
    My Answer Is By Using A Plugin.
    If You Already Know How To Make Plugin This Code Should Help
    Note: Just // a pseudo-code
    PHP:
         public function noHit(EntityDamageEvent $event){
             
    $entity $event->getEntity();
             
    $cause $this->getDamager();
             if(
    $entity instanceof Player){
                 if(
    $cause instanceof Player){
                     if(
    $cause->getGamemode(1)){
                         
    $event->setCancelled(true);
                     }
                 }
             }
         }
     
    Last edited: Jan 10, 2018
  3. padrone

    padrone Witch

    Messages:
    69
    GitHub:
    padreon
    doesn't work
     
  4. HyGlobalHD

    HyGlobalHD Spider Jockey

    Messages:
    25
    GitHub:
    HyGlobalHD
    try change
    PHP:
    $this->getCause();
    to
    PHP:
    $this->getDamager();
     
  5. Marabou

    Marabou Baby Zombie

    Messages:
    137
    GitHub:
    wiligangster
    WTF No....
    https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/event/entity/EntityDamageEvent.php

    Check here.. why '$this->getDamager()' undefined function getDamager() on null .. try learn new api ...

    It's '$event->getDamager() ' after the condition if($event instanceof EntityDamageByEntityEvent)

    if($damager->getDamager() == 1){ instead to if($damager->getGamemode(1)){ ??

    No because getGamemode() is a function who return so which gamemode is the player in the form of an int.
     
  6. Herojhjh

    Herojhjh Silverfish

    Messages:
    20
    GitHub:
    herojhjh
    PHP:
    public function onAttack(EntityDamageEvent $event){
    if (
    $event instanceof EntityDamageByEntityEvent) {
                
    $player $event->getDamager();
                if (
    $player instanceof Player) {
                    if (
    $player->getGamemode() == 1){
                         
    $event->setCancelled(true);
    }
    }
    }
    }
    Try this maybe work
     
  7. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    Did you implemented Listener?
     
  8. Herojhjh

    Herojhjh Silverfish

    Messages:
    20
    GitHub:
    herojhjh
    yes
     
  9. kenygamer

    kenygamer Banned Banned

    Messages:
    106
    GitHub:
    kenygamer
    That code is wrong...

    See how I do it in my KillMoney plugin.
     
  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.